akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


	void solve() {
		IOS;
		int n, x;
		for (; ; ) {
			cin >> n >> x;
			if (n == 0 && x == 0) {
				break;
			}
			int res = 0;
			FOR(i,1,n+1) {
				FOR(j, i + 1, n + 1) {
					FOR(k, j + 1, n + 1) {
						if (i + j + k == x) {
							res++;
						}
					}
				}
			}
			put(res);
		}
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}



Measured memory_bytes: 3200
import sys
input = sys.stdin.buffer.readline
N = int(input())
a = list(map(int, input().split()))
num = [[] for _ in range(N + 1)]
dnum = 0
mod = 10 ** 9 + 7
for i in range(N + 1):
  num[a[i]].append(i)
  if len(num[a[i]]) == 2:
    dnum = a[i]
class Factorial:
  def __init__(self, n, mod):
    self.f=[1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i=[pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N + 1, mod)
for i in range(1, N + 2):
  t = f.combi(N + 1, i)
  u = 0
  if num[dnum][0] + (N + 1 - num[dnum][1]) >= i:
    u = f.combi(num[dnum][0] + (N + 1 - num[dnum][1]), i)
    if num[dnum][0] + (N + 1 - num[dnum][1] - 1) >= i:
      u -= f.combi(num[dnum][0] + (N + 1 - num[dnum][1] - 1), i)
  print((t - u) % mod)

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) {
    if (s[i] == 'R') a[i] = 0;
    if (s[i] == 'G') a[i] = 1;
    if (s[i] == 'B') a[i] = 2;
  }
  vector<ll> cnt(3);
  rep(i,n) cnt[a[i]]++;
  ll ans = 1;
  rep(i,3) ans *= cnt[i];
  rep(j,n)rep(i,j) {
    int k = j + (j-i);
    if (k < n) {
      if (a[i] == a[j]) continue;
      if (a[i] == a[k]) continue;
      if (a[k] == a[j]) continue;
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      if (0 <= S - x - y && S - x - y <= K)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce


def prime_factorize(n):
    """素因数分解する。"""
    def facs(n):
        """試し割り法における割る数を生成する。"""
        yield 2
        max_prime = int(pow(n, 0.5)) + 2
        for x in range(3, max_prime, 2):
            yield x

    ans = set()
    for fac in facs(n):
        if n % fac == 0:
            ans.add(fac)
            while n % fac == 0:
                n //= fac
    if n != 1:
        ans.add(n)
    return ans


def gcd_list(numbers):
    # これじゃすべての最大公約数を出しているだけ。
    # すべての組み合わせにおいて最大公約数が1でなくてはいけない。
    return reduce(math.gcd, numbers)


def main():
    a, b = [int(x) for x in input().split()]
    gcd_ = math.gcd(a, b)
    primes = prime_factorize(gcd_)
    print(len(primes) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9620
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x,y,z,K;
  vector<long long>vec;
  cin>>x>>y>>z>>K;
  long long a[x],b[y],c[z];
  for(int i=0;i<x;i++) cin>>a[i];sort(a,a+x,greater<long long>());
  for(int i=0;i<y;i++) cin>>b[i];sort(b,b+y,greater<long long>());
  for(int i=0;i<z;i++) cin>>c[i];sort(c,c+z,greater<long long>());
    
  for(int i=0;i<x;i++){
  for(int j=0;j<y;j++){
  for(int k=0;k<z;k++){
    if((i+1)*(j+1)*(k+1)<=K)vec.push_back(a[i]+b[j]+c[k]);
  }}}
  sort(vec.begin(),vec.end(),greater<long long>());
  for(int i=0;i<K;i++) cout<<vec[i]<<endl;
}

Measured memory_bytes: 1400
#include <cstdio>

int main(){
	int n, p;
	int x[50];
	while(scanf("%d%d", &n, &p)){
		if(n == 0 && p == 0) break;
		for(int i = 0; i < n; i++) x[i] = 0;
		int t = 0;
		int q = p;
		while(true){
			if(p > 0){
				x[t]++;
				if(x[t] == q){
					printf("%d\n", t);
					break;
				}
				p--;
			} else{
				p += x[t];
				x[t] = 0;
			}
			t++;
			t %= n;
		}
	}
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int W, H, T, P;
int A[2][101][101];
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> W >> H >> T >> P) {
        if (W == 0) return;
        
        rep(t, 0, 2) rep(y, 0, 101) rep(x, 0, 101) A[t][y][x] = 0;
        rep(y, 0, H) rep(x, 0, W) A[0][y][x] = 1;

        rep(t, 0, T) {
            int d, c; cin >> d >> c;
            rep(y, 0, 101) rep(x, 0, 101) A[(t + 1) % 2][y][x] = 0;

            if (d == 1) {
                rep(y, 0, H) rep(x, 0, W) A[(t + 1) % 2][y][x] = A[t % 2][y][x + c];
                rep(x, 0, c) rep(y, 0, H) A[(t + 1) % 2][y][x] += A[t % 2][y][c - 1 - x];
            } else {
                rep(y, 0, H) rep(x, 0, W) A[(t + 1) % 2][y][x] = A[t % 2][y + c][x];
                rep(x, 0, W) rep(y, 0, c) A[(t + 1) % 2][y][x] += A[t % 2][c - 1 - y][x];
            }
        }

        rep(p, 0, P) {
            int x, y; cin >> x >> y;
            printf("%d\n", A[T % 2][y][x]);
        }
    }
}




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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a < b) {
    if(b < c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3096
import heapq
H, N = map(int, input().split())
A = [] #W
B = [] #V
for i in range(N):
    ai, bi = map(int, input().split())
    A += [ai]
    B += [bi]
maxA = max(A)
dp = [[0 for j in range(H+maxA+1)]for i in range(N+1)]

for j in range(1, H+maxA+1):
    dp[0][j] = float('inf')

for i in range(N):
    for j in range(H+maxA+1):
        if j - A[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i])
ans = float('inf')
for j in range(H, H+maxA+1):
    ans = min(ans, dp[N][j])
print(ans)

Measured memory_bytes: 322824
public class Main {

	public static void main(String[] args) {
		
		for(int i = 1; i < 10; i++){
			for(int j = 1; j <
					10 ; j++){
				int sum = i*j;
				System.out.println(i+"x"+j+"="+sum);
			}
		}
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}
*/
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k); 

}
/*
Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z.left==NIL || z.right == NIL) y=z;
  else y=treeSuccessor(z);

  if(y.left==NIL) x=y.left;
  else x= y.right;

  if(x!=NIL) x.p=y.p;

  if(y.p==NIL) 

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key< y->key) y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if(u!=NIL) {
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }


}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);

      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } 
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 

    
    /*else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    */
  }

  return 0;
}

Measured memory_bytes: 19364
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')
fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}

typedef long long LL;

const int N = 200005;

int n, a[N];
LL b[N], ans;

int main(){
    read(n);
    for(int i = 1; i <= n; i++){
        read(a[i]);
        b[a[i]]++;
    }
    for(int i = 1; i <= n; i++) ans += b[i] * (b[i] - 1) / 2;
    for(int i = 1; i <= n; i++)
        printf("%lld\n", ans - b[a[i]] * (b[a[i]] - 1) / 2 + (b[a[i]] - 1) * (b[a[i]] - 2) / 2);
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
	lint N, K;
	cin >> N >> K;
	map<lint, lint> m;
	rep(i, N) {
		lint a, b;
		cin >> a >> b;
		m[a] += b;
	}
	
	lint i = 1;
	while (true) {
		K -= m[i];
		if (K <= 0) {
			cout << i << endl;
			break;
		}
		i++;
	}
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a;
  cin>>a;
  vector<int> b={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<b[a-1];
}


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

const int MAX_N = 2e5 + 5;
lint A[MAX_N], S[MAX_N];

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

    lint ans = 1e15;
    for(int i=2;i<N-1;i++){
        int j = distance(A, lower_bound(A, A+i+1, A[i]/2));
        int k = distance(A, lower_bound(A+i+1, A+N+1, A[i]+(A[N]-A[i])/2));

        lint a, b, c, d;
        if(abs(A[i]-2*A[j]) < abs(A[i]-2*A[j-1])) {a = A[j], b = A[i]-A[j];}
        else {a = A[j-1], b = A[i]-A[j-1];}
        if(abs(A[N]-2*A[k]+A[i]) < abs(A[N]-2*A[k-1]+A[i])) {c = A[k]-A[i], d = A[N]-A[k];}
        else {c = A[k-1]-A[i], d = A[N]-A[k-1];}
        ans = min(ans, max(max(a, b), max(c, d))-min(min(a, b), min(c, d)));
    }

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

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    vector<int> a(5);
    for (int &x : a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    set<int> b;
    for (int i = 0; i < 50000; i += 10) {
        b.insert(i);
    }
    int res = INT_MAX;
    do {
        int time = 0;
        for (int i = 0; i < 5; i++) {
            time = (*(b.lower_bound(time)));
            time += a[i];
        }
        res = min(res, time);
    } while(next_permutation(a.begin(), a.end()));
    cout << res << "\n";
}


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

using namespace std;

#define ppii pair<int,pair<int,int>>
#define mk_ppii(a,b,c) make_pair(a,make_pair(b,c))

int main(){
	int t,p,r;
	while(cin >> t >> p >> r,t||p||r){
		vector<pair<int,int>> WAs;
		vector<pair<int,pair<int,int>>> result(t,mk_ppii(p,0,0));
		for(int i=0;i<t;i++) result[i].second.second = i+1;
		for(int i=0;i<r;i++){
			int tid,pid,time;
			string message;
			cin >> tid >> pid >> time >> message;
			if(message == "WRONG"){
				WAs.emplace_back(make_pair(tid,pid));
			}
			if(message == "CORRECT"){
				int c = count(WAs.begin(),WAs.end(),make_pair(tid,pid));
				result[tid-1].first--;
				result[tid-1].second.first += c*1200+time;
			}
		}
		sort(result.begin(),result.end());
		for(int unsigned i = 0;i<result.size();i++){
			cout << result[i].second.second << " " << p-result[i].first << " " << result[i].second.first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
using namespace std;
 
int main(){
	int n,k,a[5000],ans = 0;
	vector<int> nums[2][5001];
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> a[i];
	nums[0][0].pb(0);
	for(int i = 0;i < n;i++){
		bool ok[5001] = {};
		for(int num : nums[0][i]){
			ok[num] = true;
			if(num + a[i] <= k) ok[num + a[i]] = true;
		}
		for(int j = 0;j <= k;j++) if(ok[j]) nums[0][i + 1].push_back(j);
	}
	nums[1][n].pb(0);
	for(int i = n - 1;i >= 0;i--){
		bool ok[5001] = {};
		for(int num : nums[1][i + 1]){
			ok[num] = true;
			if(num + a[i] <= k) ok[num + a[i]] = true;
		}
		for(int j = 0;j <= k;j++) if(ok[j]) nums[1][i].push_back(j);
	}
	for(int i = 0;i < n;i++){
		bool flag = true;
		for(int num : nums[0][i]){
			int ind = lower_bound(nums[1][i + 1].begin(),nums[1][i + 1].end(),k - a[i] - num) - nums[1][i + 1].begin();
			if(nums[1][i + 1].size() == ind || num + nums[1][i + 1][ind] >= k) continue;
			flag = false;
		}
		if(flag) ans++;
	}
	cout << ans << endl;
}

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

const int INF = 1001001001;
//4方向
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  int ans = 0;
  rep(i,h) cin >> s[i];
  rep(si,h) rep(sj,w) {
    if(s[si][sj] == '#') continue;
    /*距離各マス*/
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<P> q;
    auto update = [&](int i, int j, int x){
      if(dist[i][j] != INF) return;
      dist[i][j] = x;
      q.push(P(i,j));
    };
    update(si,sj,0);//初期化
    while(!q.empty()) {//queueからなくなるまで
      int i=q.front().first;
      int j=q.front().second;
      q.pop();
      rep(dir,4){
        int ni = i+di[dir], nj = j+dj[dir];
        if(ni <0||ni>=h||nj<0||nj>=w) continue;
        if(s[ni][nj] == '#') continue;
        update(ni,nj, dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w) {
      if(dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    } 
  }
  cout << ans << endl;

}

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

long long maxvalue(long long B,long long w[],long long v[],long long n)
{
    long long dp[n+1][B+1];

    for(long long i=0;i<B+1;i++){
        dp[n][i]=0;
    }
    for(long long i=0;i<n+1;i++){
        dp[i][0]=0;
    }

    for(long long i=n-1;i>=0;i--){
        for(long long j=1; j<=B; j++){
            long long a=0;
            if(w[i]<=j){
                a=v[i]+dp[i+1][j-w[i]];
            }
            long long b=dp[i+1][j];
            dp[i][j]=max(a,b);
        }
    }
    return dp[0][B];
}

int main()
{
    long long n,W;
    cin>>n>>W;
    long long w[n],v[n];
    for(long long i=0; i<n; i++)
    {
        cin>>w[i]>>v[i];
    }

    cout << maxvalue(W,w,v,n);
}



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

typedef long long ll;
typedef pair<int, int> ii;

int n, t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int cur = 1, cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    if (t == cur) {
      ++cur;
    } else {
      ++cnt;
    }
  }
  if (cur == 1)
    cout << -1 << endl;
  else
    cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <bits/stdc++.h>
using namespace std;
const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}
const int N=200010;
struct Edge{int to,capa,next;} e[N];
int h[N],sum=0,n,m;
bool vis[N];
int cmt,cnt,col[N],c[3];
bool falun;

inline int color(const int &x)
{
    if(x>=3) return x-3;
    if(x<0) return x+3;
    return x;
}

void add_edge(int u,int v,int w)
{
    e[++sum].to=v;
    e[sum].capa=w;
    e[sum].next=h[u];
    h[u]=sum;
}

void dfs(int u)
{
    c[col[u]]++;vis[u]=1;cnt++;
    for(int tmp=h[u];tmp;tmp=e[tmp].next)
    {
        cmt+=(e[tmp].capa==1);
        int v=e[tmp].to;
        if(!vis[v]) col[v]=color(col[u]+e[tmp].capa),dfs(v);
        else if(col[v]!=color(col[u]+e[tmp].capa)) falun=0;
    }
}

int main()
{
    int u,v;
    n=read();m=read();
    for(int i=1;i<=m;i++)
    {
        u=read();v=read();
        add_edge(u,v,1);
        add_edge(v,u,-1);
    }
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]) continue;
        memset(c,0,sizeof(c));
        cmt=cnt=0;falun=1;
        dfs(i);
        if(!falun) ans+=1ll*cnt*cnt;
        else if(c[0]&&c[1]&&c[2]) ans+=1ll*c[0]*c[1]+1ll*c[1]*c[2]+1ll*c[2]*c[0];
        else ans+=cmt;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7680
N = int(input())
ABs = []
for i in range(N):
  X, L = map(int, input().split())
  A, B = X-L, X+L
  ABs.append((A, B))
ABs.sort(key=lambda AB: AB[1])
#print(ABs)
r = 1
b = ABs[0][1]
for i in range(1, N):
  A, B = ABs[i]
  if A >= b:
    r += 1
    b = B
print(r)


Measured memory_bytes: 18260
#include<bits/stdc++.h>
using namespace std;
int k,s[200005]={0},t=0,n,a[200005],f=0;
int main()
{cin>>n>>k;
 for(int i=1;i<=n;i++) 
   {cin>>a[i];
    s[a[i]]++;}
 for(int i=1;i<=n;i++) if(s[i]!=0) f++;
 sort(s+1,s+n+1);
 f-=k;
 for(int i=1;f>0;i++)
 if(s[i]!=0) {t+=s[i];f--;}
 cout<<t;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(int i=0;i<n;i++)
int main(){
  int h,w,k;	cin >> h >> w >> k;
  vector<vector<char>>	c(h);
  rep(i,h)rep(j,w){
    char ch;	cin >> ch;
    c[i].push_back(ch);
  }
  
  auto	check=[&](int i,int j){
    int cnt=0;
    for(int x=0;x<h;x++){
      for(int y=0;y<w;y++){
        if(!((i>>x)&1&&(j>>y)&1))	continue;
        if(c[x][y]=='#')	cnt++;
      }
    }
    return cnt;
  };
  
  int ans=0;
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
      int cnt=check(i,j);
      if(cnt==k){
        ans++;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n;
int a[9],b[9],ans0,ans1;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	while(next_permutation(a,a+n))
	{
		ans0++;
	} 
	while(next_permutation(b,b+n))
	{
		ans1++;
	}
	cout<<abs(ans0-ans1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N;
  cin>>N;
  cout<<N*(N+1)/2<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,h,cnt=0;
    cin>>n>>k;
    for(int i=0; i<n; i++){
        cin>>h;
        if(h>=k)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

char s[10][10];

int n,m,cnt=0;

void dfs(int x,int y) {
    --cnt;
    if(x==n && y==m) return;
    if(x<n && s[x+1][y]=='#') {
        dfs(x+1,y);return;
    }
    if(y<m && s[x][y+1]=='#') {
        dfs(x,y+1);return;
    }
}

int main() {
    read(n);read(m);
    REP(i,1,n) {
        scanf("%s",s[i]+1);
        REP(j,1,m) if(s[i][j]=='#') ++cnt;
    }
    dfs(1,1);
    if(cnt) printf("Impossible\n");
    else printf("Possible\n");
    return 0;
}

Measured memory_bytes: 384
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

SIZE = 10 ** 5
P = [-1] * (SIZE + 1)
P[0], P[1] = 0, 0

for i in range(2, SIZE + 1):
  if P[i] == -1:
    P[i] = 1
    k = 2
    while i * k <= SIZE:
      P[i * k] = 0
      k += 1
      
PP = [0] * (SIZE + 1)
for i in range(3, SIZE + 1):
  if P[i] and P[(i + 1) // 2]:
    PP[i] = 1
#print(PP)

Acum = [0]
for i in range(SIZE + 1):
  Acum.append(Acum[-1] + PP[i])
#print(Acum)

for l, r in LR:
  print(Acum[r + 1] - Acum[l])
  

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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var a = long.Parse(inputs[0]);
            var b = long.Parse(inputs[1]);
            var c = long.Parse(inputs[2]);

            var list = new List<long>();
            var count = 1L;

            while (true)
            {
                var m = (a * count) % b;
                if (list.Contains(m))
                {
                    // Console.WriteLine(count);
                    Console.WriteLine("NO");
                    return;
                }

                if ((m == 0 && c == 0) || (m != 0 && c % m == 0))
                {
                    break;
                }

                list.Add(m);
                count++;
            }

            // Console.WriteLine(count);
            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 27728
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double dis = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	printf("%.8f\n", dis);
}


Measured memory_bytes: 3152
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

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

int main() {
	ll n,m;
    vector<ll>x,y;
    cin>>n>>m;
    REP(i,m){
        ll z;
        cin>>z;
        x.push_back(z);
    }
    sort(x.begin(),x.end());
    REP(i,x.size()-1){
        ll z=x[i+1]-x[i];
        y.push_back(z);
    }
    sort(y.begin(),y.end());
    ll ans=0;
    
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
    REP(i,y.size()-n+1){
        ans+=y[i];
    }

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


Measured memory_bytes: 2548
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> left(n + 1), right(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> left[i] >> right[i];
  }
  sort(right.begin(), right.end());
  sort(left.rbegin(), left.rend());
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    if (right[i] < left[i]) ans += 2 * (left[i] - right[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n, m, sum = 0, cnt = 0;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  for (int i = 0; i < n; i++) {
    if (4 * m * a.at(i) >= sum) {
      cnt++;
    }
  }
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(void){
  long n;
  cin >> n;
  long res = 0;
  long m = n/15;
  res = 15*8*m*(m-1)/2 + (1+2+4+7+8+11+13+14)*m;
  if(n%15 > 0) res+=m*15+1;
  if(n%15 > 1) res+=m*15+2;
  if(n%15 > 3) res+=m*15+4;
  if(n%15 > 6) res+=m*15+7;
  if(n%15 > 7) res+=m*15+8;
  if(n%15 > 10) res+=m*15+11;
  if(n%15 > 12) res+=m*15+13;
  if(n%15 > 13) res+=m*15+14;
  cout << res << endl;
  return 0;
}
/*
1000000
266666333332

*/


Measured memory_bytes: 3632
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    long long n;
    cin >> n;
    vector <int> ans;
    int cur = 1;
    while (n > 0) {
        if (n % 26 == 0) {
            ans.pb(26);
            n -= cur;
        }
        else
            ans.pb(n % 26);
        n /= 26;
        cur++;
        cerr <<n << " ";
    }
    reverse(all(ans));
    /*forn (i, 0, sz(ans)) {
        if (!ans[i])
            continue;
        if (ans[i] == 1 && i + 1 < sz(ans) && ans[i + 1] == 0)
            cout << 'z';
        else
            cout << (char)(ans[i] + 'a' - 1);
    }*/
    for (int i : ans) {
            cout << (char)(i + 'a' - 1);
    }
    return 0;
}

Measured memory_bytes: 3652
from collections import defaultdict
N, M = [int(x) for x in input().split()]
dict = defaultdict(bool)  # int/bool/list....
for i in range(M):
    a, b = [int(x) for x in input().split()]
    dict[(a, b)] = True

for j in range(1, N + 1):
    if dict[(1, j)] and dict[(j, N)]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 79656
#include<iostream>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int h, w, c;

int Cnt(vector< vector<int> > &f, int y, int x, int color){
    f[y][x] = -1;
    int ret = 1;
    int my[] = {0, 0, 1, -1};
    int mx[] = {1, -1, 0, 0};
    REP(i, 4){
        int ny = y + my[i], nx = x + mx[i];
        if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
        if(f[ny][nx] == color){
            ret += Cnt(f, ny, nx, color);
        }
    }
    return ret;
}

void changeColor(vector< vector<int> > &f, int aft_color, int bef_color, int y, int x){
    f[y][x] = aft_color;
    int my[] = {0, 0, 1, -1};
    int mx[] = {1, -1, 0, 0};
    REP(i, 4){
        int ny = y + my[i], nx = x + mx[i];
        if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
        if(f[ny][nx] == bef_color){
            changeColor(f, aft_color, bef_color, ny, nx);
        }
    }
}

int dfs(vector< vector<int> > &f, int cnt){
    //debug
    //cout <<cnt <<endl;
    //REP(i, f.size()){
    //    REP(j, f[i].size()) cout <<f[i][j] <<" ";
    //    cout <<endl;
    //}
    //cout <<endl;
    if(cnt >= 5){
        if(f[0][0] == c){
            vector< vector<int> > tmp_f = f;
            return Cnt(tmp_f, 0, 0, f[0][0]);
        }
        else return 0;
    }
    int ret = 0;
    FOR(color, 1, 7){
        if(color == f[0][0]) continue;
        vector< vector<int> > tmp_f = f;
        changeColor(tmp_f, color, f[0][0], 0, 0);
        ret = max(ret, dfs(tmp_f, cnt + 1));
    }
    return ret;
}

int main(){
    while(cin >>h >>w >>c && (h || w || c)){
        vector< vector<int> > f(h, vector<int>(w));
        REP(i, h) REP(j, w) cin >>f[i][j];
        cout <<dfs(f, 0) <<endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
  ll n, k;

  cin >> n >> k;
  ll min = n;
  ll diff = abs(n - k);
  if (diff > min) {
    cout << min << endl;
  } else {
    min = diff;
    bool flag = true;
    ll div = n / k;
    // cout << "diff = " << diff << endl;
    // cout << "div =  " << div << endl;
    diff = abs(n - (div * k));
    if (diff > abs(diff - k)) {
      cout << abs(diff - k) << endl;
    } else {
      cout << diff << endl;
    }
  }
	return 0;
}


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

int main()
{
    string S;
    cin >> S;
    if ( S.size() < 26 ) {
        char c = 'a';
        while ( c <= 'z' && count(begin(S), end(S), c) == 1 ) {
            c++;
        }
        S += c;
        cout << S << endl;
    } else {
        int i = 24;
        string pat;
        while ( i >= 0 && S[i] > S[i + 1] ) {
            pat += S[i + 1];
            i--;
        }
        pat += S[i + 1];
        if ( i < 0 ) {
            cout << -1 << endl;
        } else {
            sort(begin(pat), end(pat));
            string T = S.substr(0, i);
            T += *upper_bound(begin(pat), end(pat), S[i]);
            cout << T << endl;
        }
    }
    return ( 0 );
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

ll ans[2001];

int main() {
    int s;
    cin >> s;
    for(int i = 3; i < 2001; ++i) {
        ans[i] = 1;
    }
    for(int i = 3; i <= s; ++i) {
        for(int j = 3; j <= i; ++j) {
            ans[i] = (ans[i] + ans[i-j]) % mod;
        }
    }
    cout << ans[s];
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    
    int ans = 1;
    while ((ans<<1)<=n) {
        ans <<= 1;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0; v < n; v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u = 0; u < n; u++) color[u] = WHITE;
  tt = 0;

  for(u = 0; u < n; u++) if(color[u] == WHITE) dfs_visit(u);
  for(u = 0; u < n; u++) printf("%d %d %d\n",u+1, d[u], f[u]);
}

int main(){
  int u, k, v, i ,j;

  scanf("%d",&n);
  for(i = 0; i < n; i++) for(j = 0; j < n; j++) M[i][j] = 0;

  for(i = 0; i < n; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 636
L=list(map(int,input()))
for i in range(2):
    for j in range(2):
        for k in range(2):
            if L[0]+(-1)**i*L[1]+(-1)**j*L[2]+(-1)**k*L[3]==7:
                if i==0:
                    o1="+"
                else:
                    o1="-"
                if j==0:
                    o2="+"
                else:
                    o2="-"
                if k==0:
                    o3="+"
                else:
                    o3="-"
                print(str(L[0])+o1+str(L[1])+o2+str(L[2])+o3+str(L[3])+"=7")
                exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAXN 300005
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
int n,m,sum[MAXN];
struct node{
    int l,r;
}a[MAXN];
vector<int>v[MAXN];
int lowbit(int x){
    return x&-x;
}
void add(int x,int y){
    while(x<=m){
        sum[x]+=y;
        x+=lowbit(x);
    }
}
int query(int x){
    int ans=0;
    while(x){
        ans+=sum[x];
        x-=lowbit(x);
    }
    return ans;
}
int main(){
    while(~scanf("%d%d",&n,&m)){
        memset(sum,0,sizeof(sum));
        rep(i,1,m){
            v[i].clear();
        }
        rep(i,1,n){
            scanf("%d%d",&a[i].l,&a[i].r);
            int temp=a[i].r-a[i].l+1;
            v[temp].push_back(i);
        }
        rep(i,1,m){
            int ans=0,len=v[i].size();
            rep(j,0,len-1){
                int pos=v[i][j];
                add(a[pos].l,1);
                add(a[pos].r+1,-1);
            }
            for(int j=i;j<=m;j+=i){
                ans+=query(j);
            }
            n-=len;
            printf("%d\n",ans+n);
        }
    }
    return 0;
}


Measured memory_bytes: 14592
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
ll ans;
string S;
ll N;
ll T[101];
ll p[100001];

int main() {
	cin >> N;
	rep(i, 1, N + 1) {
		cin >> p[i];
	}
	ans = 0;
	ll count = 0;
	rep(i, 1, N + 1) {
		if (p[i] == i) {
			count++;
			if (count == 2) {
				count = 0;
				ans++;
			}
		}
		else {
			if (count == 1) {
				count = 0;
				ans++;
			}
		}
	}
	if (count == 1) {
		count = 0;
		ans++;
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}


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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

bool mp[33];

int main()
{
	string str;cin >> str;
	
	REP(i,str.size()){
		mp[str[i] - 'a'] = true;
	}

	
	if(str.size() == 26){
		if(str == "zyxwvutsrqponmlkjihgfedcba"){
			cout << -1 << endl;
			return 0;
		}
		int tmp = 0;
		for(tmp = str.size() - 1;tmp >= 0;tmp--){
			mp[str[tmp] - 'a'] = false;
			if(str[tmp] > str[tmp-1]){
				REP(i,tmp-1){
					cout << str[i];
				}
		//		cout << "!,!";
				REP(i,26){
		//			cout << (!mp[i]) << ' ' << (int)(str[tmp-1] - 'a') << ' '  << i << endl;
					if((!mp[i]) && (int)(str[tmp-1] - 'a') < i){
		//				cout << "!";
						char aa = 'a' + i;
						cout << aa;
						cout << endl;
		//				SHOW1d(mp,26);
						return 0;
					}
				}
			}
		}
					
	}
	
	
	cout << str;
	
	REP(i,26){
		if(!mp[i]){
			char tmp = 'a' + i;
			cout << tmp << endl;
			return 0;
		}
	}

	return 0;
}

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

int main(){
  double a,b,c,d,e,f,x,y;

  while(std::cin >>a>>b>>c>>d>>e>>f){

    x = (double)(c*e-b*f)/(a*e-b*d);
    y = (double)(a*f-c*d)/(a*e-b*d);
    if(x == 0){x = 0;}
    if(y == 0){y = 0;}
    printf("%.3f %.3f\n",x,y);

  }
}

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

#define DFS_ITEM 4

//depth = N
int N, A, B, C, ans = 2e9;
vector<int> l(10, -1);


void calc(vector<int> v) {
    int a=0, b=0, c=0, mp=-30;
    
    for(int i=0; i<N; i++){
    	if(v[i] == 0){
    	    a += l[i];
    	    mp += 10;
    	}else if(v[i] == 1){
    	    b += l[i];		    
    	    mp += 10;
    	}else if(v[i] == 2){
    	    c += l[i];
    	    mp += 10;
    	}else if(v[i] == 3){
    	    mp += 0;
    	}else{
    	    cout << "error"<<endl;
    	}	
    }        
    
    if(a!=0 && b!=0 && c!=0){
	mp += abs(A-a) + abs(B-b) + abs(C-c);
	ans = min(mp, ans);
    }
}
void DFS(int depth, vector<int> v) {    
    if(depth == N){
	calc(v);
	return;
    }    
    for(int i=0; i<DFS_ITEM; i++){
	v[depth] = i;
	DFS(depth+1, v);	
    }
}

int main(){
    cin >> N >> A >> B >> C;
    vector<int> v(N+1);    
    for(int i=0; i<N; i++)
	cin >> l[i];
    DFS(0, v);			    
    cout << ans << "\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    for (int i = 0; i < v.size(); ++i)
      os << v[i] << " ";
    os << '\n';
  }
  return os;
}
signed main() {
    int n, x, m;
    cin >> n >> x >> m;
    vector<int> vec;
    vec.push_back(x);
    set<int> s;
    int value = (x*x)%m;
    s.insert(x);
    int i;
    while(s.find(value) == s.end())
    {
        vec.push_back(value);
        s.insert(value);
        value = (value*value)%m;
    }
    int idx = -1;
    for(i=0;i<vec.size();i++)
        if(vec[i] == value)
            break;
    idx = i;
    int cyc = vec.size() - idx;
    if(n < vec.size())
    {
        int sum = 0;
        for(i=0;i<n;i++)
            sum+=vec[i];
        cout << sum;
    }
    else
    {
       // cout << vec.size() << " " << value;
        int sum = 0;
        for(i=0;i<idx;i++)
            sum+=vec[i];
        //cout << sum << '\n';
        int tot = 0;
        for(i=idx;i<vec.size();i++)
            tot+=vec[i];
        n = n - idx;
        sum = sum + tot*(n/cyc);
        n = n%cyc;
        for(i = idx; i < idx + n;i++)
            sum+=vec[i];
        cout << sum;
    }
   // cout << vec.size() << " " << value << '\n';
}

Measured memory_bytes: 5932
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,a[110],ans=0;
    cin>>n>>x;
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    rep(i,n-1){
        if(x>=a[i]){
            ans++;
            x -=a[i];
        }
        else break;
    }
    if(x==a[n-1]) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ALDS1_4_B_binary_
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] S = getsplit();
            int[] s2 = Array.ConvertAll(S, int.Parse);            
            Console.ReadLine();
            string[] T = getsplit();
            int count=0;

            foreach (var t in T)
                if (BinarySearch(s2, getint(t)))
                    count++;

            Console.WriteLine(count);
        }

        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint(string a)
        {    
                int x = int.Parse(a);
                return x;            
        }

        static bool BinarySearch(int[] a,int key)
         {
            int left = 0;
            int right = a.Length;

            while (left<right)
            {
                int mid = (left + right) / 2;
                if (a[mid] == key)
                {
                    return true;
                }
                else if (key < a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }
            return false;
         }
    }
}

Measured memory_bytes: 18996
def main():
    a, b, x = map(int, input().split())
    if a == 0:
        left = 0
    else:
        left = (a-1)//x + 1

    if b == 0:
        right = 1
    else:
        right = b//x + 1 

    print(right - left)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	long double da,db;
	cin>>da>>db;
	da*=db;
	cout<<(LL)da<<endl;
}

Measured memory_bytes: 3724
a, b, c = map(int, input().split())
k = int(input())

count = 0
while count < k and not (a < b < c):
    if a >= b:
        count += 1
        b = 2*b
    if b >= c:
        count += 1
        c = 2*c

if count <= k:
    if a < b < c:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 61668
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    N, x0 = map(int, input().split())
    X = list(map(int, input().split()))

    ans = 0
    for x in X:
        ans = gcd(ans, abs(x - x0))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84524
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    int D, X;
    cin >> N;
    cin >> D >> X;

    vector<int>syouhi(D);
    vector<int>A(N);

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

    for (int i=0; i<N; i++){
        int j=0;
        int ai = A[i];
        while(ai*j  < D){
            syouhi[ai*j]++;
            j++;
        }
    }
    int ans = X;
    for (int i=0; i<D; i++)ans += syouhi[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int map[51][51],w,h;
void dfs(int y,int x){
	map[y][x] = 0;
	int tx,ty;
	for(int dx=-1;dx<=1;dx++){
		for(int dy=-1;dy<=1;dy++){
			tx = x + dx;
			ty = y + dy;
			if(tx > -1 && tx < w && ty > -1 && ty < h && map[ty][tx] == 1) dfs(ty,tx);
		}
	}
	return;

}
int main(){
	int count;
	while(cin >> w >> h && (w!=0 && h!=0)){
		count = 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> map[i][j];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j] == 1){
					dfs(i,j);
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0