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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 200010;
int N,M;
int D[MC];
int T[MC];

int halt(){
	cout << "NO" << endl;
	return 0;
}

int main(){
	cin >> N;
	repp(i,0,N) cin >> D[i];
	cin >> M;
	repp(i,0,M) cin >> T[i];
	sort(D,D+N);
	sort(T,T+M);
	int x = 0;
	repp(i,0,M){
		while(x < N && D[x] != T[i]) ++x;
		if(x == N) return halt();
		++x;
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define LEN1 100000
#define LEN2 500

int main(){
  int i, j, count=0;
  int n, q, S[LEN1], T[LEN2];

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

  scanf("%d", &q);
  for(i=0; i<q; i++)
    scanf("%d", &T[i]);

  for(i=0; i<q; i++){
    for(j=0; j<n; j++){
      if(T[i] == S[j]){
        count++;
        break;
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 2108
n, k = map(int, input().split())
h = list(map(int, input().split()))

def answer(n: int, k: int, h: list) -> int:
    ans = 0
    for i in range(0, n):
        if h[i] >= k:
            ans += 1
    return ans

print(answer(n, k, h))


Measured memory_bytes: 18376
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

INF = float('inf')

N, M = map(int, input().split())
adjL = [[] for _ in range(3*N)]
for _ in range(M):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    adjL[3*u+0].append(3*v+1)
    adjL[3*u+1].append(3*v+2)
    adjL[3*u+2].append(3*v+0)
S, T = map(int, input().split())
S, T = S-1, T-1

# 単一始点最短経路を求める（Dijkstra法）
def Dijkstra(adjList, vSt):
    numV = len(adjList)
    numUsed = 0
    costs = [INF] * numV
    costs[vSt] = 0
    PQ = []
    heappush(PQ, (0, vSt))
    while PQ:
        cNow, vNow = heappop(PQ)
        if cNow > costs[vNow]: continue
        numUsed += 1
        if numUsed == numV: break
        for v2 in adjList[vNow]:
            c2 = cNow + 1
            if c2 < costs[v2]:
                costs[v2] = c2
                heappush(PQ, (c2, v2))
    return costs

costs = Dijkstra(adjL, 3*S)
#print('costs:', costs)

if costs[3*T] == INF:
    print(-1)
else:
    print(costs[3*T]//3)


Measured memory_bytes: 98160
#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;
	cin >> n;
    vector<int> ns(2);
    vector<vector<int>> ka(2, vector<int>(0));
    int f = 0;
    rep(i, n){
      cin >> ns.at(1);
      ns.at(0) = ns.at(1) -1;
      if(i == 0){
        ka.at(i%2).push_back(ns.at(0));
        ka.at(i%2).push_back(ns.at(1));
      }
      for(int j=0; j<ka.at(i%2).size(); j++){
        rep(k, 2){
          if(ka.at(i%2).at(j) <= ns.at(k)){
            int fl = 0;
           for(int l=0; l<ka.at((i+1)%2).size(); l++){
             if(ka.at((i+1)%2).at(l) == ns.at(k)) fl = 1;
           }
            if(fl == 0) ka.at((i+1)%2).push_back(ns.at(k));
          }
        }
      }
      if(ka.at((i+1)%2).size() == 0) f = 1;/*
      for(int j=0; j<ka.at((i+1)%2).size(); j++){
        cout << ka.at((i+1)%2).at(j) << ' ';
      }
      cout << endl;*/
      while(ka.at(i%2).size() > 0){
        ka.at(i%2).pop_back();
      }
    }
	if(f == 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}

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

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

	if(a < b)
		cout << "a < b" << endl;
	if(a > b)
		cout << "a > b" << endl;
	if(a == b)
		cout << "a == b" << endl;

	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll ans=0,a[11],n,m,q,l[61],r[61],v[61],ad[61];
void dfs(ll x,ll y)
{
	ll i,ret=0;
	a[x]=y;
	if(x==n-1)
	{
		for(i=0;i<q;i++)
		{
			if(a[r[i]]-a[l[i]]==v[i])
			{
				ret+=ad[i];
			}
		}
		ans=max(ans,ret);
		return;
	}
	for(i=y;i<=m;i++)
	{
		dfs(x+1,i);
	}
	return;
}
int main(){
	ll i;
	cin>>n>>m>>q;
	for(i=0;i<q;i++)
	{
		cin>>l[i]>>r[i]>>v[i]>>ad[i];
		l[i]--;
		r[i]--;
	}
	for(i=1;i<=m;i++)
	{
		dfs(0,i);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int	read()//不管是正负数，都可以 
{
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(int a){
	write(a); puts("");
}
#include<map>
#include<cmath>
const int N=200005;
map<int,int> M;
map<int,int>::iterator it;
int n,k,a[N],que[N],r,ans;
int main(){
	n=read(); k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)M[a[i]]++;
	for(it=M.begin();it!=M.end();it++){
		que[++r]=it->second;
	}
	sort(&que[1],&que[r+1]);
	for(int i=1;i+k<=r;i++){
		ans+=que[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <stdio.h>
#include <string.h>

#define MAX 100
//#define NIL -1

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;
int n;

void insert(int val) {
    Node *y = NIL;
    Node *x = root;
    Node *z = new Node();
    
    z->key = val;
    z->left = NIL;
    z->right = NIL;
    
    while (x != NIL) {
        y = x;
        if (z->key > x->key) {
            x = x->right;
        } else {
            x = x->left;
        }
    }
    z->parent = y;
    
    if ( y == NIL ) {
        root = z;
    } else if ( y->key > z->key ) {
        y->left = z;
    } else {
        y->right = z;
    }
//    delete z;
}

Node * find(Node *x, int val) {
    while ( x != NIL) {
        if (x->key == val) break;
        if (x->key > val) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return x;
}

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

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

void print() {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}

int main() {
    int val;
    char moji[10];
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", moji);
        if (moji[0] == 'i') {
            scanf("%d", &val);
            insert(val);
        } else if (moji[0] == 'f') {
            scanf("%d", &val);
            Node *t = find(root, val);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else {
            print();
        }
    }
    
    return 0;
}

Measured memory_bytes: 21956
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  ll H,W,h,w; cin>>H>>W>>h>>w;
cout<<H*W-H*w-W*h+h*w<<endl;
 
  
}

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

using namespace std;

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

int sum_of_digit(int n){
	int res = 0;
	while(n > 0){
		res += n % 10;
		n /= 10;
	} // end while
	return res;
}

bool is_ok3(int n){
	int sum = sum_of_digit(n);
	return (sum % 3 == 0);
}

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

	int A, B; cin >> A >> B;

	bool ok = false;

	ok |= is_ok3(A);
	ok |= is_ok3(B);
	ok |= is_ok3(A + B);

	cout << (ok ? "Possible" : "Impossible") << endl;	
	
	return 0;
}

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

#define MAX_E 1001
int V, E, F, US[MAX_E], VS[MAX_E], CAP[MAX_E], COST[MAX_E];

class MinCostFlow {
public:
  const int INFTY = (1 << 21);
  struct Edge { int t, cap, cost, rev; };
  struct P {
    int d, id;
    bool operator < (const P &other) const {
      return d > other.d;
    }
  };

  MinCostFlow(int V):
    V(V), G(V, vector<Edge>(0)), dist(V, INFTY), prevv(V, -1), preve(V, -1), potential(V, 0) {}

  void addEdge(int s, int t, int cap, int cost) {
    G[s].push_back({ t, cap, cost, (int)G[t].size() });
    G[t].push_back({ s, 0, -cost, (int)G[s].size() - 1 });
  }

  int calc(int s, int t, int f) {
    int res = 0;

    while (f > 0) {
      dijkstra(s);
      if (dist.at(t) == INFTY) return -1;
      for (int v = 0; v < V; v++) potential.at(v) += dist.at(v);

      int d = f;
      for (int v = t; v != s; v = prevv.at(v)) {
        int cap = G.at(prevv.at(v)).at(preve.at(v)).cap;
        d = min(d, cap);
      }
      f -= d;
      res += d * potential.at(t);
      for (int v = t; v != s; v = prevv.at(v)) {
        Edge &edge = G.at(prevv.at(v)).at(preve.at(v));
        edge.cap -= d;
        G.at(v).at(edge.rev).cap += d;
      }
    }

    return res;
  }

private:
  int V;
  vector<vector<Edge> > G;
  vector<int> dist, prevv, preve, potential;

  void dijkstra(int s) {
    reset(s);
    priority_queue<P> PQ;
    vector<bool> done(V, false);
    PQ.push({ 0, s });

    while (PQ.size()) {
      P p = PQ.top(); PQ.pop();
      if (done.at(p.id)) continue;
      done.at(p.id) = true;
      if (dist.at(p.id) < p.d) continue;
      for (int e = 0; e<G.at(p.id).size(); e++) {
        Edge &edge = G.at(p.id).at(e);
        if (done.at(edge.t)) continue;
        if (edge.cap <= 0) continue;
        if (dist.at(edge.t) <= dist.at(p.id) + edge.cost + potential.at(p.id) - potential.at(edge.t)) continue;
        dist.at(edge.t) = dist.at(p.id) + edge.cost + potential.at(p.id) - potential.at(edge.t);
        prevv.at(edge.t) = p.id;
        preve.at(edge.t) = e;
        PQ.push({ dist.at(edge.t), edge.t });
      }
    }
  }

  void reset(int s) {
    fill(dist.begin(), dist.end(), INFTY);
    dist.at(s) = 0;
  }
};

void input() {
  cin >> V >> E >> F;
  for (int i=0; i<E; i++) {
    cin >> US[i] >> VS[i] >> CAP[i] >> COST[i];
  }
}

void solve() {
  MinCostFlow mcf(V);
  for (int i=0; i<E; i++) {
    mcf.addEdge(US[i], VS[i], CAP[i], COST[i]);
  }
  cout << mcf.calc(0, V-1, F) << endl;
}

int main() {
  input();
  solve();
}



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

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

int main(){
  int n,k;
  cin>>n>>k;
  ll c[n];
  rep(i,0,n) cin>>c[i];
  sort(c,c+n);
  
  ll a[n+1];
  a[0]=1;
  rep(i,1,n+1) a[i]=a[i-1]*i%mod;
  ll b[n+1];
  b[0]=1;
  rep(i,1,n+1) b[i]=power(a[i],1e9+5);
  
  ll cur=0;
  ll ans=0;
  rep(i,0,n-k+1){
    cur+=c[n-1-i]-c[i];
    ans+=cur%mod*a[n-2-i]%mod*b[k-2]%mod*b[n-k-i]%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const ll INF = 400000001;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> ab(n), cd(m);

    rep(i, n){
        cin >> ab[i].first >> ab[i].second;
    }

    rep(i, m){
        cin >> cd[i].first >> cd[i].second;
    }

    rep(i, n){
        int tmp = 0;
        ll min_dist = INF;
        rep(j, m){
            ll tmp_dist = abs(ab[i].first-cd[j].first) + abs(ab[i].second - cd[j].second);
            if(min_dist > tmp_dist){
                min_dist = tmp_dist;
                tmp = j;
            }
        }
        cout << tmp+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    static StringBuilder sb;

    public static void solve(int n, int[] arr) {
        int highest = 0;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            if (arr[i] < highest) sum += highest - arr[i];
            else highest = arr[i];
        }
        sb.append(sum);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        sb = new StringBuilder();

        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        solve(n, arr);

        pw.print(sb);
        pw.flush();
        sc.close();
    }
}

Measured memory_bytes: 60204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] as = br.readLine().split(" ");
		String temp;
		temp = as[0];
		as[0] = as[1];
		as[1] = temp;
		
		temp = as[0];
		as[0] = as[2];
		as[2] = temp;
		
		System.out.println(as[0] + " " + as[1] + " " + as[2]);
		
	}

}



Measured memory_bytes: 22740
import sys


def solve(a_list):
    for a in a_list:
        if a % 2 == 0:
            if a % 3 != 0 and a % 5 != 0:
                return False
    return True


def main():
    input = sys.stdin.buffer.readline
    _ = int(input())
    a_list = list(map(int, input().split()))
    print("APPROVED" if solve(a_list) else "DENIED")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

int main(void) {
	int n,m; cin >> n >> m;
	vi a(n); rep(i,n) cin >> a[i];
	priority_queue<int> q;
	rep(i,n) q.push(a[i]);
	rep(i,m){
		int mx = q.top();
		q.pop();
		mx /= 2;
		q.push(mx);
	}
	ll ans = 0;
	while(q.size()){
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}




Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a[200001];
bool check(ll x){
    ll mov=0;
    for(ll i=0;i<n;i++){
        mov+=(a[i]-1)/x;
    }
    if(mov<=k){
        return true;
    }
    return false;
}
int main()
{
    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll lp=0;
    ll rp=1000000001;
    ll mid;
    bool flag1=true,flag2=true;
    while(rp-lp>1){
        flag1=true,flag2=true;
        mid=(lp+rp)/2;
        if(check(mid)){
            rp=mid;
        }else{
            lp=mid;
        }

    }
    cout<<rp<<endl;
}

Measured memory_bytes: 5156
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& v : A)cin >> v;
  double ans = 0;
  for (auto& v : A)
   ans += 1. / v;
  ans = 1. / ans;
  cout << fixed << setprecision(6) << ans << endl;
}


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

int main() {
	int n ;
	while(1)
	{
		cin >> n ; if(!n) break;
		int cnt=0; map<int,int> m;
		int a[12]; for(int i=0;i<n;i++) cin >> a[i] ;
		while(1)
		{
			for(int i=0;i<n;i++) if(m.find(a[i])!=m.end()) m[a[i]]++; else m[a[i]]=1;
			int b[12];
			for(int i=0;i<n;i++) b[i]=m[a[i]];
			bool same=true;
			for(int i=0;i<n;i++) if(a[i]!=b[i]) {same=false; break;}
			if(same) break;
			cnt++; memcpy(a,b,sizeof(b)); m.clear();
		}
		cout << cnt << '\n' ;
		for(int i=0;i<n;i++) {if(i) cout << ' ' ; cout << a[i];}
		cout << '\n' ;
	}
}

Measured memory_bytes: 1196
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Atcoder.Abc
{
    //https://atcoder.jp/contests/abc173/tasks/abc173_a
    public class Abc173_A
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var N = int.Parse(ReadLine());
            var ans = (1000 - N % 1000) % 1000;

            WriteLine(ans);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 17444
nx = input().split(' ')
n = int(nx[0])+1
x = int(nx[1])

l = input().split(' ')
llen = len(l)
d = 0
bound = 0
for i in range(n):
#  print(d)
  if d<=x :
    bound += 1
  if llen <= i:
    break
  d = d + int(l[i])

print(bound)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
typedef long long ll;
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int A,B,T;
  cin>>A>>B>>T;
  int ans=0;
  while(1){
    if(T+0.5>=A){
      T-=A;
      ans+=B;
    }else{
      break;
    }
  }
  cout<<ans;
  
  return 0;
}

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

int main(){
  string al="abcdefghij";
  int N;
  cin>>N;

  queue<pair<string,int>> S;
  S.push(make_pair("a",1));

  while(!S.empty()){
    auto T=S.front();
    S.pop();
    if(T.first.size()==N) cout<<T.first<<endl;
    else{
    for(int i=0;i<=T.second;++i){
      string U=T.first;
      U.push_back(al[i]);
      if(i<T.second) S.push(make_pair(U,T.second));
      else S.push(make_pair(U,T.second+1));
    }
  }
  }
}


Measured memory_bytes: 8832
//https://atcoder.jp/contests/abc179/tasks/abc179_b
#include <iostream>
using namespace std;

const int MAXN=1e2+4;
int arr[MAXN][3];
int main() {
    int n;
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>arr[i][1]>>arr[i][2];
    }

    for (int i=1; i<=n-2; i++) {
        if (arr[i][1]==arr[i][2] && arr[i+1][1]==arr[i+1][2] && arr[i+2][1]==arr[i+2][2]) {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

int main(){
    int n;
    std::cin>>n;
    std::vector<std::tuple<long long,long,long>> c(n);
    for(size_t i = 0; i < n; i++)
    {
        long a,b;
        std::cin>>a>>b;
        c[i]=std::make_tuple(a+b,a,b);
    }
    
    std::sort(c.rbegin(),c.rend());

    long long ans=0;
    for(size_t i = 0; i < n; i++)
    {
        if(i%2==0){
            auto &v=std::get<1>(c[i]);
            ans+=v;
        }
        else{
            auto &v=std::get<2>(c[i]);
            ans-=v;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    var a = sc.nextInt()
    var b = sc.nextInt()
    val u = sc.next()

    if (u == s) {
        a--
    } else {
        b--
    }
    println("$a $b")
}


Measured memory_bytes: 31256
def solve(s,buf)
  h,w=s.split.map &:to_i
  c=0
  (nq=[0i]).each{|z|
    next if ?-==t=buf[z.imag][z.real]
    c+=1
    (cq=[z]).each{|u|
      next if buf[u.imag][u.real]==?-
      buf[u.imag][u.real]=?-
      [1,1i,-1,-1i].each{|d|
        v=u+d
        next unless (0...w)===v.real&&(0...h)===v.imag
        case buf[v.imag][v.real]
        when ?-; next
        when t; cq.push(v)
        else; nq.push(v)
        end
      }
    }
  }
  c
end
nparam,*buf=""
while s=gets
  if s=~/^\d/
    p solve(nparam,buf) if !buf.empty?
    break if s=~/^0/
    buf.clear
    nparam=s
  else
    buf.push(s)
  end
end

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int x,y;
	int i;
	int cnt;
	
	cin>>x>>y;
	
	cnt=0;
	for(i=1;i<=y;i++){
		if((i*x)%y==0) cnt++;
	}
	
	cout<<(x+y)-cnt+1<<endl;
	
	return 0;
}


Measured memory_bytes: 3132
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int main(){
  int count=0;
  string ans="";
  string s;
  cin>>s;

  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='0'){
      ans[count]='0';
      count++;
    }else if(s[i]=='1'){
      ans[count]='1';
      count++;
    }else{
      count--;
      if(count<0) count=0;
    }
  }
  for(int i=0;i<count;i++) cout<<ans[i];
  cout<<endl;
}


Measured memory_bytes: 256
N = int(input())
T,A = map(int, input().split())
H = [int(i) for i in input().split()]
ans = 0
F = 9999999999999
for n in range(N):
    f = abs(T-A-0.006*H[n])
    if f < F:
        F = f
        ans = n+1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
		using namespace std;
		#define sz(x) (int)(x).size()
		#define int long long int
		#define loop(i,a,b) for(int i=a;i<b;i++)
		#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
		#define vi vector<int>
		#define si set<int>
		#define pii pair <int, int>
		#define sii set<pii>
		#define vii vector<pii>
		#define mii map <int, int>
		#define pb push_back
		#define all(aa) aa.begin(), aa.end()
		#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
		//Constants
		const int mod = 1E9+7; /* 1e9 + 7*/
		const int MAXN = 1000005; /*1e6 +5 */
		 
		int spf[1000009]; // stores the smallest prime factor of a number
		 vector<vi> graph;
		// vi count1;
		 
		 int gcdExtended(int a, int b, int *x, int *y); 
		 
		 int count1(int x,int y,int z);
		 //int n;
		void sieve()
		{
			spf[1] = 1;
			for (int i=2; i<MAXN; i++)
				spf[i] = i;
			for (int i=4; i<MAXN; i+=2)
				spf[i] = 2;
		 
			for (int i=3; i*i<MAXN; i++)
				if (spf[i] == i)
				{
					for (int j=i*i; j<MAXN; j+=i)
						if (spf[j]==j)
							spf[j] = i;
				}
		}
		
		void print(vi v)
		{
			for(auto x:v)
			cout<<x<<" ";
			cout<<endl;
		}
		 
		/* Iterative Function to calculate (x^y)%p 	 in O(log y) */
		int power(int x,  int y, int p)
		{
			int res = 1;     // Initialize result
			x = x % p; // Update x if it is more than or
						// equal to p 
			if (x == 0) return 0; // In case x is divisible by p;     
			while (y > 0)
			{
				// If y is odd, multiply x with result
				if (y & 1)
					res = (res*x) % p;     
				// y must be even now
				y = y>>1; // y = y/2
				x = (x*x) % p;
			}
			return res;
		}
		
		 
		void solve()
		{
			int n;cin>>n;
			int arr[n];
			scan(arr,n);
			int prefix[n]={0}, ans=0,s=0;
			loop(i,0,n)
			{
				s+=arr[i];
				s=s%mod;
				prefix[i]=s;
			}
			loop(i,0,n)
			{
				int req=(s%mod -prefix[i]%mod)%mod;
				if(req<0)
				req+=mod;
				ans=(ans%mod + ((arr[i]%mod) *(req%mod))%mod)%mod;
			}
			cout<<ans%mod;
		}

		 
		int32_t main()
		{
			faster;
			int t=1;
			//cin>>t;
			while(t--) solve();		 
			return 0;
		}


Measured memory_bytes: 6684
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

ll n,k;
ll a[211111];

int main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    ll cnt=0;
    sort(a,a+n);
    for(int i=n-1;i>=n-k;i--){
        if(i<0)break;
        a[i]=0;
    }
    ll ans=0;
    rep(i,n)ans+=a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n;
    bool ans = true;
    cin >> n;
    string before, now;
    set<string>dist;
    cin >> before;
    dist.insert(before);
    rep(i, n-1) {
        cin >> now;
        if (dist.count(now)) {
            ans = false;
            break;
        }
        if (before.back() != now[0]) {
            ans = false;
            break;
        }
        dist.insert(now);
        before = now;
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed Jan 16 19:10:41 2019
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	sort.Ints(arr)
	fmt.Println(arr[len(arr)-1] - arr[0])
}


Measured memory_bytes: 512
import bisect

n,W = map(int,input().split())
b = [list(map(int, input().split())) for i in range(n)]
dp = [float("INF") for i in range(10001)]
dp[0] = 0
for v,w in b:
    for i in range(10001):
        if 10000-i+v < 10001:
            dp[10000-i+v] = min(dp[10000-i+v], dp[10000-i]+w)
for i in range(1,10000):
    dp[10000-i] = min(dp[10000-i], dp[10001-i])
print(bisect.bisect_right(dp,W)-1)


Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s, t; cin >> s >> t;
	vector<vector<int>>dp(s.size() + 1, vector<int>(t.size() + 1, 0));
	rep(i, 0, s.size()) {
		rep(j, 0, t.size()) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
	int i = s.size(), j = t.size();
	string ans;
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) {
			--i;
		}
		else if (dp[i][j] == dp[i][j - 1]) {
			--j;
		}
		else {
			ans = s[i - 1] + ans;
			--i; --j;
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 35584
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> A(n);
    cin>>A;
    vector<ll> dp(n),dp2(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=max(A[i],0LL);
        dp[i]=sum;
    }
    sum=0;
    for(ll i=n-1;i>=0;i--){
        sum+=max(A[i],0LL);
        dp2[i]=sum;
    }
    sum=0;
    for(ll i=0;i<k;i++){sum+=A[i];}
    ll ans=max(sum,0LL)+(k<n?dp2[k]:0LL);
    for(ll i=k;i<n;i++){
        sum+=A[i];
        sum-=A[i-k];
        ans=max(ans,max(sum,0LL)+dp[i-k]+(i+1<n?dp2[i+1]:0LL));
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            List<char> cs = new List<char>();
            int res = 0;
            foreach(char c in s)
            {
                if(cs.IndexOf(c) < 0)
                {
                    cs.Add(c);
                }
                else
                {
                    res++;
                }
            }
            if(res == 2 && cs.Count == 2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");

            }
        }
    }
}


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

int main(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for( int i=0; i<n; i++ ){
		cin >> arr[i];
	}
	int count = 0;
	for( int i=0; i<n; i++ ){
		for( int j=n-2; j>=i; j-- ){
			if( arr[j] > arr[j+1] ){
				count++;
				int tmp = arr[j];
				arr[j] = arr[j+1];
				arr[j+1] = tmp;
			}
		}
	}
	cout << arr[0];
	for( int i=1; i<n; i++ ){
		cout << " " << arr[i];
	}
	cout << endl;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int A,B,C;
	cin >> A >> B >> C;
	int N = C / (A * 7 + B);
	int M = C % (A * 7 + B);
	if(M > A * 7) {
		cout << N * 7 + 7 << endl;
	}
	else {
		cout << N * 7 + (M + A - 1) / A << endl;
	}
}


Measured memory_bytes: 3096
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




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

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll vis[100005];
ll d[100005];
vector<pint> M[100005];
vector<ll> anslist;
void dfs(ll K, ll dist) {

	d[K] = dist;
	vis[K] = 1;
	for (int i = 0; i < M[K].size(); i++) {
		if (vis[M[K][i].first] == 0) {
			dfs(M[K][i].first, dist + M[K][i].second);
		}
	}

}




int main() {
	ll N;
	ll a, b, c;
	cin >> N;

	rep(i, N-1) {
		cin >> a >> b >> c;
		M[a].push_back({ b, c });
		M[b].push_back({ a, c });

	}
	ll Q, K, x, y;





	cin >> Q >> K;
	vis[K] = 1;

	dfs(K, 0);

	rep(i, Q) {
		cin >> x >> y;
		anslist.push_back(d[x] + d[y]);
	}

	rep(i, Q) {
		cout << anslist[i] << endl;
	}



	return 0;
}

Measured memory_bytes: 15988
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

res = 0

for i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        x = L[i] - L[j]
        idx = bisect.bisect_right(L, x)
        res += max(j-idx, 0)

print(res)

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

int main(){
  char r[10],a[5];
  while(1){
  int hit=0,blow=0;
  cin>>r>>a;
  if(r[0]=='0'&&a[0]=='0'){
     break;
   }
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
        if(r[i]==a[j]){
          if(i==j){
            hit++;
          }else{
            blow++;
          }
        }
    }
  }
  cout<<hit<<" "<<blow<<"\n";
}
  return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,K; cin>>N>>K;
	int ans = 0;
	rp(y,1,N+1){
		int x; cin>>x;
		int a = x;
		int b = K-x;
		int minX = min(a,b);
		ans += minX * 2;
	}
	ote(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a = 0, b = 0, c = 0;
  cin >> a >> b;
  c = a + b;
  
  if (c % 2 == 0) cout << c / 2 << endl;
  else cout << c / 2 + 1 << endl;
}

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

int main(){
 int N,M,K;
  long long sum=0;
  cin >> N >> M >> K;
  vector<int> A(N),B(M);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int j=0;j<M;j++){
    cin >> B.at(j);
    sum+=B.at(j);
  }
  int ans=0;
  int j=M;
  for(int i=0;i<N+1;i++){
    while(j>0 && sum>K){
      j--;
      sum-=B.at(j);
    }
    if(sum>K){
      break;
    }
    ans=max(ans,i+j);
    if(i==N){
      break;
    }
    sum+=A.at(i);
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 4816
#include<stdio.h>
#include<string.h>
int main()
{
	char s[101];
	int t[101],l[100],i,j,r;
	l['I']=1;
	l['V']=5;
	l['X']=10;
	l['L']=50;
	l['C']=100;
	l['D']=500;
	l['M']=1000;
	for(;gets(s);)
	{
		memset(t,0,sizeof(t));
		t[0]=l[s[0]];
		for(i=1,j=0;s[i];i++)
		{
			if(s[i]==s[i-1])
				t[j]+=l[s[i]];
			else
			{
				if(l[s[i]]>l[s[i-1]])
					t[j]*=-1;
				t[++j]+=l[s[i]];
			}
		}
		for(i=r=0;i<=j;i++)
			r+=t[i];
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int mod=1000000007;

int n,a[100005],p,res[100005],f[100005];

int fpow(int x,int y){
    if(y==0)return 1;
    if(y==1)return x;
    int res=fpow(x,y/2);
    if(y%2==1)return int(((long long)res*res%mod)*x%mod);
    return int((long long)res*res%mod);
}

int inverse(int x){
    return fpow(x,mod-2);
}

int main(){
    memset(f,-1,sizeof f);
    scanf("%d",&n);
    for(int i=0;i<=n;i++){
        scanf("%d",a+i);
        if(f[a[i]]!=-1)p=i;else f[a[i]]=i;
    }
    int len=n+1,curr=1,rev=1;
    int rlen=f[a[p]]+n-p,rcurr=1,rrev=1;
    for(int i=1;i<=n+1;i++){
        curr=int((long long)curr*len%mod);
        curr=int((long long)curr*inverse(rev)%mod);
        len--;rev++;
        printf("%d\n",(curr+mod-rcurr)%mod);
        if(rlen>=0){
            rcurr=int((long long)rcurr*rlen%mod);
            rcurr=int((long long)rcurr*inverse(rrev)%mod);
            rlen--;
            rrev++;
        }
    }
    return 0;
} 

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

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

    int* b = new int[n]();
    for(int i=1;i<=n-1;i++)
    {
        cin>>b[i];
    }
    ll sum =0;
    int* a = new int[n+1]();
    a[1] = b[1];
    for(int i=2;i<=n-1;i++)
    {
        a[i] = min( b[i-1] , b[i] );
        sum += a[i];
    }
    sum += b[1];
    sum += b[n-1];
    cout<<sum;


}

Measured memory_bytes: 3628
import fractions
n=int(input())
a=list(map(int, input().split()))
ans=a[0]
for i in range(1,n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
tmp=0
for j in range(n):
  tmp+=(ans-1)%a[j]
print(tmp)

Measured memory_bytes: 5304
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {
    def main(args: Array[String]): Unit = { 
        digit(readLine().split(" ").map(_.toDouble))
    }   

    @tailrec
    def digit(n: Seq[Double]): Unit = {
       val d: Double = n(1) * n(3) - n(0) * n(4)
       val x: Double = zero((n(1) * n(5) - n(4) * n(2)) / d)
       val y: Double = zero((n(2) * n(3) - n(0) * n(5)) / d)
       println(f"$x%.3f $y%.3f")
       val next: String = readLine()
       if(next == null) Unit else digit(next.split(" ").map(_.toDouble))
    }

    def zero(n: Double): Double = if(Math.abs(n) == 0) 0 else n
}

Measured memory_bytes: 44172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

struct scc {
    using Graph = vector<vector<int>>;
    int N;
    Graph FG, RG;

    scc(int _N)
        : N(_N), FG(_N), RG(_N){}

    // 辺追加
    void add_edge(int u, int v) { FG[u].emplace_back(v), RG[v].emplace_back(u); }
    
    vector<vector<int>> get_scc() {
        int now_ord = 0, group_num = 0;
        vector<int> used(N), ord(N, -1), group(N, -1);

        bool sw = false;
        auto dfs = [&](auto&& dfs, int &v, Graph& G) -> void {
            used[v] = 1;
            for(auto to: G[v]) {
                if(!used[to]) dfs(dfs, to, G);
            }
            if (sw) group[v] = group_num;
            else    ord[now_ord] = v, now_ord++;
        };

        // 1回目dfs
        for (int i = 0; i < N; i++) if (!used[i]) dfs(dfs, i, FG);
        sw = true;
        fill(used.begin(), used.end(), 0);
        // 2回目dfs
        for (auto it = ord.rbegin(); it != ord.rend(); it++)
            if (group[*it] == -1) dfs(dfs, *it, RG), group_num++;

        vector<vector<int>> groups(group_num);
        for (int i = 0; i < N; i++) groups[group[i]].emplace_back(i);

        return groups;
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    scc G(N);

    rep(i, M){
        ll u, v;
        cin >> u >> v;
        G.add_edge(u, v);
    }

    auto ans = G.get_scc();

    cout << ans.size() << endl;
    rep(i, ans.size()){
        cout << ans[i].size();
        for(auto v: ans[i]) cout<<" " <<v;
        cout << '\n';
    }
}

Measured memory_bytes: 79692
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-05 15:00:28
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int c = b - a;
    int d = 0;
    int prev = 0;
    int ans;
    for (int i = 1; i <= 999; i++) {
        d += i;
        if (d == prev + c) {
            ans = d - b;
            break;
        }
        
        prev = d;
    }

    cout << ans << endl;

    return 0;
}


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

int N;
string S;

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

	cin >> N >> S;
	if (N % 2 == 0) {
		for (int i = 0; i < (N / 2); i++) {
			if (S[i] != S[i + (N / 2)]) {
				cout << "No" << "\n";
				return 0;
			}
		}
		cout << "Yes" << "\n";
	}
	else 
		cout << "No" << "\n";
}

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

int main(){
    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(s[i] == '+') ans++;
        if(s[i] == '-') ans--;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
const double EPS = 1e-10;//sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)  cerr << #x << " = " << (x) << endl;//debug
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);


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



Measured memory_bytes: 3872
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def FloorSum(n, m, a, b):
    ans = 0
    if a >= m:
        ans += (n-1)*n*(a//m)//2
        a %= m
    if b >= m:
        ans += n*(b//m)
        b %= m

    y_max = (a*n+b)//m
    x_max = (y_max*m-b)
    if y_max == 0: return ans
    ans += (n-(x_max+a-1)//a)*y_max
    ans += FloorSum(y_max, a, m, (a-x_max%a)%a)
    return ans

for _ in range(II()):
    n,m,a,b=MI()
    print(FloorSum(n,m,a,b))


Measured memory_bytes: 9264
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

def dpp(n):
    for i in range(2,n+1):
        if a[i] == 0:
            dp[i] = 0
        else:
            dp[i] = dp[i-1]+dp[i-2]
    return dp[n]

N,M = I()
a = [1]*(N +1)
for i in range(M):
    x = k()
    a[x] = 0

dp = [0]*(N+1)
if a[1] == 0:
    dp[1] = 0
    dp[0] = 1
else:
    dp[0] = dp[1] =1

print(dpp(N) % mod)


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

using namespace std;

int main(){
	long long n;
	cin>>n;
	vector<long long> A(n);
	vector<long long> B=A;
	vector<long long> C=A;

	for(long long i=0;i<n;i++) cin>>A.at(i);
	for(long long i=0;i<n;i++) cin>>B.at(i);
	for(long long i=0;i<n;i++) cin>>C.at(i);

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());

	vector<long long> AB(n,0);
	vector<long long> BC=AB;
	vector<long long> ruiseki(n+1,0);

	long long ans=0;

	for(long long i=0;i<n;i++){
		long long a=A.at(i);
		auto it=upper_bound(B.begin(),B.end(),a);

		AB.at(i)=distance(it,B.end());
	}

	for(long long i=0;i<n;i++){
		long long a=B.at(i);
		auto it=upper_bound(C.begin(),C.end(),a);

		BC.at(i)=distance(it,C.end());
	}

	reverse(BC.begin(),BC.end());

	for(long long i=1;i<=n;i++){
		ruiseki.at(i)=ruiseki.at(i-1)+BC.at(i-1);
	}

	for(long long i=0;i<n;i++){
		ans+=ruiseki.at(AB.at(i));
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<numeric>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
	int a[4],b[4];
	REP(i,4)cin>>a[i];
	REP(i,4)cin>>b[i];
	cout<<max(accumulate(a,a+4,0), accumulate(b,b+4,0))<<endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          ll i;

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

	          string S;
	          cin >> S;

	          ll n=S.size();
	          ll p=-1LL;
	          for(i=0;i<n;i++){
	        	  if(S[i]=='B'){
	        		  p=i;
	        		  break;
	        	  }
	          }

	          if(p==-1LL){
	        	  cout << 0 << endl;
	        	  return 0;
	          }

	          ll ans=0;
	          for(i=p+1;i<n;i++){
	        	  if(S[i]=='W'){
	        		  ans+=i-p;
	        		  p++;
	        	  }
	          }

	          cout << ans << endl;

	          return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}



int c[1005];
int ans=0;
string s[3]={"Sunny","Cloudy","Rainy"};
string str;
vector<P> v[1005][1005];
int main() {
	bool a=true;
	cin>>str;
	for(int i=0;i<str.size();++i){
		if(i%2==0){
			if(str[i]=='L')a=false;
		}else{
			if(str[i]=='R')a=false;
		}
	}
	if(a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 23936