akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
struct City {
    int p, y, i, n;
};
void Main(){
    int N = read(), M = read();
    vector<City> C(M);
    for (int i = 0; i<M; i++) {
        C[i].p = read();
        C[i].y = read();
        C[i].i = i;
    }
    sort(C.begin(), C.end(), [](const City& a, City& b){return a.y<b.y;});
    vector<int> O(N, 0);
    for (auto &c:C) {
        O[c.p]++;
        c.n = O[c.p];
    }
    sort(C.begin(), C.end(), [](const City& a, City& b){return a.i<b.i;});
    for (auto c:C) printf("%012lld\n", (long long)c.p*1000000+c.n);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int erase(vector<vector<int>>& bd){
	for(int i=0;i<bd.size();i++){
		for(int j=0;j<3;j++){
			if( bd[i][j]%10 == bd[i][j+1]%10 && bd[i][j+1]%10 == bd[i][j+2]%10 ){
				bd[i][j] += 10;
				bd[i][j+1] += 10;
				bd[i][j+2] += 10;
			}
		}
	}
	int points = 0;
	for(int i=0;i<bd.size();i++){
		for(int j=0;j<5;j++){
			if(bd[i][j] >= 10){
				points += bd[i][j]%10;
				bd[i][j] = 0;
			}
		}
	}
	return points;
}
void drop(vector<vector<int>>& bd){
	bool update = true;
	while(update){
		update = false;
		for(int i=1;i<bd.size();i++){
			for(int j=0;j<5;j++){
				if(bd[i][j] == 0 && bd[i-1][j] != 0){
					bd[i][j] = bd[i-1][j];
					bd[i-1][j] = 0;
					update = true;
				}
			}
		}
	}
}
bool solve(){
	int H;
	cin >> H;
	if(H == 0)return false;
	vector<vector<int>> bd(H,vector<int>(5));
	for(int i=0;i<H;i++){
		for(int j=0;j<5;j++){
			cin >> bd[i][j];
		}
	}
	int ret = 0,p;
	while((p = erase(bd)) != 0){
		ret += p;
		drop(bd);
	}
	cout << ret << endl;
	return true;
}



int main(void){
	while(solve()){
		
	}
	return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const double INF = 1e18;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool eq(double x, double y){ return abs(x - y) < EPS; }
struct Point{
  int x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  Point operator+(const Point& b) const { return Point(x + b.x, y + b.y); }
  Point operator-(const Point& b) const { return Point(x - b.x, y - b.y); }
  Point operator*(const double b) const { return Point(x * b, y * b); }
  Point operator*(const Point& b) const { return Point(x * b.x - y * b.y, x * b.y + y * b.x); }
  Point operator/(const double b) const { return Point(x / b, y / b); }
  bool operator< (const Point& b) const { return x != b.x ? x < b.x : y < b.y; }
  bool operator==(const Point& b) const { return eq(x, b.x) && eq(y, b.y); }
  int norm(){ return x * x + y * y; }
  double arg(){ return atan2(x, y); }
  double abs(){ return sqrt(norm()); }
  Point rotate(double theta){ return Point(cos(theta) * x - sin(theta) * y, sin(theta) * x + cos(theta) * y); }
  Point rotate90(){ return Point(-y, x); }
};

bool compare_y(const Point& a, const Point& b){
  return a.y < b.y;
}

int closest_pair(vector<Point>::iterator begin, vector<Point>::iterator end){
  int N = end - begin;
  if(N == 1) return INF;
  int M = N / 2;
  int mx = (begin + M)->x; //中心のx座標
  int d = min(closest_pair(begin, begin + M), closest_pair(begin + M, end));
  inplace_merge(begin, begin + M, end, compare_y); //y座標でソート

  vector<Point> b;
  for(vector<Point>::iterator it1 = begin; it1 != end; it1++){
    if(abs(it1->x - mx) >= d) continue;
    for(vector<Point>::reverse_iterator it2 = b.rbegin(); it2 != b.rend(); it2++){
      Point dfp = *it1 - *it2;
      if(dfp.y >= d) break;
      d = min(d, dfp.norm());
    }
    b.push_back(*it1);
  }

  return d;
}

int main(){
  int N;
  while(cin >> N && N){
    vector<Point> ps(N);
    REP(i, N){
      scanf("%d %d", &ps[i].x, &ps[i].y);
    }
    sort(ps.begin(), ps.end());
    cout << closest_pair(ps.begin(), ps.end()) << endl;
  }
  return 0;
}

Measured memory_bytes: 10824
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, res = 0;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	cout << d[n / 2] - d[n / 2 - 1];
	//system("pause");
	return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 7;

ll dp[MAXN][14];
int main(){
    int n;
    string s;
    cin >> s;
    n = s.size();
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i){
        if(s[i-1] == '?'){
            for(int j = 0; j <= 9; ++j){
                for(int k = 0; k <= 12; ++k){
                    dp[i][(j+k*10)%13] += dp[i-1][k];
                    dp[i][(j+k*10)%13] %= MOD;
                }
            }
        } else {
            int ch = s[i-1] - '0';
            for(int k = 0; k <= 12; ++k){
                dp[i][(ch+k*10)%13] += dp[i-1][k];
                dp[i][(ch+k*10)%13] %= MOD;
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}

Measured memory_bytes: 11392
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

struct Line {
  int k, b;
  double start;

  int at(int x) {
    return k * x + b;
  }

};

int main() {
  cout.setf(ios::fixed);
  cout.precision(9);
  int n;
  cin >> n;
  vector<int> t(n + 1);
  vector<int> v(n + 1);
  vector<int> starts(n + 1);
  copy_n(istream_iterator<int>(cin), n, t.begin());
  copy_n(istream_iterator<int>(cin), n, v.begin());
  t[n] = 1;
  v[n] = 0;
  vector<Line> lines;
  lines.push_back(Line{1, 0, 0});
  if(t[0] > v[0]){
    lines.push_back(Line{0, v[0], double(v[0])});
  }
  for(int i = 1; i <= n; ++i){
    starts[i] = starts[i - 1] + t[i - 1];
    while(lines.back().at(starts[i]) > v[i]){
      if(lines.back().k == -1){
        lines.pop_back();
      }else if(lines.back().k == 0){
        int pos = starts[i] + v[i] - lines.back().b;
        if(pos <= lines.back().start){
          lines.pop_back();
        }else{
          lines.push_back(Line{-1, starts[i] + v[i], double(pos)});
        }
      }else{
        double pos = (starts[i] + v[i] - lines.back().b) / 2.;
        if(pos <= lines.back().start){
          lines.pop_back();
        }else{
          lines.push_back(Line{-1, starts[i] + v[i], double(pos)});
        }
      }
    }
    if(lines.back().k == 0){
      lines.push_back(Line{1, v[i - 1] - starts[i], double(starts[i])});
    }
    if(lines.back().k == -1){
      lines.push_back(Line{0, v[i], double(starts[i])});
    }else if(lines.back().k == 1){
      if(lines.back().at(starts[i] + t[i]) > v[i]){
        lines.push_back(Line{0, v[i], double(starts[i] + v[i] - lines.back().at(starts[i]))});
      }
    }
  }
  double result = 0;
  for(size_t i = 0; i + 1 < lines.size(); ++i){
    double l = lines[i].start;
    double r = lines[i + 1].start;
    result += lines[i].k * (r * r - l * l) * 0.5 + lines[i].b * (r - l);
  }
  cout << result << endl;
}


Measured memory_bytes: 384
def ABC162C(a,b):#from:https://atcoder.jp/contests/abc162/submissions/11871774
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return max(a,b)
    

a,b,c,d=map(int,input().split())
e=c//ABC162C(c,d)*d
print(b-b//c-b//d+b//e-(a-1-(a-1)//c-(a-1)//d+(a-1)//e))

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

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

using ll = std::int64_t;

template <typename T>
T mod_expt(T a, std::int64_t n, T mod){
    T power {1};
    while(n > 0){
        if(n & 1){power = power * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return power;
}

ll N, P;
std::string S;
ll cnt[10100];

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

  std::cin >> N >> P >> S;

  ll ans = 0;

  if(P == 2){
      for(int i=0;i<N;++i){
          if((S[i] - '0') % 2 == 0){
              ans += i + 1;
          }
      }
  }else if(P == 5){
      for(int i=0;i<N;++i){
          if((S[i] - '0') % 5 == 0){
              ans += i + 1;
          }
      }      
  }else{
      ll cur = 0;

      cnt[0] += 1;

      for(int i=N-1;i>=0;--i){
          cur = (mod_expt<ll>(10, (N - 1) - i, P) * (S[i] - '0') + cur) % P;
          ans += cnt[cur];
          cnt[cur] += 1;
      }
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	long long n,b,buffer=0,ans=0;
	cin >> n;
	vector<long long> a(n + 1);
	for (int i = 0; i < n + 1; i++) cin >> a.at(i);
	for (int i = 0; i < n; i++)
	{
		cin >> b;

		if (buffer > 0)
		{
			if (buffer > a.at(i))
			{
				buffer = a.at(i);
				ans += a.at(i);
				a.at(i) = 0;
			}
			else
			{
				a.at(i) -= buffer;
				ans += buffer;
			}
		}
		if (a.at(i) >= b)
		{
			buffer = 0;
			ans += b;
		}
		else
		{
			buffer = b - a.at(i);
			ans += a.at(i);
		}
	}
	if (a.at(n) > buffer) ans += buffer;
	else ans += a.at(n);
	cout << ans;
}

Measured memory_bytes: 1152
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Measured memory_bytes: 58196
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    X,N = map(int,input().split())

    if N == 0:
        print(X)
        exit()

    p = set(map(int,input().split()))


    minim = INF
    ans = 0
    for i in range(10**4+1):
        if i in p: continue

        if minim > abs(i-X):
            ans = i
            minim = abs(i-X)


    print(ans)






if __name__ == "__main__":
  main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,m,a;
    cin>>n>>m;
    int flag=0;
    for (long long int i=0;i<m;i++) {
        cin>>a;
        n-=a;
        if (n<0) {
            cout<<-1<<endl;
            flag=1;
            break;
        }
    }
    if (flag==0) {
        cout<<n<<endl;
    }
}


Measured memory_bytes: 3636
import scala.io.Source.stdin

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for{
      i <- 3 to Math.sqrt(n).toInt by 2
      if primes(i) == 1
    }
      (i*i to n by i*2).foreach { primes(_) = 0 }

    for(i<-1 to n)
      primes(i) = primes(i)+primes(i-1)

    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(1000000)
    for(i <- stdin.getLines) {
      println(p(i.toInt))
    }
  }
}

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

int main(){
  int k,a,b;cin >> k >> a >> b;
  string ans;
  if(b-a>=k)ans="OK";
  else{
    ans="NG";
    for(int i=a;i<=b;i++)if(i%k==0)ans="OK";
  }
  cout << ans << endl;
}

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

string s;
int k, c['z'-'a'+1];
vector<string> strs;

int main() {
	cin >> s >> k;
	for (int i = 0; i < s.length(); i++) {
		c[s[i] - 'a']++;
	}

	for (int i = 0; i < 'z' - 'a' + 1; i++) {
		//cout << "i:" << i << endl;
		if (c[i] > 0) {
			//cout << "a" << endl;
			for (int j = 0; j < s.length(); j++) {
				//cout << "b" << endl;
				if (s[j] == (char)(i + 'a')) {
					for (int l = 1; l <= k; l++) {
						if ((j + l) <= s.length()) {
							strs.push_back(s.substr(j, l));
						}
					}
				}

			}

			//cout << "c" << endl;
			sort(strs.begin(), strs.end());
			//cout << "d" << endl;
			strs.erase(unique(strs.begin(), strs.end()), strs.end());
		}

		if (strs.size() >= k) {
			break;
		}
	}

	/*for (int i = 0; i < strs.size(); i++) {
		cout << strs[i] << endl;
	}
	cout << "e" << endl;*/
	cout << strs[k - 1] << endl;
}

Measured memory_bytes: 1660
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int ans = 0;
		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < N; i++) {
			int a = in.nextInt();
			if(set.contains(a)){
				set.remove(a);
				ans --;
			}else{
				set.add(a);
				ans ++;
			}
		}
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 63268
#include <bits/stdc++.h>
#define rep(i, N) for(int i = 1; i <= N; i++)

using namespace std;

int N;
int x[10], y[10];

double dist(int i, int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return sqrt(dx*dx + dy*dy);
}


int main(){
    cin >> N;
    rep(i, N) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    
    do{
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    }while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ll a,b,x,cnt = 0;
    cin >> a >> b >> x;;

    if(a % x == 0)
        cnt++;

    cout << (b/x) - (a/x) + cnt;

    return 0;
}


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

const int N=1e3+20;

int n,k,d,x,ans,f[N];

int main()
{
	cin>>n>>k;
	while(k--)
	{
		cin>>d;
		while(d--) cin>>x,f[x]++;
	}

	for(int i=1;i<=n;i++)
		if(f[i]==0) ans++;
	cout<<ans;
}

Measured memory_bytes: 3628
// Enjoy your stay.

#include <bits/stdc++.h>

#define ECH(it, A) for (__typeof((A).begin()) it=(A).begin(); it != (A).end(); ++it)
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int N,a[22],L[22],H[22];



template<class T> inline T ceil(T x, T y){return (x - 1) / y + 1;}


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

    cin>>N;
    rep(i,N)cin>>a[i];
    double lo = 0, hi = 1;
    rep(_,40){
        double mi = (lo+hi)/2;
        rep(i,N){
            L[i] = ceil(a[i] * (1 - mi));
            H[i] = floor(a[i] * (1 + mi));
        }
        set<int> cur,nx;
        rep2(i,L[0],H[0]+1){
            cur.insert(i);
        }
        rep2(i,1,N){
            if(sz(cur) == 0)break;
            nx.clear();

            ECH(it, cur){
                int t = *it;
                for(int k = ceil(L[i], t) * t;
                    k <= H[i] / t * t; k += t){
                    //if(!memo[k]){
                        nx.insert(k);
                        //memo[k] = 1;
                    //}
                }
            }
            cur = nx;
        }
        if(sz(cur)) hi = mi;
        else lo = mi;
    }
    cout<<fixed<<setprecision(16)<<hi<<endl;
}

Measured memory_bytes: 8896
#include <cstdio>
#include <algorithm>

using namespace std;

int x[100000];

int main() {
    int n, k, ans = 1e9, i;
    
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < n; i++) scanf("%d", &x[i]);
    
    for (i = 0; i + k <= n; i++) {
        int x1 = x[i], x2 = x[i + k - 1];
        
        if (x2 <= 0) {
            ans = min(ans, abs(x1));
        } else if (x1 >= 0) {
            ans = min(ans, abs(x2));
        } else {
            ans = min(ans, min(abs(x1), abs(x2)) + abs(x1) + abs(x2));
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 512
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;
int x[1001];
void primefactor(int n){

  bool flag=true;
  for( int i=2LL ;i*i<=n;i++){
    while(n%i==0){
      x[i]++;
      n/=i;
      flag=false;
    }
  }
  if(n!=1)x[n]++;
}


int main(){
  int a[maxn];
  int n;
  cin>>n;
  fill(a,a+maxn,0);
  for(int i=0;i<n;i++){
    int tmp;
    cin>>a[i];
    
  }
  sort(a,a+n);
  bool flag=true;
  int rest;
  if(n%2==0)rest=1;
  else rest=0;
  int rest2;
  if(n%2==0)rest2=0;
  else rest2=1;
  if(n%2==1 and a[0]!=0)flag=false;
  for(int i=0;i<n/2;i++){
    if( a[2*i+1-rest]!=(i+rest2)*2+rest or a[2*i+2-rest]!=(i+rest2)*2+rest)flag=false;
  }
  ll res=1LL;
  for(int i=0;i<n/2;i++){
    res=(res*2)%1000000007;
  }
  if(flag){
    cout<<res<<endl;
  
  }
  else cout<<0<<endl;



  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3];
	for(int i=0;i<3;i++){
		cin>>a[i];
	} 
	sort(a,a+3);
	int f=1;
	for(int i=1;i<3;i++){
		if(a[i]==a[i-1]) f++;
	}
	if(f==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


signed main(){ 
    int n; cin>>n;
    string ans="";

    while(n>0){
        n--;
        int r=n%26;
        ans+='a'+r;
        n /= 26;
    }
    reverse(all(ans));
    cout<<ans<<endl;
    
}  

Measured memory_bytes: 3620
# https://atcoder.jp/contests/abc045/tasks/abc045_b

a = gets.upcase
b = gets.upcase
c = gets.upcase
hash = { A: a, B: b, C: c }

next_user = hash[:A].slice!(..0)
winner = "A"

while next_user != nil
  next_user = hash[next_user.intern]&.slice!(..0)
  if next_user == 'A' || next_user == 'B' || next_user == 'C'
    winner = next_user
  end
end

puts winner


Measured memory_bytes: 14288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

ll ans = 0;

int main() {
  string s;
  cin >> s;
  vector<ll> v(s.size());
  for (int i = 0; i < s.size(); ++i) {
    v[i] = s[i] - '0';
  }

  ll len = s.size();
  ll ans = 0;
  for (int i = 0; i < (1 << len - 1); ++i) {
    ll num = v[0];
    for (int j = 0; j < len-1; ++j) {
      if ((i >> j) & 1) {
        ans += num;
        num = 0;
      }
      num = num * 10 + v[j + 1];
    }
    ans += num;
  }
  cout << ans << endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll const MOD = 1e9+7;

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

  int n;
  cin >> n;

  map<pair<ll, ll>, pair<int, int>> mp;

  int cnt_0 = 0;
  rep(i, n){
    ll a, b;
    cin >> a >> b;
    if(a == 0 && b == 0){
      cnt_0++;
    }else if(b == 0){
      mp[make_pair(1, 0)].first++;
    }else if(a == 0){
      mp[make_pair(1, 0)].second++;
    }else{

      ll gcd_ab = gcd(abs(a), abs(b));
      
      if((a > 0 && b > 0) || (a < 0 && b < 0)){
        mp[make_pair(abs(a)/gcd_ab, abs(b)/gcd_ab)].first++;
      }else{
        mp[make_pair(abs(b)/gcd_ab, abs(a)/gcd_ab)].second++;
      }
    }
  }

  ll ans = 1;

  for(auto p : mp){

    ll tans = 0;
    tans += ans;
    tans = (tans + (ans * (modpow(2, p.second.first, MOD) + MOD - 1) % MOD) % MOD) % MOD;
    tans = (tans + (ans * (modpow(2, p.second.second, MOD) + MOD - 1) % MOD) % MOD) % MOD;

    tans = tans % MOD;

    ans = tans;

  }

  ans = (ans + cnt_0 + MOD - 1) % MOD;

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


Measured memory_bytes: 16060
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//$fp = fopen("input.txt", "r");
$fp = fopen("php://stdin", "r");
$n = (int)fgets($fp);

for($i = 0; $i < $n; $i++) {
    $buf = rtrim(fgets($fp));
    for($j = 0; $j < strlen($buf)-6; $j++) {
        if(isHoshino($buf, $j) ) $buf[$j+6] = 'a';
    }
    echo $buf;
    if($i < $n - 1) echo "\n";
}

function isHoshino($str, $pos) {
    if($str[$pos] != 'H') {
        return false;
    }
    if($str[$pos+1] != 'o') {
        return false;
    }
    if($str[$pos+2] != 's') {
        return false;
    }
    if($str[$pos+3] != 'h') {
        return false;
    }
    if($str[$pos+4] != 'i') {
        return false;
    }
    if($str[$pos+5] != 'n') {
        return false;
    }
    if($str[$pos+6] != 'o') {
        return false;
    }
    return true;
}
?>

Measured memory_bytes: 6616
from collections import deque

H, W = map(int, input().split())
CH, CW = map(lambda x:int(x)-1, input().split())
DH, DW = map(lambda x:int(x)-1, input().split())

mp = [input() for _ in range(H)]
ds1 = [[0,-1],[0,1],[-1,0],[1,0]]
ds2 = [[i,j] for i in range(-2,3) for j in range(-2,3)]

memo = [[0]*W for _ in range(H)]
memo[CH][CW] = 1

h1 = deque([(CH,CW)])
h2 = deque([])
ans = 0

while 1:
  while h1:
    t = h1.popleft()
    h2.append(t)
    for d in ds1:
      if t[0]+d[0] >= 0 and t[0]+d[0] < H \
         and t[1]+d[1] >= 0 and t[1]+d[1] < W:
        if mp[t[0]+d[0]][t[1]+d[1]] == '.' and memo[t[0]+d[0]][t[1]+d[1]] == 0:
          memo[t[0]+d[0]][t[1]+d[1]] = 1
          h1.append((t[0]+d[0], t[1]+d[1]))
  if memo[DH][DW] == 1:
    print(ans)
    exit()
  ans += 1

  while h2:
    t = h2.popleft()
    for d in ds2:
      if t[0]+d[0] >= 0 and t[0]+d[0] < H \
         and t[1]+d[1] >= 0 and t[1]+d[1] < W:
        if mp[t[0]+d[0]][t[1]+d[1]] == '.' and memo[t[0]+d[0]][t[1]+d[1]] == 0:
          memo[t[0]+d[0]][t[1]+d[1]] = 1
          h1.append((t[0]+d[0], t[1]+d[1]))
          
  if not h1:
    print(-1)
    exit()

Measured memory_bytes: 85872
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main() {
	map<string, int>mp;
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	int max = -1;
	for (int i = 0; i < n; ++i) {
		mp[s[i]]++;
		if (max < mp[s[i]])max=mp[s[i]];
	}
	for (int i = 0; i < n; ++i) {
		if (mp[s[i]] == max) {
			cout << s[i] << endl;
			i += max - 1;
		}
	}
	return 0;
}

Measured memory_bytes: 26752
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

void solve (void)
{
  int N;int K;
  cin>>N>>K;
    if(K > (N-1)*(N-2)/2)
  {
    cout<<-1<<endl;
    return;
  }
  cout<< N - 1 + (N-2)*(N-1)/2 - K <<endl;

  for (int i = 0; i < N-1; i++)
  {
    cout<<1<<" "<<2+i<<endl;
  }
  int cnt = (N-2)*(N-1)/2 - K;
  for (int i = 2; i < N; i++)
  {
    for (int j = i+1; j <= N; j++)
    {
      if(cnt <= 0)continue;
      cout<<i<<" "<<j<<endl;
      cnt--;
    }
    
  }
  
  
  
  
  return;
}

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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
/*
author: Apoorv Singh
*/

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

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230;
int modulo = 1e9 + 7;

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a; cin >> a;
    cout << 3*a*a;
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split(' ').Select(_ => int.Parse(_));
            var m = array.First();
            var d = array.Last();

            var count = 0;
            for (int month = 1; month <= m; month++)
            {
                for (int day = 10; day <= d; day++)
                {
                    var d10 = (day / 10) % 10;
                    var d1 = day % 10;

                    if (d10 == 1)
                        continue;
                    if (d1 == 1)
                        continue;

                    if (month == d10 * d1)
                        count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11348
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
typedef long long ll;

using namespace std;
#define N 100010
vector<ll> g[N];
ll nz[N],p[N];
int main(){
    ll n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)nz[i]=0;
    for(int i=0;i<n+m-1;i++){
      ll a,b;cin>>a>>b;
      g[a].push_back(b);
      nz[b]++;
    }
    queue<ll> Q;
    for(int i=1;i<=n;i++)if(nz[i]==0){
      Q.push(i); p[i]=0;
    }
    while(!Q.empty()){
      ll x=Q.front(); Q.pop();
      for(auto y:g[x]){
	nz[y]--;
	if(nz[y]==0){
	  Q.push(y);
	  p[y]=x;
	}
      }
    }
    for(int i=1;i<=n;i++)cout<<p[i]<<endl;
    return 0;
}


Measured memory_bytes: 7808
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
  S, C = map(int, input().split())
  s.append(S)
  c.append(C)
for i in range(10 **(n + 1)):
  tmp = str(i)
  if len(tmp) == n and all([tmp[s[j] - 1] == str(c[j]) for j in range(m)]):
    print(tmp)
    exit()
print(-1)

Measured memory_bytes: 9148
N = int(input())
H = list(map(int,input().split()))

z = False
for a,b in zip(H,H[1:]):
    if a<b:
        z = False
    if a<=b:
        continue
    if a-b > 1:
        print('No')
        exit()
    assert a-b == 1
    if z:
        print('No')
        exit()
    z = True

print('Yes')

Measured memory_bytes: 14396
#include <iostream>
#include <utility>

int count = 0;
void bubbleSort(int num[], int N)
{
  for(int i=0; i<N-1; ++i){
    for(int j=N-1; j>i; --j){
      if(num[j] < num[j-1]){
        std::swap(num[j], num[j-1]);
        count++;
      }
    }
  }
}

int main(){
  int n;
  std::cin >> n;

  int num[n];
  for(int i=0; i<n; ++i){
    std::cin >> num[i];
  }
  bubbleSort(num, n);
  for(int i=0; i<n; ++i){
    if(i != 0) std::cout << " ";
    std::cout << num[i];
  }
  std::cout << std::endl;
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 3080
n=input()
a=sorted(map(int,raw_input().split()))
m=input()
b=sorted(map(int,raw_input().split()))
if n<m:print "NO"
else:
    i=0
    j=0
    while i<m:
        if b[i]==a[j]:
            i+=1
            j+=1
        elif b[i]<a[j]:
            break
        else:
            j+=1
            if j>=n: break
    print "YES" if i==m else "NO"


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

// |o|o||||  |...最多種 o...その他（|の間にoを入れ込むイメージ）

int main(){
  int K,T; cin >> K >> T;
  int a[T]; REP(i,T){cin >> a[i];}
  sort(a,a+T,greater<int>());
  int most = a[0];
  int rest = K-most;
  if(rest>=most-1){
    cout << "0\n";
  }else{
    cout << most-rest-1 << "\n";
  }
  
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll my_floor(ll a){
    if(a%10==0){
        return a;
    }else{
        ll diff = a % 10;
        a -= diff;
        a += 10;
        return a;
    }
}

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

    vector<ll> A(5);
    FOR(i, 0, 5){
        cin >> A.at(i);
    }

    ll minus = 0;
    FOR(i, 0, 5){
        ll a = A[i] % 10;
        if(a!=0){
            ll diff = 10 - a;
            minus = max(minus, diff);
        }
    }

    ll sum = 0;
    FOR(i, 0, 5){
        sum += my_floor(A[i]);
    }
    sum -= minus;

    p(sum);
    
    return 0;
}

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

int number_count[100005];

int main() {
    int N, number, count = 0;
    cin >> N;
    for (int i = 0; i < 100005; i++) number_count[i] = 0;
    for (int i = 0; i < N; i++) {
        cin >> number;
        number_count[number]++;
    }
    int min_p = 0, max_p = 100005;
    while (min_p != max_p) {
        if (number_count[min_p] == 0 || number_count[min_p] == 1) min_p++;
        if (min_p == max_p) break;
        if (number_count[max_p] == 0 || number_count[max_p] == 1) max_p--;
        if (number_count[min_p] != 0 && number_count[min_p] != 1 && number_count[max_p] != 0 && number_count[max_p] != 1) {
            int del_num = min(number_count[min_p], number_count[max_p]) - 1;
            number_count[min_p] -= del_num;
            number_count[max_p] -= del_num;
        }
    }
    if (number_count[min_p] != 1 && number_count[min_p] != 0) {
        if (number_count[min_p] % 2 == 0) number_count[min_p] = 0;
        else number_count[min_p] = 1; 
    }
    for (int i = 0; i < 100005; i++) {
        if (number_count[i] != 0) count++;
    }
    cout << count << endl;
    return 0;
}

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')


n, q = map(int, input().split())
queries = []
for _ in range(q):
    com, x, y = map(int, input().split())
    queries.append([com, x, y])

parents = [i for i in range(n)]
size = [1 for _ in range(n)]


def find(x):
    if x != parents[x]:
        parents[x] = find(parents[x])
    return parents[x]


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


def unite(x, y):
    x_root = find(x)
    y_root = find(y)
    if x_root == y_root:
        return
    if x_root < y_root:
        x_root, y_root = y_root, x_root
    parents[y_root] = x_root
    size[x_root] += size[y_root]


for com, x, y in queries:
    if com == 0:
        unite(x, y)
    else:
        if same(x, y):
            print(1)
        else:
            print(0)



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


int n;
char buf[60];
char buf2[60];
#define MOD 1000000007
int main(){
	cin >> n;
	scanf("%s", buf);
	scanf("%s", buf2);
	int pr = 0;
	long long int way = 1;
	for (int i = 0; i < n; i++){
		if (buf[i] == buf2[i]){
			way *= 3 - pr;
			pr = 1;
			if (way >= MOD){
				way %= MOD;
			}
		}
		else{
			if (pr == 0){
				way *= 6;
			}
			else{
				if (pr == 1){
					way *= 2;
				}
				else{
					way *= 3;
				}
			}
			pr = 2;
			i += 1;
			if (way >= MOD){
				way %= MOD;
			}
		}
	}
	printf("%lld\n", way);
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
n = int(input())
ki = [[]for j in range(n)]
for i in range(n-1):
	    a,b=map(int,input().split())
	    a-=1
	    b-=1
	    ki[a].append([b,i])
	    ki[b].append([a,i])


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,-1)
print(*clist)


		


Measured memory_bytes: 95728
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define MODk 998244353
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ll modularExponentiation(ll x,ll n,ll M);
void dsp(vector<ll> &V);
void dsp2(vector<pair<ll,ll>>&V);
void dsp3(map<ll,ll>&M);
double fact(double n);
ll nPr(ll n,ll r);
ll nCr(ll n,ll r);
ll mx;
bool isPalindrome(string k) 
{ 
    // Start from leftmost and rightmost corners of str 
    ll l = 0; 
    ll h = sz(k) - 1; 
  
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (k[l++] != k[h--]) 
        { 
            return false; 
        } 
    } 
    return true; 
} 
void solve()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
ll gcd(ll a,ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
          
} 
ll lcm(ll a,ll b)  
{  
    return (a*b)/gcd(a, b);  
}  
ll modularExponentiation(ll x,ll n,ll M)
{   
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
void dsp(vector<ll> &V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j]<<" ";
    }
    cout<<endl;
}
void dsp2(vector<pair<ll,ll>>&V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j].first<<" "<<V[j].second<<" ";
    }
    cout<<endl;
}
void dsp3(map<ll,ll>&M)
{
      map<ll,ll>::iterator it=M.begin();
      while(it!=M.end())
      {
        cout<<it->first<<" "<<it->second<<endl;
        it++;
      }
}
double fact(double n)
{
    double i=1;
    double res=1;
    
    if(n==0)
        return 1.00;
    
    while(i<=n)
    {
        res*=i;
        i++;
    }
    
    return res;
}
ll nPr(ll n,ll r)
{
    return (fact(n)/fact(n-r));
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>

Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll=long long;
#define MOD  1000000007

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  std::cout << n*(n+1)/2 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

const int N=100,inf=0x5FFFFFFF;
struct node
{
	int x,y;
}R[N+5],B[N+5];
int n,ans;
bool vis[N+5];
int Ma[N+5][N+5],fa[N+5];

int Dfs(int u)
{
	for(int v=1;v<=n;v++)
		if(Ma[u][v]&&!vis[v])
		{
			vis[v]=1;
			if(fa[v]==-1||Dfs(fa[v]))
			{
				fa[v]=u;
				return true;
			}
		}
	return false;
}

void Solve()
{
	memset(fa,-1,sizeof(fa));
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		ans+=Dfs(i);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&R[i].x,&R[i].y);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&B[i].x,&B[i].y);
		for(int j=1;j<=n;j++)
			if(R[j].x<B[i].x&&R[j].y<B[i].y)
				Ma[j][i]=1;
	}
	Solve();
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
	int n,m;
	int ans;
	scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
    	scanf("%d",&m);
    	if (m%2==0)
    	{
    		ans++;
		}	
	}
	printf("%d",int(pow(3,n)-pow(2,ans)));
 	return 0;
} 


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




int main(){

  ll mod=1e9+7;
  ll n,a=1,b=1,c=1;
  cin>>n;
  rep(i,n){
      a*=10;
      b*=9;
      c*=8;
      a%=mod;
      b%=mod;
      c%=mod;
  }
  ll ans=(a-2*b+c)%mod;
  while(ans<0){
    ans+=mod;
  }
  
  cout<<ans;
}

Measured memory_bytes: 3616
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static final int DIJ[] = {0, 1, 0, -1, 0};

	static void solve() throws Exception {
		int h = scanInt(), w = scanInt();
		boolean grid[][] = new boolean[h][w];
		int curSet[] = new int[2 * h * w], newSet[] = new int[2 * h * w], curSize = 0;
		for (int i = 0; i < h; i++) {
			String l = scanString();
			for (int j = 0; j < w; j++) {
				grid[i][j] = l.charAt(j) == '#';
				if (grid[i][j]) {
					curSet[curSize++] = i;
					curSet[curSize++] = j;
				}
			}
		}
		int ans = 0;
		do {
			int newSize = 0;
			for (int i = 0; i < curSize; i += 2) {
				int y = curSet[i], x = curSet[i + 1];
				for (int d = 0; d < 4; d++) {
					int ny = y + DIJ[d], nx = x + DIJ[d + 1];
					if (ny >= 0 && ny < h && nx >= 0 && nx < w && !grid[ny][nx]) {
						grid[ny][nx] = true;
						newSet[newSize++] = ny;
						newSet[newSize++] = nx;
					}
				}
			}
			curSize = newSize;
			int t[] = curSet;
			curSet = newSet;
			newSet = t;
			++ans;
		} while (curSize > 0);
		out.print(ans - 1);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 44856
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
int a[200]={0};
int main()
{
	string str;
	cin>>str;
	for(int i=0;i<str.size();i++)
	{
		a[str[i]]++;
	}
	for(int i=97;i<=122;i++)
	{
		if(a[i]%2)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void){ 
	char str[256],data[256],str_copy[256];
	scanf("%s",str);
	scanf("%s",data);
	
	strcpy(str_copy,str);
	//scanf("%s",data);
	strcat(str,str_copy);
	int i,len;
	len = strlen(data);
	if(strstr(str,data)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	//puts(str);
	
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> p(N), v(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        if (p[i] == i + 1) v[i] = 1;
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (v[i] == 0) continue;
        int cnt = 0, j = i;
        while (v[j] == 1) {
            cnt++;
            j++;
        }
        ans += (cnt + 1) / 2;
        i = j;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

a,b,c=MI()
for i in range(b):
    if (a*i)%b==c:
        print("YES")
        sys.exit()
print("NO")

Measured memory_bytes: 3444
#include <stdio.h>
#include <string.h>

#define LEN 100005

typedef struct
{
    char name[100];
    int time;
} DATA;

void enqueue(DATA);
DATA dequeue();

int head = 0, tail = 0;
DATA data[LEN + 1];

int main()
{

    int elaps = 0, t, i, n, q, flag = 0;
    DATA tmp;
    scanf("%d%d", &n, &q);

    for (i = 0; i < n; i++)
    {
        scanf("%s %d", tmp.name, &tmp.time);
        enqueue(tmp);
    }

    while (1)
    {
        // printf("経過時間:%d\n",elaps);

        tmp = dequeue();
        if (q < tmp.time)
            t = q;
        else
            t = tmp.time;
        tmp.time -= t;
        elaps += t;

        if (tmp.time > 0)
            enqueue(tmp);
        else
            printf("%s %d\n", tmp.name, elaps);

        if (head == tail)
            break;
    }

    return 0;
}

void enqueue(DATA x)
{
    if (tail == LEN)
        tail = 0;
    strcpy(data[tail].name, x.name);
    data[tail].time = x.time;
    tail++;
}

DATA dequeue()
{
    if (head == LEN)
        head = 0;
    head++;
    return data[head - 1];
}



Measured memory_bytes: 11956