akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

bool has3(int x) {
	while(x) {
		if (x % 10 == 3) return true;
		x /= 10;
	}
	return false;
}

void call(int n) {
	for (int x = 1; x <= n; x++) {
		if (x % 3 == 0 || has3(x)) {
			cout << " " << x;
		}
	}
	cout << endl;
}

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

	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int f(int x){
  if(x%2==0){
    return x/2;
  }
  return x*3+1;
}
int g(int s,int n){
  if(n==1){
    return s;
  }
  return f(g(s,n-1));
}
int main(){
  int s;
  cin>>s;
  vector<int> an(1000000);
    bool finished =false;
  for(int i=1;i<=1000000;i++){
    an.at(i)=g(s,i);
    for(int j=1;j<i;j++){
      if(an.at(i)==an.at(j)){
        cout<<i<<endl;
        finished =true;
      break;
      }
    }
  if(finished) {
    break;
  }
  }
}

Measured memory_bytes: 4096
#include<stdio.h>

int main(void){
    int P,Q,R,L,l;
    scanf("%d %d %d",&P,&Q,&R);
    l = (P + Q) * (P <= R && Q <= R);
    if(l != 0) L = l;
    l = (P + R) * (P <= Q && R <= Q);
    if(l != 0) L = l;
    l = (R + Q) * (R <= P && Q <= P);
    if(l != 0) L = l;
    printf("%d",L);
    return 0;
}

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

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}
vector<ll> SieveOfEratosthenes(ll n,ll a)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    vector<ll>v;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p= a; p<=n; p++)
       if (prime[p])
          v.push_back(p);
    return v;
}
void permute(string a, int l, int r)
{
    // permutes string
    if (l == r)
    {
        cout<<a<<endl;
    }
    else
    {
        for (int i = l; i <= r; i++)
        {
            swap(a[l], a[i]);
            permute(a, l+1, r);
        }
    }
}
int main()
{
    int n;
    cin>>n;
    int ans = 0;
    for(int i =1;i<n;i++)
    {
        for(int j = 1;i*j<n;j++)
        {
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int H,W;
  cin>>H>>W;
  vector<vector<char>>a(H+2,vector<char>(W+2));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<=H+1;i++){
    for(int j=0;j<=W+1;j++){
      if(i==0||j==0||i==H+1||j==W+1){
        a[i][j]='#';
      }
    }
  }
  for(int i=0;i<=H+1;i++){
    for(int j=0;j<=W+1;j++){
      cout<<a[i][j];
    }cout<<endl;
  }
  return 0;  
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int bj[maxn];
int ans=0;
std::vector<int> v[maxn];
	int n;int m;
void dfs(int x,int cnt)
{
	if(cnt==n)
	{
		ans++;
		return ;
	}
	for(auto k:v[x])
	{
		if(!bj[k])
		{
			bj[k]=1;
			dfs(k,cnt+1);
			bj[k]=0;
		}
	}
}
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n;
	cin>>m;
	int a,b;
	repd(i,1,m)
	{
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	bj[1]=1;
	dfs(1,1);
	cout<<ans<<endl;
	
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();} 
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') 
{*p = *p * 10 + ch - '0';}}}

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

using namespace std;

int main() {
	int n, r = 0, a = 0, b = 0, x = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int i = 1; i < s.length(); i++)
			if (s[i - 1] == 'A'&&s[i] == 'B')
				r++;
		if (s[0] == 'B') b++;
		if (s.back() == 'A') a++;
		if (s[0] == 'B' && s.back() == 'A') x++;
	}
	if (a&&a == x && b == x) r--;
	cout << r + min(a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var i int
	var i1, i2, ans int
	fmt.Scan(&i1, &i2)

	for i = 0; i < 2; i++ {
		if i1 < i2 {
			ans += i2
			i2 += -1
		} else {
			ans += i1
			i1 += -1
		}
	}
	fmt.Print(ans)
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int a[4];
    string s;
    cin >> s;

    rep(i, 0, 4) {
        a[i] = s[i] - '0';
    }

    rep(i,0,8){
        int cnt = a[0];
        rep(j,0,3){
            if((i >> j) & 1) cnt += a[j+1];
            else cnt -= a[j+1];
        }
        if(cnt == 7){
            cout << a[0];

            rep(j,0,3){
                if((i >> j) & 1) cout << "+";
                else cout << "-";
                cout << a[j+1];
            }
            cout << "=7" << endl;
            return 0;
        }


    }


    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        cout << a[i];
        if (i > 0) {
            cout << " ";
        }
    }
    
    cout << endl;
    return 0;
    
}



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

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

  int cnt = 0;
  string digit;
  for (int i = 1; i <= N; i++){
    digit = to_string(i);
    if (digit.size() % 2 != 0) cnt += 1;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3668
#include<stdio.h>
#include<sstream>
#include<string>
int F(int x)
{
	int d=1,t=1,r=0;
	while(d*10<=x)
	{
		r+=d*9*t;
		d*=10;
		++t;
	}
	return r+(x-d+1)*t;
}
int main()
{
	int N,K,l,m,r,i;
	while(scanf("%d%d",&N,&K),N)
	{
		for(l=1,r=13e7;l<r;)
		{
			m=(l+r)/2;
			if(F(m)<N)l=m+1;
			else r=m;
		}
		std::stringstream s;
		for(i=l;s.str().size()<=K*K;++i)
			s<<i;
		printf("%s\n",s.str().substr(N-F(l-1)-1,K).c_str());
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]p  = new int [N];
 
    int all = 0;
    for(int i=0; i<N; i++){
    p[i] = sc.nextInt();
        all += p[i];
    }
    Arrays.sort(p); 
    int hangaku = p[N-1]/2;

    System.out.println(all-hangaku);
    }
}


Measured memory_bytes: 35764
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int AB = 26;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int k = parseInt(sc.next());
		int[] l = new int[n];
		for(i=0;i<n;i++) {
			l[i] = parseInt(sc.next());
		}
		sc.close();
		Arrays.parallelSort(l);
		int sum=0;
		for (i = n-1; i >= n-k; i--) {
			sum+=l[i];
		}
		out.println(sum);
	}
}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  int x;
  if (N < 10) x = N;
  else if (N < 100) x = 9;
  else if (N < 1000) x = 9 + (N - 99);
  else if (N < 10000) x = 9 + 900;
  else if (N < 100000) x = 9 + 900 + (N - 9999);
  else x = 9 + 900 + 90000;
  cout << x << endl;

  return 0;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> vec(2*M);
  rep (i, 2*M) {
  cin >> vec.at(i);
  }
  
  rep (i, N) {
  int count = 0;
    rep(j, 2*M) {
      if (vec.at(j) == i+1) {
      count++;
      }
    }
  cout << count << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  	int N, D, ans;
  	cin >> N >> D;
  	ans = N / (D*2+1);
  	if(N % (D*2+1) == 0){
  	
    }else{
   		ans++;
    }
  	cout << (int)ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
   	#endif
    int n,m;
    cin>>n>>m;
    cout<<(n*n)-m;
   return 0;
}

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

int main(){
  char X,Y;
  cin >> X >> Y;
  if(X>Y){
    cout << '>' << endl;
  }else if(X<Y){
    cout << '<' << endl;
  }else{
    cout << '=' << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    char x,y;
    scanf("%c %c",&x,&y);
    if(x>y)
    {
        printf(">\n");
    }
    else if(x==y)
    {
        printf("=\n");
    }
    else
    {
        printf("<\n");
    }

    return 0;
}



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

int main() {

	string s, t; cin >> s >> t;
	
	const int p = 26;
	vector<int> s_num(p), t_num(p);

	for (int i = 0; i < s.size(); i++) {
		s_num[s[i] - 'a']++;
		t_num[t[i] - 'a']++;
	}

	sort(s_num.begin(), s_num.end());
	sort(t_num.begin(), t_num.end());
	
	bool can = true;
	for (int i = 0; i < p; i++) {
		if (s_num[i] != t_num[i]) {
			can = false;
		}
	}
	
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

pair<int, int> to_L_S(string s) {
    vector<int> a;
    for (int i = 0; i < s.length(); i++) {
        a.push_back((int)(s[i] - '0'));
    }
    while (a.size() <= 3) {
        a.push_back(0);
    }
    sort(a.begin(), a.end());
    int L = 0;
    int S = 0;
    int k[4] = {1, 10, 100, 1000};
    for (int i = 0; i < 4; i++) {
        L += (a[i] * k[i]);
        S += (a[i] * k[3 - i]);
    }
    return make_pair(L, S);
}

int main() {

    for (int i = 0; i < 1000000; i++) {
        string s;
        cin >> s;
        if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) {
            if (s[0] == '0') {
                return 0;
            }
            cout << "NA\n";
        } else if (s == "6174") {
            cout << "0\n";
        } else {
            pair<int, int> p = to_L_S(s);
            int cnt = 1;
            while (p.first - p.second != 6174) {
                cnt++;
                int N = p.first - p.second;
                // cout << p.first << " " << p.second << "\n";
                // cout << N << "\n";
                p = to_L_S(to_string(N));
            }
            cout << cnt << "\n";
        }

    }
    return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


using ll = long long;
using namespace std;


int main()
{
    ll N;
    cin >> N;
    vector<string> S(N);
    string l;
    for (int i = 0 ; i < N ; i++)
    {
        cin >> l;
        S.push_back(l);
    }
    
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    // for (auto it = S.begin() ; it!=S.end(); ++it)
    // {
    //     cout << *it << endl;
    // }
    cout << S.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 15740
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=100005;
vector<int>e[N];int n;
bool dfs(int x,int fa){int m=0;for(int v:e[x])if(v!=fa)m+=dfs(v,x); if(m>1)puts("First"),exit(0);return m^1;}

int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),e[u].pb(v),e[v].pb(u);
	if(dfs(1,0))puts("First");else puts("Second");
	return 0;
}

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

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

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int>p(n);
	rep(i, n)
		cin >> p[i];

	int ans = 0;
	for (int i = 1; i < n - 1; i++)
		if (p[i] > p[i - 1] && p[i] < p[i + 1])
			ans++;
		else if (p[i]<p[i - 1] && p[i]>p[i + 1])
			ans++;

	cout << ans << endl;

	return 0;
}

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

int main()
{
  int i, j, k, ii, c, d, n, m;
  char buf[16] = {0};
  buf[15] = '\0';
  buf[14] = '\n';
  fscanf(stdin, "%d\n", &n);
  int *a = (int*)malloc(sizeof(int)*n);
  
  int sep = '\n';
  char *line = NULL;
  size_t linecap = 0;
  ssize_t linelen;
  getline(&line, &linecap, stdin);
  
  a[0] = 0;  
  i=0;
  for (char *p=line; *p!='\n'; p++) {
    if (*p < '0') {
      i++;
      p++;
      a[i] = *p-'0';
    } else {
      a[i] = a[i] * 10 + *p - '0';
    }
  }
  
  fscanf(stdin, "%d\n", &m);
  getline(&line, &linecap, stdin);
  char *p=line;
  i = j = 0;
  
  int b;
  for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
  p++;
  
  if (a[i]<=b) {
    c = a[i++];
  } else {
    c = b;
    j++;
    for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
    p++;
  }
  
  d = c;
  if (d==0) {
    fputs("0\n", stdout);
  } else {
    for (ii=13; d>0; ii--, d/=10)   buf[ii] = '0' + (d%10);
    fputs(buf+ii+1, stdout);
  }
  
  while (i<n && j<m) {
    if (c==a[i]) {
      i++;
      continue;
    }
    if (c==b) {
      j++;
      for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
      p++;
      continue;
    }
    
    if (a[i]<=b) {
      c = a[i++];
    } else {
      c = b;
    }
    //    printf("%d\n", c);
    d = c;
    for (ii=13; d>0; ii--, d/=10)   buf[ii] = '0' + (d%10);
    fputs(buf+ii+1, stdout);
  }


  while (i<n && j<m) {
    if (c==a[i]) {
      i++;
      continue;
    }
    if (c==b) {
      j++;
      for (b = 0; ; b = b * 10 + *(p++) - '0');
      p++;
      continue;
    }
    
    if (a[i]<=b) {
      c = a[i++];
    } else {
      c = b;
    }

    for (ii=13; d>0; ii--, d/=10)   buf[ii] = '0' + (d%10);
    fputs(buf+ii+1, stdout);
      
  }
  
  while (i<n) {
    if (c==a[i]) {
      i++;
      continue;
    }
    c = a[i++];
    d = c;
    for (ii=13; d>0; ii--, d/=10)   buf[ii] = '0' + (d%10);
    fputs(buf+ii+1, stdout);

  }
  
  while (j<m) {
    if (c==b) {
      j++;
      for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
      p++;
      continue;
    }
    c = b;
    d = b;
    for (ii=13; d>0; ii--, d/=10)   buf[ii] = '0' + (d%10);
    fputs(buf+ii+1, stdout);

  }
  return 0;
}



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

int main(){
  int D;
  cin >> D;
  if( D == 25)
    cout << "Christmas";
  else if(D == 24)
    cout << "Christmas Eve";
  else if(D == 23)
    cout << "Christmas Eve Eve";
  else
    cout << "Christmas Eve Eve Eve";

  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,m,c;
    cin>>n>>m>>c;
    int b[m];
    for (int i = 0; i < m; ++i) {
        cin>>b[i];
    }
    int x,s=0,count=0;
    for (int i = 0; i < n; ++i) {
        s=0;
        for (int j = 0; j < m; ++j) {
            cin>>x;
            s+=b[j]*x;
        }
        s+=c;
       if(s>0)
           count++;
    }
    cout<<count;
}

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

typedef long long ll;
ll n, m;
ll M = 1e9 + 7;

ll f(ll p) {
	ll re;
	for (re = 1; p > 0; re = re * p-- % M);
	return re;
}

ll g(ll p) {return p > 0 ? p : -p;}

int main()
{
	cin >> n >> m;
    cout << f(n) * f(m) * max(0LL, 2 - g(n - m)) % M << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, y;
    while(cin >> x >> y) {
        if(x == 0) {
            ll ans = abs(y);
            if(y < 0)ans++;
            cout << ans << endl;
            continue;
        }
        if(y == 0) {
            ll ans = abs(x);
            if(x > 0)ans++;
            cout << ans << endl;
            continue;
        }

        ll d = abs(y) - abs(x), ans = abs(d);
        // 絶対値を
        // 増やす
        if(x < 0 && d>0)ans++, x = -x;
        // 減らす
        if(x > 0 && d < 0)ans++, x = -x;

        if(x*y < 0)ans++;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
    int a = scan.nextInt();
    if(n%500 <=a){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}


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

int main() {
    long long X,Y; cin >> X >> Y;
    long long c=0;
    while(Y>=X){
      X *= 2;
      c++;
    }
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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; }



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,x; cin>>N>>x;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  ll ans=INF;
  ll sans=0;
  auto sA=A;
  rep(i,N-1) if(sA[i]+sA[i+1]>x) {sans+=sA[i]+sA[i+1]-x; sA[i+1]=max(0LL,x-sA[i]);}
  chmin(ans,sans);
  //rep(i,N) {if(i!=0) cout<<" "; cout<<sA.at(i);} cout<<'\n';
  
  sans=0;
  reverse(A.begin(),A.end());
  sA=A;
  rep(i,N-1) if(sA[i]+sA[i+1]>x) {sans+=sA[i]+sA[i+1]-x; sA[i+1]=max(0LL,x-sA[i]);}
  chmin(ans,sans);
  
  cout<<ans<<'\n';
  
  return 0;
}

Measured memory_bytes: 4732
inH, inW = map(int, input().split())
inMap = list()

for i in range(inH):
  inMap.append(list(input()))

def chkPaint(x,y):
  mv = [[-1,0], [1,0], [0,-1], [0,1]]
  for pos in mv:
    if x+pos[0]<0 or x+pos[0]>=inH or y+pos[1]<0 or y+pos[1]>=inW  :
      continue
    if inMap[x+pos[0]][y+pos[1]] == "#":
        return True
  return False

flg=True
for i in range(inH):
  for j in range(inW):
    if inMap[i][j] == "#":
      flg = chkPaint(i,j)
    if flg == False:
      break
  if flg == False:
    break

if flg:
  print("Yes")
else:
  print("No")
    

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    int slen=s.length(), len=0;
    int l=0;
    for(int i=0;i<slen;i++) {
        char c = s[i];
        if (c=='A' || c=='C' || c=='G' || c=='T') {
            l++;
            if (l>len) len = l;
        } else {
            l = 0;
        }
    }
    cout << len << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 * 1000 + 47;

struct point
{
	LL x, y;
	int type, i;
	point() {}
	point(LL x1, LL y1, int type1, int i1)
	{
		x = x1;
		y = y1;
		type = type1;
		i = i1;
	}
};

struct segment
{
	LL x1, x2, y;
};

point P[MAX];
point Q[MAX];
segment S[MAX];
multiset<LL> sett;
vector<int> g[MAX];
int v, n, r;
int qsz;
int sz;
LL cx, cy;

LL square(LL x1, LL y1, LL x2, LL y2, LL x3, LL y3)
{
	return (x2 - x1) * (y2 - y1) - (x3 - x1) * (y2 - y1);
}

bool cw(const point& a, const point& b)
{
	LL s = square(cx, cy, a.x, a.y, b.x, b.y);
	if (s == 0) return a.y > a.y;

	return square(cx, cy, a.x, a.y, b.x, b.y) < 0;
}

bool cmp(const point& a, const point& b)
{
	return cw(a, b);
}

bool inside(LL x, LL y)
{
	bool g = (y - cy) * v + cx > x;
	bool s = -(y - cy) * v + cx < x;
	return g && s;
}

LL getMin(LL x, LL y)
{
	LL ans = LINF;
	FOR(i, 0, n)
	{
		if (S[i].y <= y) continue;
		LL xx = (S[i].y - y) * v + x;

		if (S[i].x1 < xx && xx < S[i].x2) ans = min(ans, S[i].y);
	}

	return ans;
}

vector<int> RES;
vector<int> V;
double ans = LINF;

void dfs(int v)
{
	V.PB(v);
	LL val = getMin(P[v].x, P[v].y);

	if (val > r && (r - P[v].x) / v < ans)
	{
		ans = (r - P[v].x) / v;
		RES = V;
	}

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to);
	}

	V.pop_back();
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	if (s.substr(0, 4) == "YAKI")
	{
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
}

Measured memory_bytes: 47360
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	string S;
	cin >> S;

	int cnt0, cnt1;
	cnt0 = count(S.begin(), S.end(), '0');
	cnt1 = S.size() - cnt0;

	cout << min(cnt0, cnt1) * 2 << endl;

	return 0;
}


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

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

int main() {
  int H,W;
  vector< string > s;
  cin >> H >> W;

  s.push_back( string( W+2, '#' ));
  int wn = 0;
  REP(i,H) {
    string ss;
    cin >> ss;
    ss = "#" + ss +"#";
    REP(j,W+2) if ( ss[j] == '.' ) wn++;
    s.push_back( ss );
  }
  s.push_back( string( W+2, '#' ) );
  REP(i,60) REP(j,60) len[i][j] = 100*100;
  len[1][1] = 0;

  queue<pair<int,int> > q;
  q.push( { 1, 1 } );
  while( !q.empty() ) {
    auto v = q.front(); q.pop();
    int y = v.first;
    int x = v.second;
    REP(i,4) {
      int ny = y+dy[i];
      int nx = x+dx[i];
      if ( s[ny][nx] == '.' && len[ny][nx] > len[y][x]+1 ) {
        len[ny][nx] = len[y][x] + 1;
        q.push({ ny, nx });
      }
    }
  }
  if (len[H][W] == 100*100) {
    cout << "-1" << endl;
  } else {
    cout << (wn - (len[H][W]+1)) << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[][] a = new int[3][3];
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				a[i][j] = scan.nextInt();
			}
		}

		int n = scan.nextInt();
		for(int i = 0; i < n; i++) {
			int x = scan.nextInt();
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					a[j][k] = a[j][k] == x ? 0 : a[j][k];
				}
			}
		}


		int[][] naname = new int[2][3];
		naname[0][0] = a[0][0];
		naname[0][1] = a[1][1];
		naname[0][2] = a[2][2];
		naname[1][0] = a[0][2];
		naname[1][1] = a[1][1];
		naname[1][2] = a[2][0];

		boolean f = false;
		for(int i = 0; i < 3; i++) {
			boolean f2 = true;
			for(int j = 0; j < 3; j++) {
				if(a[i][j] != 0) f2 = false;
			}
			if(f == false) {
				f = f2;
			} else {
				break;
			}
		}
		for(int i = 0; i < 3; i++) {
			boolean f2 = true;
			for(int j = 0; j < 3; j++) {
				if(a[j][i] != 0) f2 = false;
			}
			if(f == false) {
				f = f2;
			} else {
				break;
			}
		}
		for(int i = 0; i < 2; i++) {
			boolean f2 = true;
			for(int j = 0; j < 3; j++) {
				if(naname[i][j] != 0) f2 = false;
			}
			if(f == false) {
				f = f2;
			} else {
				break;
			}
		}

		System.out.println(f ? "Yes" : "No");

		scan.close();

	}

}


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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


	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && a == c)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}

const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,t;
	cin>>n>>t;
	vector<int> a(n),b(n);
	rep(i,n) cin>>a[i]>>b[i];
	ll re=0;
	rep(i,31){
		int st=t&~((1<<i)-1);
		if(i && t>>(i-1)&1) st|=((1<<(i-1))-1);
		ll sum=0;
		rep(j,n)if((a[j]&st)==a[j]) sum+=b[j];
		MX(re,sum);
	}
	cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 1024
x, n = map(int, input().split())
if n:
    p = list(map(int, input().split()))
    ans = x  # tmp = 0
    res = 0
    for i in range(1, 102):
        if i not in p:
            if ans > abs(i - x):
                ans = abs(i - x)
                res = i
    print(res)
else:
    print(x)


Measured memory_bytes: 9184
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**6 + 5)

def dfs_numbering(st, M, V, ANS, cnt, v):
    ST = [st]
    while len(ST) > 0:
        # print(ST,V)
        i = ST[-1]
        if ANS[i] == -1:
            V[i] = v
            end = 1
            for x in M[i]:
                if V[x] == -1:
                    ST.append(x)
                    end = 0
                    # cnt = dfs_numbering(x, M, V, ANS, cnt, v)
            if end == 1:
                ST.pop()
                ANS[i] = cnt
                cnt += 1
        else:
            ST.pop()
    return cnt

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        cnt = 0
        for i in range(n):
            if V[i] == -1:
                cnt = dfs_numbering(i, self.M, V, ANS, cnt, 0)

        # print(ANS)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        # print(ANS1)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

n, m = map(int,input().split())

S = scc(n)
for i in range(m):
    frm, to = map(int,input().split())
    S.add_edge(frm, to)
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(len(ANS[i]), end=" ")
    print(*ANS[i])

Measured memory_bytes: 270312
#include <iostream>

using namespace std;

int main(void){
    int N;
    cin >> N; cin.ignore();
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r; cin.ignore();
        ans += r - l + 1;
    }
    cout << ans << endl;
} 


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

#[fastout]
fn main() {
    input! {
        n: i64,
    }
    match n % 10 {
        2 | 4 | 5 | 7 | 9 => println!("hon"),
        0 | 1 | 6 | 8 => println!("pon"),
        _ => println!("bon"),
    }
}


Measured memory_bytes: 2144
#include<cstdio>
using namespace std;
int n,k,ans=1;
int main()
{
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++)
  {
    if(ans>k)  ans+=k;
    else  ans*=2;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


A, B, K = LI()
temp = 0
for i in range(min(A, B), 0, -1):
    if A % i == 0 and B % i == 0:
        temp += 1
        if temp == K:
            print(i)
            exit()


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

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

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

n = onem()
po = []
for i in range(n):
    po.append(l())

co = 0

for i in range(n):
    on = po[-(i+1)]
    on[0] += co
    co += (on[1] - (on[0] % on[1])) if on[0] % on[1] != 0 else 0

print(co)


Measured memory_bytes: 31732
#include<stdio.h>

int main(void)
{
  int S;
  int h, m, s;

  scanf("%d", &S);
  h=S/3600;
  m=S-3600*h;
  s=m%60;
  printf("%d:%d:%d\n", h, m/60, s);

  return 0;
}

Measured memory_bytes: 592
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:40 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
    
all(nstr.count(c) for c in '753')

ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
#A, B, totAB = zip(*ABT)


(x >> i) & 1

"""
N = int(input())

A = [0]*N
A[:] = map(int, input().split())

A.sort()
while len(A) != 1:
    for n in range(len(A)-1):
        A[n+1] = A[n+1] % A[0]
    A = [e for e in A if e != 0]
    A.sort()
print(A[0])



Measured memory_bytes: 25208
#include<stdio.h>
int main()
{
	int a[3];
	int i,j,t;
	int cj1, cj2;
	int time=0;
	for (i = 0; i < 3; i++)
	{
		scanf("%d", &a[i]);
	}
	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 2 - i; j++)
		{
			if (a[j] > a[j + 1])
			{
				t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}
		}
	}
	cj1 = a[2] - a[0];
	cj2 = a[2] - a[1];
	if ((cj1 - cj2) % 2 != 0)
	{
		cj2++;
		time++;
	}
	time = time + (cj1 - cj2) / 2;
	time = time + cj2;
	printf("%d", time);
	return 0;
}

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

int main(int argc, char const *argv[]) {
    const int N = 110000;
    int n, a;
    int arr[N] = {};

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

    for (int i = 0; i < n; i++) {
        cout << arr[i] << ' ';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1280
//A - AtCoder Contest Scheduling
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  long long int d,c[30],i,j,tmp;
  scanf("%lld", &d);
  for(i = 1; i <= 26; i++) {
    scanf("%lld", &c[i]);
  }
  long long int s[d+2][30];
  for(i = 1; i <= d; i++) {
    for(j = 1; j <= 26; j++) {
          scanf("%lld", &s[i][j]);
    }
  }


  long long int r[367]={};
  for (i=1; i<=d; ++i) {
    r[i]=1;
    for (j=2; j<=26; ++j) {
      //for (k=i+1; k<=total; ++k) {
          if (s[i][1] < s[i][j]) {
            tmp =  s[i][1];
            s[i][1] = s[i][j];
            s[i][j] = tmp;
            r[i]=j;
          }
      //}
    }
  }
  //printf("aaa\n");
srand((unsigned int) time(0));
  for (i=1; i<=d; ++i) {
    printf("%d\n", (rand()%26)+1);
  }

  return 0;
}


Measured memory_bytes: 1816
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll X, Y, Z;
	cin >> X >> Y >> Z;

	cout << Z << " " << X << " " << Y << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  priority_queue <Pli> que;
  for (int i = 0; i < A; i++){
    ll P; cin >> P; que.push(make_pair(P, 0));
  }
  for (int i = 0; i < B; i++){
    ll Q; cin >> Q; que.push(make_pair(Q, 1));
  }  
  for (int i = 0; i < C; i++){
    ll R; cin >> R; que.push(make_pair(R, 2));
  }

  int R = 0, G = 0, T = 0;
  ll ans = 0;
  while (R + G + T < X + Y){
    Pli Q = que.top(); que.pop();

    if (Q.second == 0){
      if (R < X) {
        R++; ans += Q.first;
      }
    }
    if (Q.second == 1){
      if (G < Y){
        G++; ans += Q.first;
      }
    }
    if (Q.second == 2){
      T++; ans += Q.first;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10092
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

int cnt, w, h;
char m[100][100];

void dfs(pii);

int main(void){
    while(cin >> w >> h, w){
        MEMSET(m, '#');

        cnt = 0;
        pii p;

        rep(y, h){
            cin >> m[y];
            rep(x, w) if(m[y][x] == '@') m[y][x] = '.', p = mp(x, y);
        }

        dfs(p);
        cout << cnt << endl;
    }

    return 0;
}

void dfs(pii p){
    if((p.X < 0 || w <= p.X) ||
       (p.Y < 0 || h <= p.Y)) return;

    if(m[p.Y][p.X] == '.') cnt ++;
    else return;
    m[p.Y][p.X] = '#';

    rep(i, 4){
        pii next = mp(p.X + dx[i], p.Y + dy[i]);
        dfs(next);
    }
}

Measured memory_bytes: 1184
#22 C - Guess The Number
N,M = map(int,input().split())

sc = []
for _ in range(M):
    s,c = map(int,input().split())
    sc.append((s,c))
sc = list(set(sc))

ans = [0]*N
for i, j in sc:
    if ans[i-1] != 0:
        result = -1
        break
    ans[i-1] = j
else:
    if ans[0] == 0:
        ans[0] = 1
    ans = [str(k) for k in ans]
    result = ''.join(ans)
if (1,0) in set(sc):
    result = -1
if N == 1 and M == 1 and sc == [(1,0)]:
    result = 0
if N == 1 and M == 0:
    result = 0
print(result)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin>>n;
  vector<int> l(n),r(n);
  rep(i,n){
    cin>>l.at(i);
  }
  r.at(0) = l.at(0);
  if(l.at(0)==2){
    cout<<1;
    return 0;
  }
  int min=1;
 for(int j=1; j<n; j++){
    r.at(j) = l.at(r.at(j-1)-1);
   min++;
   if(r.at(j)==2){
     cout<<min;
     return 0;
   }  
 }
  if(min==n){
    cout<<-1;
  }
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

int n;
ll a[200010];
int pl[200010], pr[200010];

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

  cin >> n;
  REP(i,n) cin >> a[i+1];
  REP(i,n) a[i+1] += a[i];

  int p = 1;
  for (int i = 2; i <= n-2; i++) {
    while (1) {
      if (abs(a[i] - a[p] - a[p]) > abs(a[i] - a[p+1] - a[p+1]) && p+1 < i) {
        p++;
      } else {
        pl[i] = p;
        break;
      }
    }
  }

  p = n;
  for (int i = n-2; i >= 2; i--) {
    while (1) {
      if (abs(a[n] - a[p] - (a[p] - a[i])) > abs(a[n] - a[p-1] - (a[p-1] - a[i])) && p-1 > i) {
        p--;
      } else {
        pr[i] = p;
        break;
      }
    }
  }

  //pl)i)pr)n)
  ll ans = INF;
  for (int i = 2; i <= n-2; i++) {
    ll aa,bb,cc,dd;
    aa = a[pl[i]];
    bb = a[i] - aa;
    cc = a[pr[i]] - a[i];
    dd = a[n] - aa - bb - cc;
    ans = min(ans, max({aa,bb,cc,dd}) - min({aa,bb,cc,dd}));
  }

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


Measured memory_bytes: 3328
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    conb = [0]*N
    ans = 0
    for i in A:
        conb[i-1] += 1
    for j in conb:
        if j != 0:
            ans += j*(j-1)//2
    for k in range(N):
        print(ans- conb[A[k]-1]+1)



if __name__ == '__main__':
    solve()

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;

 
int main() {
  string s, t;
  cin >> s >> t;
  t.erase(t.size()-1);
  if(s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3600
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ps := make([]int, n)
	var p int
	for i := 0; i < n; i++ {
		fmt.Scan(&p)
		ps[i] = p - 1
	}
	cs := make([]int, n)
	var c int
	for i := 0; i < n; i++ {
		fmt.Scan(&c)
		cs[i] = c
	}

	ans := int(-1e18)
	for i := 0; i < n; i++ {
		c := calc(ps, cs, k, i)
		ans = max(ans, c)
	}
	fmt.Println(ans)
}

func calc(ps []int, cs []int, k, s int) int {
	n := len(ps)
	mx := int(-1e18)
	l := 0
	sum := 0
	done := make([]bool, n)
	var dfs func(i int)
	dfs = func(i int) {
		if done[i] {
			return
		}
		l++
		done[i] = true

		sum += cs[i]
		mx = max(mx, sum)
		k--
		if k == 0 {
			return
		}
		dfs(ps[i])
	}
	dfs(ps[s])

	if sum > 0 && k > 0 {
		cc := k / l
		if k%l == 0 {
			cc = (k - 1) / l
		}
		sum += sum * cc
		mx = max(mx, sum)
		k -= cc * l
		done = make([]bool, n)
		dfs(ps[s])
	}

	return mx
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

int main() {
  int x,y,a=10000;
  cin>>x;
  for(int i=0;i<x;i++){
    cin>>y;
    int b=0;
    while(y%2==0){
      y/=2;
      b++;
    }
    if(a>b)
      a=b;
  }
  cout<<a<<endl;
}
      


Measured memory_bytes: 256