akhauriyash/Code-Regression huggingface dataset:
//In The Name of Beauty
//...So here I go is my shot
//Feet fail me not 'cause maybe the only opportunity that I got...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e4 + 8;
ll const KAM  = 1e2 + 8;
ll const delta = 1000000007;
ll dp[MAXN][KAM];
int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    string k;
    cin >> k;
    ll d;
    cin >> d;
    dp[0][0] = 1;
    for(ll i = 0;i < MAXN - 1;i++)
    {
        for(ll j = 0;j < d;j++)
        {
            for(ll k = 0;k < 10;k++)
            {
                dp[i + 1][(k + j) % d] = (dp[i + 1][(k + j) % d] + dp[i][j]) % delta;
            }
        }
    }
    ll ans = 0;
    ll temp = 0;
    for(ll i = 0;i < k.size();i++)
    {
        for(ll j = (k[i] - '0') - 1;j >= 0;j--)
        {
            ans = (ans + dp[k.size() - i - 1][(d - (temp + j) + d) % d]) % delta;
        }
        temp = (temp + (k[i] - '0')) % d;
    }
    if(temp % d != 0)ans = (ans - 1 + delta) % delta;
    cout << ans;
    return 0;
}
//Written by M_H_H_7


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

using namespace std;

int n;

string s;

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

    cin >> n;

    cin >> s;

    int ps = 0;
    for (int i = 1; i <= n; i++) {
        switch (s[i - 1]) {
            case '(':
                ps++;

                break;

            case ')':
                ps--;

                break;
        }

        if (ps < 0) {
            cout << '(';
        }

        ps = max(0, ps);
    }

    cout << s;

    for (int i = 0; i < ps; i++) {
        cout << ')';
    }

    cout << endl;

    return 0;
}


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

using namespace std;

#define long long long
#define ft(i, a, b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (long i = (long)a ; i >= (long)b ; i--)
#define X first 
#define Y second

const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;

long n , m , h[mxN] , ans , cnt[mxN];
bool mark[mxN];
pair < long , long > a[mxN];

void Solve() {
    sort(a + 1 , a + m + 1);
    ft(i , 1 , m) {
        int u = a[i].X , v = a[i].Y;
        if (h[u] <= h[v]) mark[u] = true;
        if (h[v] <= h[u]) mark[v] = true;
    }
    ft(i , 1 , n) if (mark[i] == false) ans++;
    cout << ans;
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n >> m;
    ft(i , 1 , n) cin >> h[i];
    ft(i , 1 , m) cin >> a[i].X >> a[i].Y;
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 6040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,3) if(s[i]=='1') cnt++;
  cout << cnt << endl;
  return 0;
}


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


string name[20];
int m[20];
int d[20][30];
int point[20];

int main(){
	int n;
	while(cin>>n&&n){
		map<int,int> mp;
		memset(point,0,sizeof(point));
		for(int i=0;i<n;i++){
			cin>>name[i]>>m[i];
			for(int j=0;j<m[i];j++){
				cin>>d[i][j];
				++mp[d[i][j]];
			}
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<m[i];j++){
				point[i]+=n+1-mp[d[i][j]];
			}
		}
		string ans;
		int minp=1<<30;
		for(int i=0;i<n;i++){
			if(point[i]<minp || point[i]==minp&&name[i]<ans){
				minp=point[i];
				ans=name[i];
			}
		}
		cout<<minp<<' '<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a >= 13)
		cout << b;
	else if (a >= 6 && a <= 13)
		cout << b / 2;
	else if (a <= 5)
		cout << 0;
	return 0;
}
/*
时间限制: 2秒/内存限制: 1024 MB
成绩: 100 分

问题陈述
高桥，A岁，正在坐一个摩天轮。
如果您年满13岁或以上，则需支付B日元（B是偶数）乘坐摩天轮，但6至12岁（含）的儿童可免费乘坐一半的费用，5岁或5岁以下的儿童免费。（日元是日本的货币。）
找出高桥摩天轮的成本。

限制
•0≤A≤100
0≤A≤100
•2≤B≤1000
2≤B≤1000
·B是一个偶数。

输入
输入由标准输入以以下格式提供:
A B

输出
打印高桥摩天轮的成本。

样本输入1
30 100

样本输出1
100
高桥现在已经30岁了，摩天轮的费用是100日元。

样本输入2
12 100

样本输出2
50
高桥12岁
12
年，摩天轮的成本是100的一半
100日元，即50日元。

样本输入3
0 100

样本输出3
0
高桥是0岁，他可以免费乘坐摩天轮。
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    int count=0;
    for (int i=1;i<=n;i++) {
        if (i==1) {
            if (deq[i-1]==i) {
                swap(deq[i-1],deq[i]);
                count++;
            }
        } else if (i==n) {
            if (deq[i-1]==i) {
                swap(deq[i-1],deq[i-2]);
                count++;
            }
        } else {
            if (deq[i-1]==i) {
                swap(deq[i-1],deq[i]);
                count++;
            }
        }
    }
    cout<<count<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int x;
    cin >> x;

    if(x < 1200){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main(){
  int n,l;
  scanf("%d %d",&n,&l);

  char temp[101];
  char str[100][101];

  int i,j;
  for(i=0;i<n;i++){
    scanf("%s",&str[i]);
  }

  for(i=0;i<(n-1);i++){
    for(j=(n-1);j>i;j--){
      if(strcmp(str[j-1],str[j])>0){
        strcpy(temp,str[j-1]);
        strcpy(str[j-1],str[j]);
        strcpy(str[j],temp);
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%s",str[i]);
  }
  return 0;
}

Measured memory_bytes: 1740
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	
	final long MOD =  (long)(1e9+7);
	void solve() {
		int N = sc.nextInt();
		long T = sc.nextLong();
		long[] t = new long[N];
		for (int i = 0; i < N; i++) t[i] = sc.nextLong();
		
		long ans = 0;
		long r = 0;
		for (int i = 0; i < N; i++) {
			ans += T;
			if (r > t[i]) {
				ans -= r - t[i];
			}
			r = t[i] + T;
		}
		
		out.println(ans);
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 50280
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    string a ,b;
    cin >> a >> b;
    string s = a;
    s += b;
    ll k = 0;
    rep(i, s.size()){
        k = (k*10 + s[i]-'0');
    }
    ll aa = sqrt(k);
    cout << (aa*aa == k ? "Yes": "No");
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    int maximum = max(H, W);
    if (N % maximum == 0) cout << N / maximum << endl;
    else cout << N / maximum + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int X;
cin >>X;
vector <bool > expo(X+1);
expo[1] = 1;
for(int b=2;b<=X;b++){
int v = b*b;
while(v<=X){
expo[v] = 1;
v *= b;
}
}
for(int i=X;i>=1;i--) if(expo[i]){
cout <<i<<endl;
return 0;
}
}


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

int main() {
  int N; // 2~8
  int itr=1;
  int p_pos, q_pos;

  cin >> N;

  vector<int> P(N);
  vector<int> Q(N);

  for (int i=0; i<N; i++) {
    cin >> P.at(i);
  }
  for (int i=0; i<N; i++) {
    cin >> Q.at(i);
  }

  vector<int> v(N);
  iota(v.begin(), v.end(), 1);
  do {
      if (P == v) p_pos = itr;
      if (Q == v) q_pos = itr;
      itr++;
  } while( next_permutation(v.begin(), v.end()) );

  cout << abs(p_pos - q_pos) << endl;
}

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

int com(const char *x,const char *y){
    return strcmp(x,y);
}

int main(){
    int n,l,i;
    char s[101][101];
    scanf("%d %d",&n,&l);
    for (i=0; i<n; i++) scanf("%s",s[i]);
    qsort(s, n, sizeof(s[0]), com);
    for (i=0; i<n; i++) printf("%s",s[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
int main(){
  #define int long long
  int H,W;
  cin>>H>>W;
  int ch,cw,dh,dw;
  cin>>ch>>cw>>dh>>dw;
  vector<string> vec(H);
  vector<vector<int>> tree(H*W,vector<int>(0));
  for(int i=0;i<H;i++){
    cin>>vec.at(i);
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=i-2;k<=i+2;k++){
        for(int l=j-2;l<=j+2;l++){
          if(k>=0 && k<H && l>=0 && l<W){
            if(vec.at(k).at(l)=='.'){
              tree.at(i*W+j).push_back(k*W+l);
            }
          }
        }
      }
    }
  }
  vector<int> dist(H*W,-1);
  vector<int> determined(H*W,0);
  priority_queue<P,vector<P>,greater<P>> que;
  que.push(make_pair(0,(ch-1)*W+cw-1));
  dist.at((ch-1)*W+cw-1)=0;
  while(!que.empty()){
    int v=que.top().second;
    int p=que.top().first;
    que.pop();
    if(determined.at(v)==1){
      continue;
    }
    determined.at(v)=1;
    for(int i=0;i<(int)tree.at(v).size();i++){
      int nv=tree.at(v).at(i);
      if(determined.at(nv)==1){continue;}
      int memo=dist.at(v);
      int sa=nv-v;
      if(sa==1 || sa==-1 || sa==W || sa==-W){}
      else{memo++;}
      if(dist.at(nv)!=-1 && memo>=dist.at(nv)){continue;}
      if(dist.at(nv)==-1){
        dist.at(nv)=memo;
        que.push(make_pair(memo,nv));
        //cout<<v+1<<" "<<nv+1<<" "<<dist.at(nv)<<endl;
      }
      if(dist.at(nv)!=-1 && memo<dist.at(nv)){
        dist.at(nv)=memo;
        que.push(make_pair(memo,nv));
        //cout<<v+1<<" "<<nv+1<<" "<<dist.at(nv)<<endl;
      }
      dist.at(nv)=memo;
    }
  }
  cout<<dist.at((dh-1)*W+dw-1)<<endl;
}

Measured memory_bytes: 188280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	ll wei,num;
}a[2005];
ll dp[2005][2005]={0};
ll n;
bool cmp(node a1,node a2)
{
	return a1.num>a2.num;
}
ll fen(ll num,ll l,ll r)
{
	if(num>n) return 0;
	if(l==r) return dp[l][r]=a[num].num*abs(a[num].wei-l);
	if(dp[l][r]!=-1) return dp[l][r];
	ll ans1=fen(num+1,l+1,r)+a[num].num*abs(a[num].wei-l);
	ll ans2=fen(num+1,l,r-1)+a[num].num*abs(a[num].wei-r);
	return dp[l][r]=max(ans1,ans2);
}
int main(void)
{

	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i].num);
		a[i].wei=i;
	}
	sort(a+1,a+n+1,cmp);
	memset(dp,-1,sizeof(dp));
	fen(1,1,n);
	cout<<fen(1,1,n);
}

Measured memory_bytes: 35368
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
  public class AOJ {
    public static void Main(string[] args) {
      int count = int.Parse(Console.ReadLine());
      var li = Console.ReadLine().Split(' ').Select(long.Parse).Take(count);
      Console.WriteLine("{0} {1} {2}", li.Min(), li.Max(), li.Sum());
    }
  }
}

Measured memory_bytes: 10180
// finish date: 2018/09/29

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> c1(100001), c2(100001);
    rep(i, 100001) {
        c1[i].second = i;
        c2[i].second = i;
    }
    rep(i, n) {
        int v;
        cin >> v;
        if (i % 2 == 0) c1[v].first++;
        else c2[v].first++;
    }
    sort(c1.begin(), c1.end());
    sort(c2.begin(), c2.end());
    reverse(c1.begin(), c1.end());
    reverse(c2.begin(), c2.end());
    if (c1[0].second != c2[0].second) {
        cout << n - c1[0].first - c2[0].first;
    } else {
        cout<<min(n - c1[0].first - c2[1].first,n - c1[1].first - c2[0].first);
    }

    return 0;
}



Measured memory_bytes: 1792
a = list(map(int,input().split()))

f = 0
for i in a:
    if i % 2 == 0:
        f = 1

if f:
    ans = 0
else:
    tmp = []
    for i in range(2):
        for j in range(i+1,3):
            tmp.append(a[i] * a[j])
    #print(tmp)
    ans = min(tmp)

print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) {
            cout << "No\n";
            return 0;
        }
    }
    if (t.size() != n + 1) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}
/*

*/  

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n, ans = 1;
map<int, set<P> > vx, vy;
P3 pos[3005];

int main() {
    cin >> n;
    REP(i,n){
        int x, y, dir;
        char d;
        cin >> x >> y >> d;
        if(d == '>') dir = 0;
        if(d == 'v') dir = 1;
        if(d == '<') dir = 2;
        if(d == '^') dir = 3;
        vx[x].insert({y,dir});
        vy[y].insert({x,dir});
        pos[i] = {{x,y},dir};
    }
    REP(i,n){
        auto xs = vx, ys = vy;
        int px = pos[i].first.first, py = pos[i].first.second, dir = pos[i].second, cnt = 1;
        while(1){
            xs[px].erase({py,dir});
            ys[py].erase({px,dir});
            if(dir == 0){
                auto p = ys[py].upper_bound({px,-1});
                if(p==ys[py].end())break;
                px = (*p).first;
                dir = (*p).second;
                cnt++;
            }
            else if(dir == 1){
                auto p = xs[px].upper_bound({py,-1});
                if(p==xs[px].end())break;
                py = (*p).first;
                dir = (*p).second;
                cnt++;
            }
            else if(dir == 2){
                if(ys[py].size()==0) break;
                auto p = ys[py].upper_bound({px,-1});
                if(p==ys[py].begin())break;
                p--;
                px = (*p).first;
                dir = (*p).second;
                cnt++;
            }
            else if(dir == 3){
                if(xs[px].size()==0) break;
                auto p = xs[px].upper_bound({py,-1});
                if(p==xs[px].begin())break;
                p--;
                py = (*p).first;
                dir = (*p).second;
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4488
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
p = list(map(int, input().split()))
ans = -1

for i in range(0,102):
    if i not in p:
        if abs(i-X) < abs(ans-X):
            ans = i
print(ans)

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

int main(void)
{
	char c;
	int num;

	while(true){
		int x = 0;
		int one = 0;
		int sum = 0;
		while(scanf("%d", &num)){
			if(num > 10)
				num = 10;
			if(num == 1)
				one++;
			else
				sum += num;

			scanf("%c", &c);
			if(c == '\n')
				break;
		}
		if(num == 0 && one == 0)
			break;

		if(sum > 21)
			cout << 0 << endl;
		else {
			if(one > 0){
				if(sum + 11 + (one-1) <= 21)
					cout << sum + 11 + (one-1) << endl;
				else if(sum + one <= 21)
					cout << sum + one << endl;
				else
					cout << 0 << endl;
			}
			else
				cout << sum + one << endl;
		}

	}

	return 0;
}

		

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root,NIL;
int maxh;

void insert(int x){
  int H;
  Node b=NIL;
  Node a = root;
  Node c;

  c = malloc(sizeof(struct node));
  c->key =x;
  c->left = NIL;
  c->right = NIL;

  while(a!=NIL){
    b=a;
    if(c->key < a->key){
      a = a->left;
    }
    else{
      a = a->right;
    }
  }

  c ->parent = b;

  if(b ==NIL){
    root =c;
  }
  else{
    if(c->key < b->key){
      b->left =c;
    }
    else{
      b->right =c;
    }
  }
}
 
void inorder(Node x){
  if(x == NIL){
    return;
  }
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}
void preorder(Node x){
  if( x ==NIL) {
    return;
  }
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

int main(){
  int i,num,x;
char com[20];
scanf("%d",&num);
maxh=0;
for(i=0;i<num;i++){
  scanf("%s",com);
  if(strcmp(com,"insert")==0){
    scanf("%d",&x);
    insert(x);
  }
  else if(strcmp(com,"print")==0){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
  }
 }
return 0;
}



Measured memory_bytes: 25296
#include <stdio.h>

/* -------- main code -------- */
int    main(void)
{
    int    k, s;
    int    x, y, z;
    int    ptn;
    int    s_ret;

    s_ret = scanf("%d %d", &k, &s);

    ptn = 0;
    for(x = 0; x <= k; x++){
        for(y = 0; y <= k; y++){
            z = s - (x + y);
            if((0 <= z) && (z <= k)){
                ptn++;
            }
        }
    }

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

    return (0);
}

Measured memory_bytes: 128
#include <iostream>
#include <set>

int main() {
    int N;
    std::cin >> N;
    std::set<int> s;
    for (int i = 0; i < N; ++i) {
        int e;
        std::cin >> e;
        s.insert(e);
    }

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int k;
        std::cin >> k;
        if (!s.count(k)) {
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    std::cout << 1 << std::endl;
}



Measured memory_bytes: 12472
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  string s;
  cin>>s;
  int i1 = stoi(s.substr(0,4));
  int i2 = stoi(s.substr(5,2));
  int i3 = stoi(s.substr(8,2));


  if(i1>=2020){
    cout<<"TBD"<<endl;
    return 0;
  }else if(i1==2019&&i2>=5){
        cout<<"TBD"<<endl;
    return 0;
  }else if(i2==4&&i3>=31){
        cout<<"TBD"<<endl;
    return 0;
  }
  cout<<"Heisei"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
#define int long long
 
signed main(){

	int n;
	cin>>n;

	int t[n];
	int x[n];
	int y[n];

	int tmp=0;
	int time;
	int distance;

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

	if(n==1){

		distance=x[0]+y[0];

		if(t[0]<distance){
			cout<<"No"<<endl;
		}else{
			if((t[0]-distance)%2==0){
				cout<<"Yes"<<endl;
			}else{
				cout<<"No"<<endl;
			}
		}

		return 0;
	}

	for(int i=0;i<n;i++){
		if(i==0){
			distance=x[i]+y[i];
			time=t[i];
		}else{
			distance=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
			time=t[i]-t[i-1];
		}

		if(time<distance){
			cout<<"No"<<endl;
			return 0;
		}else{
			if((time-distance)%2==0){
				//pass
			}else{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int rev[3] = {2,1,0};
int seki[3][3] = {{0,0,0},{0,1,1},{0,1,2}};
int wa[3][3] = {{0,1,2},{1,1,2},{2,2,2}};

int f(const string &s, int b, int e){ // [begin,end]
    int ind = -1;
    int nest = 0;
    loop(i,b,e){
        if(s[i] == '(') nest++;
        if(s[i] == ')') nest--;
        if((s[i] == '*' || s[i] == '+') && nest == 0)  ind = i;
    }
    int ret = -1;
    if(ind < 0){
        if(s[b] == '(' && s[e] == ')'){
            return f(s, b+1, e-1);
        }
        int t = 0;
        while(s[b] == '-')b++,t++;
        if(s[b] == '(')
            ret = f(s,b+1,e);
        else
            ret = s[b] - '0';
        if(t%2)ret = rev[ret];
        //cout << b <<" " << e << " " <<ret <<endl;
        return ret;
    }else{
        ret = f(s, b, ind-1);
        if(s[ind] == '+') ret = wa[ret][f(s,ind+1,e)];
        else ret = seki[ret][f(s,ind+1,e)];
    //    cout << b << " " << e <<" " <<ret << endl;
        return ret;
    }
}

int solve(string s, int a, int b, int c){
    int n = s.size();
    rep(i,n){
        if(s[i] == 'P') s[i] = '0' + a;
        if(s[i] == 'Q') s[i] = '0' + b;
        if(s[i] == 'R') s[i] = '0' + c;
    }
    //cout << s << endl;
    int ret = f(s, 0, n-1);
    //cout << ret << endl;
    return ret;
}

int main(void) {
  string s;
  while(cin >> s, s != "."){
      int ans = 0;
      rep(i,3)rep(j,3)rep(k,3){
          //cout << i << " " << j << " " << k <<endl;
          if(solve(s,i,j,k) == 2)ans++;
        //  cout << solve(s,i,j,k) << endl;
      }
      cout << ans << endl;
  }
}



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

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

    int a, b, idx = 1;
    do {
        if (retu == p) a = idx;
        if (retu == q) b = idx;
        idx++;
    } while (next_permutation(retu.begin(), retu.end()));

    int ans = abs(a - b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
int n;
int r[MAX];
cin>>n;
for(int i=0 ; i<n; i++){
    cin>>r[i];
}
int maxv=-2000000000;
int minv=r[0];
for (int i=1 ;i<n;i++){
    maxv=max(maxv,r[i]-minv);
    minv=min(minv,r[i]);
}
cout<<maxv<<endl;
return 0;
}


Measured memory_bytes: 3888
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        int res = 0;
        int p = 0;
        for(int i=1; i<n; i++) {
            if(a[i-1]>=a[i]) {
                p++;
                res = Math.max(res, p);
            } else {
                p = 0;
            }
        }
        System.out.println(res);


    }

}


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

#define elemof(n) (sizeof(n) / sizeof(*n))

int input(long *lst, size_t size);
int max_index(long *lst, size_t size);
int min_index(long *lst, size_t size);

int main(void){
    long data[200001] = {0};
    long maxVal = -10000000000;
    int n = 0;
    int maxIndex, minIndex;
    int i ,next_i = 0;
    long Ri , Rj = 0;
    long val = 0;

    n = input(data, elemof(data)); /* ???????????????????????? */

    /* ???????????????????°?????????????????????????????????? (?????????) */
    minIndex = min_index(data , n);

    for (i = 0 ; i < n ; i++){
        Ri = data[i];

        //printf("i:%d\n" , i);
        next_i = i + 1;
        if (next_i < n){
            if(maxIndex < next_i){
                /* ????????????????????§????????????????????????????????? (?????????) */
                maxIndex = max_index(&data[next_i] , n - next_i);
                maxIndex += next_i;
            }
            Rj = data[maxIndex];

            val = Rj - Ri;
            if (maxVal < val){
                maxVal = val;
            }
            
        }

        if (i == minIndex){
            break;
        }
    }

    printf("%ld\n", maxVal);
    return 0;
}

int input(long *lst, size_t size){
    char str[12] ;
    int n = 0;
    int i;
    /* ?????????????????°????????? */
    fgets(str , elemof(str) , stdin);
    n = atoi(str);

    for(i = 0 ; i < n ; i++){
        fgets(str , elemof(str) , stdin);
        if(i < size){
            lst[i] = atoi(str);
        }
    }
    return n;
}

/* ?????????????????§??????????????????????????????????????? (?????????) */
int max_index(long *lst, size_t size){
    long maxVal = 0;
    int maxIndex = 0;
    int i;
    for(i = 0 ; i < size ; i++){
        if (maxVal < lst[i]){
            maxVal = lst[i];
            maxIndex = i;
        }
    }
    return maxIndex;
}

/* ????????????????°???????????????????????????????????????? (?????????) */
int min_index(long *lst, size_t size){
    long minVal = 1000000000;
    int minIndex = 0;
    int i;
    for(i = 0 ; i < size ; i++){
        if (minVal > lst[i]){
            minVal = lst[i];
            minIndex = i;
        }
    }
    return minIndex;
}

Measured memory_bytes: 2104
n=int(input())
a=list(map(int, input().split()))

money=1000

chart=[a[0]]

for kabuka in a:
    if kabuka==chart[-1]:
        continue
    else:
        chart.append(kabuka)

days=len(chart)
kabu=0

if days==1:
    print(money)
    exit()

for i in range(days):
    if i==0:
        if chart[0]<chart[1]:
            kabu=money//chart[0]
            money%=chart[0]

    elif i==days-1:
        money+=kabu*chart[i]
        kanu=0
    
    else:
        if chart[i-1]<chart[i] and chart[i]>chart[i+1]:
            money+=kabu*chart[i]
            kabu=0

        if chart[i-1]>chart[i] and chart[i]<chart[i+1]:
            kabu=money//chart[i]
            money%=chart[i]

print(money)

Measured memory_bytes: 9248
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long x[110000];
long long dp[41][2];
int main(){
	int a;
	long long b;
	scanf("%d%lld",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%lld",x+i);
	}
	for(int i=0;i<41;i++)for(int j=0;j<2;j++)dp[i][j]=-inf;
	dp[40][1]=0;
	for(int i=39;i>=0;i--){
		int A=0;
		int B=0;
		for(int j=0;j<a;j++){
			if(x[j]&(1LL<<i))A++;
			else B++;
		}
		dp[i][0]=max(dp[i][0],dp[i+1][0]+(1LL<<i)*max(A,B));
		if(b&(1LL<<i)){
			dp[i][0]=max(dp[i][0],dp[i+1][1]+(1LL<<i)*A);
			dp[i][1]=max(dp[i][1],dp[i+1][1]+(1LL<<i)*B);
		}else{
			dp[i][1]=max(dp[i][1],dp[i+1][1]+(1LL<<i)*A);
		}
	}
	long long ret=max(dp[0][0],dp[0][1]);
	printf("%lld\n",ret);
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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



int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    bool flag = true;
    int n;
    string s;
    cin >> n >> s;
    if(n&1)flag = false;
    string t = s.substr(0,n/2);
    if(t+t != s)flag = false;
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}
	

Measured memory_bytes: 256
#include<stdio.h>
int main();
int solve(int, int);
int n,A[50];
int main(){
  int q,m,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  int r;
  if(m==0) return 1;
  if(i>=n) return 0;
  r=solve(i+1,m) || solve(i+1,m-A[i]);
  return r;
}



Measured memory_bytes: 2052
S=input()
str_list=["dreamer","eraser","dream","erase"]
     
while True:
  S_tmp=S
  for str in str_list:
    if S[-len(str):]==str:
      S=S[0:len(S)-len(str)]
        
  if S_tmp==S:
    break    
        
if S=="":
  print("YES")
if S!="":
  print("NO")  

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

const ll INF = 1e18;

template <typename C>
bool warshall_floyd(vector<vector<C>>& G) {
	int n = G.size();
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (G[i][k] == INF || G[k][j] == INF || G[i][j] <= G[i][k] + G[k][j]) continue;
				G[i][j] = G[i][k] + G[k][j];
			}
		}
	}
	for (int i = 0; i < n; i++) if (G[i][i] < C()) return true;
	return false;
}

template <typename C>
void add_edge(vector<vector<C>>& G, int s, int t, C c) {
	G[s][t] = min(G[s][t], c);
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int V, E;
	cin >> V >> E;
	vector<vector<ll>> G(V, vector<ll>(V, INF));
	for (int i = 0; i < V; i++) G[i][i] = 0;
	for (int i = 0; i < E; i++) {
		int s, t;
		ll d;
		cin >> s >> t >> d;
		add_edge(G, s, t, d);
	}
	if (warshall_floyd(G)) {
		puts("NEGATIVE CYCLE");
	}
	else {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				if (G[i][j] == INF) {
					printf("INF%c", " \n"[j + 1 == V]);
				}
				else {
					printf("%lld%c", G[i][j], " \n"[j + 1 == V]);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  double kotae;
  for(int i=0;i<n;i++){
    kotae+=(double)1/(double)a[i];
  }
  kotae=(double)1/kotae;
  cout<<fixed<<setprecision(12)<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
def main():
	S = input()
	head = 0
	tail = len(S)-1
	for i, c in enumerate(S):
		if c == "A":
			head = i
			break

	for i in range(tail, head, -1):
		if S[i] == "Z":
			tail = i
			break
	print(tail-head+1)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
string s;
int main()
{
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> s;
    if(s[s.length()-1] == '3')cout << "bon";
    else if(s[s.length()-1] == '0' || s[s.length()-1] == '1' || s[s.length()-1] == '6' || s[s.length()-1] == '8')cout << "pon";
    else cout << "hon";
    return 0;
}


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

int main(){
  int n,x,m,min=100000;
  cin >> n >> x;
  for(int i=0;i<n;i++){
    cin >> m;
    if(m < min) min = m;
    x -= m;
  }
  cout << n + x/min << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets(chomp:true).to_i
a = gets.split.map(&:to_i)

def partition(a, p, r)
  x = a[r]
  i = p - 1
  (p...r).each do |j|
    if a[j] <= x
      i += 1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i + 1], a[r] = "[#{a[r].to_s}]", a[i + 1]
  puts a.join(" ")
end

partition(a, 0, n - 1)


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

int main(){
    while(1){

    int n,sum=0; cin>>n;

    if(n ==0) break;

    vector<int> inc(n);

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

        cin>>inc.at(i);

        sum += inc.at(i);
    }


    int count=0,avg = sum / n;

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

        if( avg >= inc.at(i)) count++;
    }

    cout<<count<<endl;
    }

    return 0;
}


Measured memory_bytes: 3144
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

N,K = map(int,input().split())

fac = [0]*(N+1)
fac[0] = 1
fac[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1] * i % mod

def combi(n,r,mod=10**9+7):
    return( ( fac[n] * modinv(fac[r]) )%mod * modinv(fac[n-r]) % mod)

for j in range(1,K+1):
    if N - K + 1 < j:
        print(0)
    else:
        print(combi(N-K+1,j) * combi(K-1,j-1) % mod)

Measured memory_bytes: 41840
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define MAX 100010
int p[MAX] = {0};

int parent(int i) {
    if (p[i] == i) return i;
    return p[i] = parent(p[i]);
}

int main() {
    int n, m ;
    int x, y, z;
    cin >> n >> m;
    int ans = n;
    for (int i=1;i<=n;i++) {
        p[i] = i;
    }
    for (int i=1;i<=m;i++) {
        cin >> x >> y >> z;
        int px = parent(p[x]);
        int py = parent(p[y]);
        if (px != py) {
            p[px] = py;
            ans --;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
if __name__ == '__main__':
    A, B = map(int, input().split())

    K2 = (A+B)

    answer = 'IMPOSSIBLE'
    if 2*A-K2 == -1 * (2*B-K2) and (A+B)%2==0:
        answer = K2//2

    print(answer)



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

signed main() {
    int n,a,b;
    string s;
    cin >> n >> a >> b >> s;

    int tot = 0;
    int abr = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'a'){
            if(tot < a + b) {
                tot++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if(s[i] == 'b'){
            abr++;
            if(tot < a + b && abr <= b){
                tot++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,m,head[MN+5],cnt=1,ans=0,f[MN+5],g[MN+5][2],Fa[MN+5],dep[MN+5],A,B,C,c[MN+5],num,mn=1e9,q[MN+5],top;
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
    e[++cnt]=(edge){t,head[f]};head[f]=cnt;
    e[++cnt]=(edge){f,head[t]};head[t]=cnt;
}
inline int Abs(int x){return x<0?-x:x;}
void dfs(int x,int fa=0)
{
    ++g[x][f[x]];
    for(int i=head[x];i;i=e[i].next)
        if(e[i].to!=fa)
        {
            if(x==A&&e[i].to==B) continue;
            if(x==B&&e[i].to==A) continue;
            f[e[i].to]=f[x]^1;dfs(e[i].to,x);
            g[x][0]+=g[e[i].to][0];
            g[x][1]+=g[e[i].to][1];
        }
    ans+=Abs(g[x][0]-g[x][1]);
}
void FindCircle(int x,int fa)
{
    Fa[x]=fa;
    for(int i=head[x];i;i=e[i].next)
        if(e[i].to!=fa)
        {
            if(dep[e[i].to]) A=x,B=e[i].to;
            else dep[e[i].to]=dep[x]+1,FindCircle(e[i].to,x);
        }
}
int main()
{
    n=read();m=read();if(n&1) return 0*puts("-1");
    if(m<n)
    {
        for(int i=1;i<n;++i) ins(read(),read());
        dfs(1);
        printf("%d\n",g[1][0]==g[1][1]?ans:-1);
    }
    else
    {
        for(int i=1;i<=n;++i) ins(read(),read());
        FindCircle(dep[1]=1,0);
        for(int x=A,y=B;x!=y;C=x=Fa[x])
            if(dep[x]<dep[y]) swap(x,y);
        for(int i=A;i!=C;i=Fa[i]) c[++num]=i;
        c[++num]=C;int len=dep[A]+dep[B]-2*dep[C]+1;num=len;
        for(int i=B;i!=C;i=Fa[i]) c[len--]=i;
        if(dfs(1),num&1)
        {
            if(Abs(g[1][1]-g[1][0])&1) return 0*puts("-1");
            int dif=(g[1][1]-g[1][0])/2;ans=Abs(dif);
            for(int i=A;i;i=Fa[i]) g[i][0]+=dif;
            for(int i=B;i;i=Fa[i]) g[i][0]+=dif;
            for(int i=1;i<=n;++i) ans+=Abs(g[i][0]-g[i][1]);
            printf("%d\n",ans);
        }
        else
        {
            if(g[1][0]!=g[1][1]) return 0*puts("-1");
            for(int i=A;i!=C;i=Fa[i]) q[++top]=g[i][0]-g[i][1];
            for(int i=B;i!=C;i=Fa[i]) q[++top]=g[i][1]-g[i][0];
            sort(q+1,q+top+1);
            int res;
            if(top&1) res=q[(top+1)/2];
            else res=Abs(q[top/2])<Abs(q[top/2+1])?q[top/2]:q[top/2+1];
            res=-res;
            for(int i=A;i;i=Fa[i]) g[i][0]+=res;
            for(int i=B;i;i=Fa[i]) g[i][1]+=res;
            ans=Abs(res);for(int i=1;i<=n;++i) ans+=Abs(g[i][0]-g[i][1]);
            printf("%d\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC146E
{
    class Program
    {
        public static long Solve(long n, long k, long[] a)
        {
            var numbers = new Dictionary<long, int>();
            var queue = new Queue<long>();
            long ans = 0;
            //var dic = new Dictionary<long, long>();
            var s = Sums(a).ToArray();
            Func<long, long> f = i => Math.Abs(i - s[i]) % k;

            for (long j = 0; j <= n; ++j)
            {
                var key = f(j);
                ans += numbers.ContainsKey(key) ? numbers[key] : 0;
                if (numbers.ContainsKey(key)) numbers[key] += 1;
                else numbers[key] = 1;
                queue.Enqueue(key);
                if (k < j + 2)
                {
                    numbers[queue.Dequeue()] -= 1;
                }
            }
            return ans;
        }

        private static IEnumerable<long> Sums(long[] a)
        {
            long s = 0;
            yield return s;
            foreach (var ai in a)
            {
                s += ai;
                yield return s;
            }
        }


        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');

            long n = Convert.ToInt64(line[0]);
            long k = Convert.ToInt64(line[1]);
            long[] a = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt64);
            Console.WriteLine(Solve(n, k, a));
        }
    }
}


Measured memory_bytes: 54688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long int MOD = 1000000007;
const long long  INF = 1LL << 60;

bool solve(string S){
    for(int i = 0; i < S.size()-1; i++){
        if (S[i] != S[i+1]) return true;
    }
    return false;
}

int main(void){
    string S; cin >> S;
    
    if(solve(S)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
S = [int(sys.stdin.readline()) for _ in range(N)]

S = np.array(S)
ans = S.sum()
if ans % 10 == 0:
    if np.any(S % 10 != 0):
        ans -= S[S % 10 != 0].min()
    else:
        ans = 0
print(ans)



Measured memory_bytes: 13636
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            if (input.Length == 3 && input.Contains("a") && input.Contains("b") && input.Contains("c"))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int N , K; char str[200003];

int main(){
	deque < char > ans; int rev = 0; scanf("%d %d %s" , &N , &K , str + 1);
	for(int i = 1 ; i <= N ; ++i) ans.push_back(str[i]);
	if(N == 1){putchar(K & 1 ? 'A' + 'B' - str[1] : str[1]); return 0;}
	
	int cnt = 0; for(int i = 1 ; i < ans.size() ; ++i) cnt += ans[i] != ans[i - 1];
	while(cnt + 1 < ans.size() && K--)
		if((ans.front() == 'A') ^ rev){ans[1] != ans[0] ? --cnt : ++cnt; ans[0] = 'A' + 'B' - ans[0];}
		else{cnt += (ans.front() != ans.back()) - (ans[0] != ans[1]); ans.push_back(ans.front()); ans.pop_front(); rev ^= 1;}
	if(K > 0){
		for(int i = 1 ; i <= 2 * N && K-- ; ++i)
			if((ans.front() == 'A') ^ rev) ans.front() = 'A' + 'B' - ans.front();
			else{ans.push_back(ans.front()); ans.pop_front(); rev ^= 1; ++cnt;}
		if(K > 0){
			K %= 2 * N;
			while(K--)
				if((ans.front() == 'A') ^ rev) ans.front() = 'A' + 'B' - ans.front();
				else{ans.push_back(ans.front()); ans.pop_front(); rev ^= 1; ++cnt;}
		}
	}
	for(auto t : ans) putchar(rev ? 'A' + 'B' - t : t);
	return 0;
}


Measured memory_bytes: 896