akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 31556
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323

const int N = 1e5+5;
ll vis[N];
vl g[N];


void dfs(ll s)
{
       vis[s]=1;
       for(ll d:g[s])
       {
              if(!vis[d]) dfs(d);
       }
}


void solve()
{
       ll n;
       cin>>n;
       ll m;
       cin>>m;
       rep(i,1,m+1)
       {
              ll x, y,z;
              cin>>x>>y>>z;
              g[x].pb(y);
              g[y].pb(x);
       }
       ll cc=0;
       for(ll i=1; i<=n; i++)
       {
              if(!vis[i])
              {
                     cc++;
                     dfs(i);
                     }
       }
       cout<<cc<<endl;
}

int main()
{
       speed_up;
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>p;
vector<int>key;
map<int,int>num;
main()
{
  int n,m;
  int a;
  int ans=0;
  
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(num.count(a)==0)
      key.push_back(a);
    num[a]++;
  }

  for(int i=0;i<key.size();i++){
    if(num[key[i]]<key[i])
      ans+=num[key[i]];
    if(num[key[i]]>key[i])
      ans+=num[key[i]]-key[i];
  }
  cout << ans << endl;
  
  return (0);
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int n;

void dfs(string s,char mx){
    if (s.length() == n){
        cout << s.c_str() << endl;
    }else{
        for (char c = 'a' ; c<=mx;c++){
            dfs(s+c,((c == mx)? (char)(mx+1):mx));
        }
    }
}
int main(void){
    // Your code here!
    cin >> n;
    dfs("",'a');
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ans += a[0];
    int cnt = 1;
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (cnt == n - 1)
            {
                cout << ans << endl;
                return 0;
            }
            cnt++;
            ans += a[i];
        }
    }

    return 0;
}


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

int main(){
int N; cin >> N;
vector<long long> L(N+1);
L[0] = 2;
L[1] = 1;
for (int i = 2; i <= N; i++) {
    L[i] = L[i-1] + L[i-2];
}

cout << L[N] << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    multiset <int, greater<int>> st;
    st.insert(a);
    for (int i = 1; i < n; i++) {
        cin >> a;
        auto itr = st.upper_bound(a);
        if (itr != st.end()) st.erase(itr);
        st.insert(a);
    }

    cout << st.size() << "\n";
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

class Dice{
	int pip_top;
	int pip_front;
	int pip_right;
	int pip_left;
	int pip_back;
	int pip_bottom;
}

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		Dice d1= new Dice();

		d1.pip_top=sc.nextInt();
		d1.pip_front=sc.nextInt();
		d1.pip_right=sc.nextInt();
		d1.pip_left=sc.nextInt();
		d1.pip_back=sc.nextInt();
		d1.pip_bottom=sc.nextInt();

		int q=sc.nextInt();

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

			int pip1=sc.nextInt();
			int pip2=sc.nextInt();

			if(pip1==d1.pip_top)
				top_right(d1,pip2);
			else if(pip1==d1.pip_right)
				right_right(d1,pip2);
			else if(pip1==d1.pip_front)
				front_right(d1,pip2);
			else if(pip1==d1.pip_left)
				left_right(d1,pip2);
			else if(pip1==d1.pip_back)
				back_right(d1,pip2);
			else
				bottom_right(d1,pip2);
		}
	}

	private static void top_right(Dice d1,int p2) {
		if(p2==d1.pip_front)
			System.out.println(d1.pip_right);
		else if(p2==d1.pip_right)
			System.out.println(d1.pip_back);
		else if(p2==d1.pip_back)
			System.out.println(d1.pip_left);
		else
			System.out.println(d1.pip_front);
	}

	private static void right_right(Dice d1,int p2) {
		if(p2==d1.pip_front)
			System.out.println(d1.pip_bottom);
		else if(p2==d1.pip_bottom)
			System.out.println(d1.pip_back);
		else if(p2==d1.pip_back)
			System.out.println(d1.pip_top);
		else
			System.out.println(d1.pip_front);
	}

	private static void front_right(Dice d1,int p2) {
		if(p2==d1.pip_left)
			System.out.println(d1.pip_bottom);
		else if(p2==d1.pip_bottom)
			System.out.println(d1.pip_right);
		else if(p2==d1.pip_right)
			System.out.println(d1.pip_top);
		else
			System.out.println(d1.pip_left);
	}

	private static void left_right(Dice d1,int p2) {
		if(p2==d1.pip_front)
			System.out.println(d1.pip_top);
		else if(p2==d1.pip_top)
			System.out.println(d1.pip_back);
		else if(p2==d1.pip_back)
			System.out.println(d1.pip_bottom);
		else
			System.out.println(d1.pip_front);
	}

	private static void back_right(Dice d1,int p2) {
		if(p2==d1.pip_top)
			System.out.println(d1.pip_right);
		else if(p2==d1.pip_right)
			System.out.println(d1.pip_bottom);
		else if(p2==d1.pip_bottom)
			System.out.println(d1.pip_left);
		else
			System.out.println(d1.pip_top);
	}

	private static void bottom_right(Dice d1,int p2) {
		if(p2==d1.pip_front)
			System.out.println(d1.pip_left);
		else if(p2==d1.pip_left)
			System.out.println(d1.pip_back);
		else if(p2==d1.pip_back)
			System.out.println(d1.pip_right);
		else
			System.out.println(d1.pip_front);
	}


}


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

int n;

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	vector<int> A(n);
	int mod = 1000000007;
	long long sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> A[i];
		sum += A[i];
		sum %= mod;
	}

	long ans = 0;

	for(int i = 0; i < n; i++) {
		sum -= A[i];
		if(sum < 0) sum += mod;

		ans += A[i] * sum;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	int n; cin>>n;
	n++;
	vector<int> v(n);
	for(int i=1; i<n; i++) cin>>v[i];
	int cnt=0;
	int pos=1;
	while(cnt<n){
		cnt++;
		if(v[pos]==2) break;
		else pos=v[pos];
	}
	cout<<(cnt<n?cnt:-1)<<endl;
}

Measured memory_bytes: 3780
#include <stdio.h>
#include <string.h>
#define N 2000000
int it = 0, n, tree[N + 1];
void swap(int *x, int *y) {
	int tmp = *x;
	*x = *y;
	*y = tmp;
}
void maxHeap(int u) {
	int left, right, largest;
	left = u * 2;
	right = u * 2 + 1;
	
	if (left <= it && tree[u] < tree[left])
		largest = left;
	else 
		largest = u;
	if (right <= it && tree[largest] < tree[right])
		largest = right;

	if (largest != u) {
		swap(&tree[u], &tree[largest]);
		maxHeap(largest);
	}
}
void insert(int key) {

	tree[++it] = key;
	int parent = it / 2;
	int u = it;
	while (u > 1 && tree[u] > tree[parent]) {
		swap(&tree[u], &tree[parent]);
		u = parent;
		parent = u / 2;

	}
}
int extract(void) {
	int rtn = tree[1];
	tree[1] = tree[it--];
	maxHeap(1);
	return rtn;
}
int main() {
	int in;
	char command[8];

	while (1) {
		scanf("%s", command);
		if (strcmp(command, "end") == 0)
			break;
		if ('e' == command[0])
			printf("%d\n", extract());
		else {
			scanf("%d", &in);
			insert(in);
		}
	}
	return 0;
}

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

long long cnt;
int l;
int A[1000000];
int n;
vector <int> G;

void insertionSort(int A[],int n,int g){
    for (int i=0; i<n; i++){
        int v=A[i];
        int j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}
    
void shellSort(int A[],int n){
    //数列G={1,4,13,40,121,364,1093,...}を生成
    for (int h=1; ; ){
        if (h>n) break;
        G.push_back(h);
        h=3*h+1;
    }
    for (int i=G.size()-1; i>=0; i--){
        insertionSort(A,n,G[i]);
    }
}
    
int main(){
    cin >> n;
    for (int i=0; i<n; i++) scanf("%d",&A[i]);
    cnt=0;
        
    shellSort(A,n);
        
    cout << G.size() << endl;
    for (int i=G.size()-1; i>=0; i--){
        cout << G[i];
        if (i) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
        
    for (int i=0; i<n; i++) printf("%d\n",A[i]); 
    return 0;
}



Measured memory_bytes: 7184
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    //string s;
    //cin >> s;
    int x=tx-sx;
    int y=ty-sy;
    cout << 'D';
    REP(i, x+1) cout << 'R';
    REP(i,y+1) cout << 'U';
    cout << 'L';
    REP(i, y) cout << 'D';
    REP(i,x+1) cout << 'L';
    REP(i,y+1) cout << 'U';
    REP(i, x+1) cout << 'R';
    cout << 'D';
    REP(i, x) cout << 'L';
    REP(i,y) cout << 'D';
    cout << endl;
    //cout << s.size();
}
    




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

typedef pair<int, int> pii;

double dist (pii a, pii b)
{
    return sqrt((double)pow(a.first - b.first, 2) + (double)pow(a.second - b.second, 2));
}

int main()
{
    int N;
    cin >> N;
    vector<pii> xy(N);
    for (int i = 0; i < N; i++) cin >> xy[i].first >> xy[i].second;

    vector<int> v(N);
    for (int i = 0; i < N; i++) v[i] = i;

    double sum = 0;
    int count = 0;
    do {
        for (int i = 0; i < N-1; i++) sum += dist(xy[v[i]], xy[v[i+1]]);
        count++;
    } while (next_permutation(v.begin(), v.end()));

    cout << fixed << setprecision(10) << sum / count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    vector<int> t(N+1, 1);
    FOR(i, 1, N+1){
        int x = i;
        FOR(j, 2, N+1){
            while(x%j == 0){
                t[j]++;
                x /= j;
            }
        }
    }
    llint ans = 1;
    REP(i, N+1){
        // cout << t[i] << "\n";
        ans = (ans * t[i]) % MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sortv(x) sort(x.begin(), x.end())
#define dump(x) cerr << #x << " = " << x << endl
typedef long long ll;

struct UnionFind
{
  vector<int> par;
  UnionFind(int N) : par(N)
  {
    for (int i = 0; i < N; i++)
      par[i] = i;
  }
  int root(int x)
  {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y)
  {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }
  bool same(int x, int y)
  {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
} typedef UF;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++)
  {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
  }
  int ans = 0;
  for (int i = 0; i < M; i++)
  {
    UF uf(N);
    for (int j = 0; j < M; j++)
    {
      if (i != j)
        uf.unite(A[j], B[j]);
    }
    int cnt = 0;
    for (int j = 0; j < N; j++)
    {
      if (uf.par[j] == j)
        cnt++;
    }
    if (cnt > 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll X;
    cin >> X;

    if (X <= 599)
    {
        cout << "8" << endl;
    }
    else if (X <= 799)
    {
        cout << "7" << endl;
    }
    else if (X <= 999)
    {
        cout << "6" << endl;
    }
    else if (X <= 1199)
    {
        cout << "5" << endl;
    }
    else if (X <= 1399)
    {
        cout << "4" << endl;
    }
    else if (X <= 1599)
    {
        cout << "3" << endl;
    }
    else if (X <= 1799)
    {
        cout << "2" << endl;
    }
    else if (X <= 1999)
    {
        cout << "1" << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll factorial[1010000];
ll invfactorial[1010000];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

ll nCrM(ll n, ll r){
	ll ret = factorial[n];
	ret *= invfactorial[n - r];
	ret %= MOD;
	ret *= invfactorial[r];
	ret %= MOD; 
	return ret;
}
int main(void){
    factorial[0] = 1;

    for (int i = 1; i < 1010000; i++){
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    for (int i = 0; i < 1010000; i++){
        ll x, y;
        ll g = extGCD(factorial[i], MOD, x, y);
        while (x < 0) x += MOD;
        x %= MOD;
        invfactorial[i] = x;
    }

    ll x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    ll i = (y - (2 * x)) / (-3);
    ll j = x - (2 * i);
    if(i < 0 || j < 0){
        cout << 0 << endl;
        return 0;
    }

    cout << nCrM(i + j, j) << endl;
} 

Measured memory_bytes: 16128
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, A[200000];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
    }

    intmax_t n = 1;
    for (size_t i = 0; i < N; i++) {
        if (A[i] != n) {
            ans++;
            continue;
        }
        n++;
    }

    if (ans == N)
        ans = -1;
    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + (b/2) << endl;
}


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

#define MAX 200

vector<vector<int>> adj_mat(MAX, vector<int>(MAX, 0));
vector<int> d(MAX, -1); //頂点を訪問したステップを記録
vector<int> f(MAX, -1); //頂点の隣接リストを探索し終えたステップを記録

int n;
int step = 1;

void dfs(int init_node){
    stack<int> s;
    int node = init_node;
    s.push(node);
    d.at(node) = step;

    int next_node = -1;
    while(1){
        step++;

        next_node = -1;
        rep(i, n){
            if(adj_mat.at(node).at(i) == 1 && d.at(i) == -1){
                next_node = i;
                break;
            }
        }

        if(next_node == -1){        //新たなノードがない場合
            s.pop();            //次のノードが存在しないノードをスタックから削除
            if(s.size() == 0){
                f.at(node) = step;
                step++;
                break;
            }
            next_node = s.top();

            f.at(node) = step;   // 新たなノードがないので訪問ずみ
            // cout << "node not found " << node+1 << "    " << next_node+1 << endl;
        }else{                      //新たなノードがある場合
            s.push(next_node);
            d.at(next_node) = step; // 初めて見つけたノードとして記録
            // cout << "node found " << node+1 << " --> " << next_node+1 << endl;
        }
        
        node = next_node;
    }
}

int main(){
    cin >> n;

    // 隣接行列の作成
    rep(i, n){
        int u, k; cin >> u >> k;
        rep(j, k){
            int v; cin >> v;
            adj_mat.at(u-1).at(v-1) = 1;
        }
    }


    rep(i, n){
        if(d.at(i) == -1){
            dfs(i);
        }
    }

    rep(i, n){
        cout << i + 1 << " " << d.at(i) << " " << f.at(i) << endl;
    }


}




Measured memory_bytes: 3288
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) x.begin(),x.end()
#define len(x) (int)(x).size()
//#define endl "\n"
#define m_p make_pair
#define int long long


using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ld,ld> pari;

ld PI = 3.14159265358979323846;


struct Edge{
    int a,c;
};

typedef tree<int, null_type, less<int >,
    rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void volodya22(){
    #ifdef THERE
        freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
    cout << fixed;
}


int n,m;
const int N = 1e6+7;
const int alphabet = 256;
const int INF = 1e18;
const ll MOD = 1e9+7;
const ld eps = 1e-10;
const int L = 30;

int m1 = 137*137*137*137*13;
int m2 = 1e9+9;
//int p = 347;


void input(){
    int a,b;
    cin >> a >> b;
    b += a*3;
    cout << b/2;
}


void solve(){

}

signed main(){
    volodya22();
    input();
    solve();
}


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

#define pb push_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;

using namespace std;
const int MAXN = 1e5 + 5 * 1e2;

ll n, k, a[MAXN];
ll pref[MAXN], dp1[MAXN], dp2[MAXN];

int main(){

cin >> n >> k;
for(int i=1;i<=n;i++){
    cin >> a[i];
    pref[i] += pref[i - 1] + a[i];
    /**/
    dp1[i] += dp1[i - 1];
    if(a[i] > 0){
        dp1[i] += a[i];
    }

}
for(int i=n;i>=1;i--){
    dp2[i] += dp2[i + 1];
    if(a[i] > 0){
        dp2[i] += a[i];
    }
}
ll ans = 0;
for(int i=1;i<=n-k+1;i++){
    ans = max(ans, dp1[i - 1] + dp2[i + k] + max(0ll, pref[i + k - 1] - pref[i - 1]));
}
cout << ans;
return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
	
	int N;
	cin >> N;
	long long ans=1;
	for(int i=1; i<=N; i++){
		(ans*=i)%=1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * Matheus Oliveira
 * 09:31:00 02/05/2020
 * c.cpp
*/

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

#define EPS
#define INF
#define MAXN 100
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) printf("%s: ", #x); for(int i = bg; i < ed; i++) printf("%d%c", x[i], (i == ed-1) ? '\n' : ' ');

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

struct Quad {
	int a, b, c, d;
} qs[MAXN];

int ans[MAXN], n, maxi, m, q;

bool comp(Quad f, Quad s) { 
	if(f.a == s.a) {
		if(f.b == s.b) return f.c < s.c;
		return f.b < s.b;
	}
	return f.a < s.a;
}

void getAns() {
	int ret = 0;
	for(int i = 0; i < q; i++) {
		if( (ans[ qs[i].b ] - ans[ qs[i].a ]) == qs[i].c ) ret += qs[i].d;
	}
	//debugarr(ans, 1, n+1)
	maxi = max(ret, maxi);
}

void go(int idx) {
	if(idx > n) getAns();
	else {
		for(int i = ans[idx-1]; i <= m; i++) {
			ans[idx] = i;
			go(idx+1);
		}
	}
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	
	for(int i = 0; i < q; i++) scanf("%d %d %d %d", &qs[i].a, &qs[i].b, &qs[i].c, &qs[i].d);
	sort(qs, qs+q, comp);
	
	//printf("\n");
	//for(int i = 0; i < q; i++) printf("%d %d %d %d\n", qs[i].a, qs[i].b, qs[i].c, qs[i].d);

	ans[1] = 1;
	for(int i = 1; i <= m; i++) {
		ans[2] = i;
		go(3);
	}

	printf("%d\n", maxi);
	return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int A, B, C;
    cin >> A >> B >> C;
    
    if (C >= A && C <= B) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;


int main(){
  int K,N;
  cin >> N >> K;
  int pattern = K;

  for(int i = 1; i<N; i++){
    pattern *= K-1;
  }

  cout << pattern <<endl;
   return 0;
}


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

int MAX_N=262144;
vector<int64_t> seg(MAX_N*2-1);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return MAX_N;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return min(X,Y);
  }
}


int main() {
  int64_t N,Z=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int64_t a;
    cin>>a;
    seg[MAX_N+i]=a;
  }
  for(int i=MAX_N-2;i>=0;i--){
    seg[i]=min(seg[2*i+1],seg[2*i+2]);
  }
  for(int64_t i=0;i<N;i++){
    int64_t a=seg[i+MAX_N];
    int64_t L=0,R=i+1;
    while(R-L>1){
      int64_t D=(L+R)/2;
      int64_t C=qu(D,i+2,0,0,MAX_N);
      if(C==seg[i+MAX_N]){
        R=D;
      }
      else{
        L=D;
      }
    }
    a*=(i+1-L);
    L=i+2,R=MAX_N;
    while(R-L>1){
      int64_t D=(L+R)/2;
      int64_t C=qu(i+1,D,0,0,MAX_N);
      if(C==seg[i+MAX_N]){
        L=D;
      }
      else{
        R=D;
      }
    }
    a*=(R-i-2);
    Z+=a;
  }
  cout<<Z<<endl;
}



Measured memory_bytes: 7344
fun main(args: Array<String>) {
    apc001c()
}

private enum class Seat(private val value: String) {
    VACANT("Vacant"), MALE("Male"), FEMALE("Female");

    override fun toString(): String {
        return this.value
    }
}

private fun query(i: Int): Seat {
    println(i)
    return Seat.valueOf(readLine()!!.toUpperCase())
}

fun apc001c() {
    val n = readLine()!!.toInt()

    var leftIndex = 0
    var left = query(leftIndex)
    if (left == Seat.VACANT) return

    var rightIndex = n - 1
    val right = query(rightIndex)
    if (right == Seat.VACANT) return

    while (true) {
        val midIndex = (leftIndex + rightIndex) / 2
        val mid = query(midIndex)
        when (mid) {
            Seat.VACANT -> return
            else -> {
                val indexDiff = midIndex - leftIndex
                if ((mid != left && indexDiff % 2 == 0) || (mid==left && indexDiff%2==1)) {
                    rightIndex = midIndex
                } else {
                    leftIndex = midIndex
                    left = mid
                }
            }
        }
    }
}


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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int max_n = 100000, inf = 1000111222;


int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cout << (-3 % 2) << endl;

    ll a, b;
    cin >> a >> b;
    ll d = (b - a);
    if (d % 2 == 0) {
        cout << a + d / 2;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}



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

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;}
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  string x;
  cin >> x;
  int cnt=0,s=0,t=0;
  FOR(i,x.size()){
    if(x[i]=='S'){
      s++;
    }else{
      if(s==0){
        cnt+=2;
      }else s--;
    }
  }

  cout << cnt << endl;
  
  
}


Measured memory_bytes: 640
Sa = input()
Sb = input()
Sc = input()
l = [len(Sa), len(Sb), len(Sc)]
s = [Sa, Sb, Sc]
p = 0
while True:
    if l[p] <= 0:
        print("ABC"[p])
        break
    else:
        l[p] -= 1
        p = "abc".find(s[p][len(s[p])-l[p]-1])

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

long long cnt(long long a, long long b){
  return abs(a-1)+abs(b-1);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  long long n; cin >> n; long long ans= cnt(n,1);
  for(long long i=2;i*i<=n;i++){
    if(n%i == 0) ans = min(ans, cnt(i, n/i));
  }
  cout << ans << "\n";
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF = (1LL<<60)-1;
const int maxN = 1000001;
int32_t main()
{
    SPEED;
    int n,x;
    cin>>n>>x;
    int arr[n];
   
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
    }
      int sum=0;
    sort(arr,arr+n);

    for(int i=0;i<n;i++)
    {
     if(x>=arr[i])
     {
       x-=arr[i];
       sum++;
     }
     else 
     {
     	break;
     }
    }

    if(sum==n and x>0)
    {
    	sum--;
    }

    cout<<sum<<endl; 
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int cnt=0;
  cin>>s;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='x')
    {
      cnt++;
    }
  }
  if(cnt>7)
  {
    cout<<"NO";
  }
  else
  {
    cout<<"YES";
  }
  return 0;
}

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

int main() {
    ll N, X, T;

    cin >> N >> X >> T;

    ll ans = 0;

    if (N%X == 0) {
        ans = (N/X) * T;
    } else {
        ans = (N/X + 1) * T;
    }
    


    


    

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

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

int main(void)
{   
    char i,t;
    char facetab[7]={0};
    char dice[102]={0};
    char *ptr;
    
    for(i=0;i<6;i++)
        scanf("%d",&facetab[i]);
    
    scanf("%s",ptr=dice);
    
    for(i=0;i < strlen(dice);i++)
    {
        switch(*ptr++)
        {
        case 'E':
            t = facetab[0];
            facetab[0] = facetab[3];
            facetab[3] = facetab[5];
            facetab[5] = facetab[2];
            facetab[2] = t;
            break;
            
        case 'N':
            t = facetab[0];
            facetab[0] = facetab[1];
            facetab[1] = facetab[5];
            facetab[5] = facetab[4];
            facetab[4] = t;
            break;    
            
        case 'S':
            t = facetab[0];
            facetab[0] = facetab[4];
            facetab[4] = facetab[5];
            facetab[5] = facetab[1];
            facetab[1] = t;
            break;  
            
        case 'W':
            t = facetab[0];
            facetab[0] = facetab[2];
            facetab[2] = facetab[5];
            facetab[5] = facetab[3];
            facetab[3] = t;
            break;      
            
        }
    }
    printf("%d\n",facetab[0]);
    return 0;
}


Measured memory_bytes: 2128
x1, y1, x2, y2 = [int(w) for w in input().split()]
b = x2 - x1
a = y2 - y1

x3 = x2-a
y3 = y2+b

x4 = x3-b
y4 = y3 - a

print(x3, y3, x4, y4)



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


int main() 
{ 
    ios_base::sync_with_stdio(0) ;
    cin.tie(0); cout.tie(0) ;
    
    long long n ;
    cin >> n ;
    cout << n*(n-1)/2;
    return 0; 
}  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}

// O(n * W)

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<ll> dp(W + 1); // 0 ... W
    // dp[i] - the maximum total value of items with total weight exactly i
    for(int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);
        // dp[0] -> dp[3] -> dp[6]
        for(int weight_already = W - weight; weight_already >= 0; --weight_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            max_self(dp[weight_already+weight], dp[weight_already] + value);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= W; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", dp[W]);
}

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

void bubbleSort(string* A, int n){
	bool flag = true;
	while(flag){
		flag = false;
		for(int j=n-1; j>0; j--)
			if(A[j-1][1] > A[j][1]){
				swap(A[j-1], A[j]);
				flag = true;
			}
	}
}
void selectionSort(string* A, int n){
	for(int i=0; i<n; i++){
		int minj = i;
		for(int j=i; j<n; j++)
			if(A[j][1] < A[minj][1]) minj = j;
		if(i != minj) swap( A[i], A[minj] );
	}
}
int main(){
	int n;
	cin >> n;
	
	string A[100], B[100];
	for(int i=0; i<n; i++){
		cin >> A[i];
		B[i] = A[i];
	}
	
	bubbleSort(A, n);
	selectionSort(B, n);
	
	
	cout << A[0];
	for(int i=1; i<n; i++) cout << " " << A[i];
	cout << "\nStable\n";
	
	cout << B[0];
	for(int i=1; i<n; i++) cout << " " << B[i];
	for(int i=0; i<n; i++){
		if(A[i] != B[i]){
			cout << "\nNot stable" << endl;
			return 0;
		}
	}
	cout << "\nStable" << endl;
	return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

static const int MAX=10000;
static const int INFTY=(1<<20);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n;

vector<pair<int,int> >adj[MAX];

void dijkstra()
{
  priority_queue<pair<int,int> >PQ;
  
  int color[MAX];
  int d[MAX];
  
  for(int i=0; i<n; i++)
    {
      d[i]=INFTY;
      color[i]=WHITE;
    }

  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0] = GRAY;

  while(!PQ.empty())
    {
      pair<int,int>f=PQ.top();PQ.pop();
    
      int u = f.second;

      color[u] = BLACK;

      if(d[u]<f.first*(-1))
	{
	  continue;
	}

      for(int j=0;j<adj[u].size();j++)
	{
	  int v=adj[u][j].first;
      
	  if(color[v]==BLACK)
	    {
	      continue;
	    }
      
	  if(d[v]>d[u]+adj[u][j].second)
	    {
	      d[v]=d[u]+adj[u][j].second;
        
	      PQ.push(make_pair(d[v]*(-1),v));
	
	      color[v] = GRAY;
	    }
	}
    }

  for(int i=0;i<n;i++)
    {
      cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}

int main(void)
{
  int k, u, v, c;

  cin>>n;
  
  for(int i=0;i<n;i++)
    {
      cin>>u>>k;
    
      for(int j=0;j<k;j++)
	{
	  cin>>v>>c;
      
	  adj[u].push_back(make_pair(v, c));
	}
    }

  dijkstra();

  return 0;
}



Measured memory_bytes: 8016
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

struct edge
{
    int to;
    int cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector< vector < edge > > Graph;

void dfs(Graph &G, int st, vector<int> &x){
    x[st] = 0;

    stack<int> S;
    int N = G.size();
    static vector<vector<edge>::iterator> itr(N);
    if(st == 0) REP(i, N){ itr[i] = G[i].begin(); }
    static vector<int> done(N, 0);
    S.push(st);
    while(!S.empty()){
        int u = S.top();
        if(itr[u] == G[u].end()){
            S.pop();
            done[u] = 2;
        }else{
            edge v = *itr[u]++;
            if(!done[v.to]){
                done[v.to] = 1;
                S.push(v.to);
                x[v.to] = x[u] + v.cost;
            }
        }
    }
}


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

    int N, M;
    cin >> N >> M;

    Graph G(N);
    REP(i, M){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        G[l].pb(edge(r, d));
        G[r].pb(edge(l, -d));
    }
    vector<int> x(N, INF);
    REP(i, N){
        if(x[i] == INF) dfs(G, i, x);
    }
    REP(l, N){
        // cout << x[l] << "\n";
        for(auto e : G[l]){
            if(x[e.to] - x[l] != e.cost){
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");

    return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod


int n, m;
vector<vector<int>> g(100000 + 6);

int ord[100000 + 6], low[100000 + 6];
bool visited[100000 + 6];

vector<pair<int, int>> Bridges;
vector<int> Points;

void dfs(int now, int par, int &cnt) {
    visited[now] = true;
    ord[now] = cnt++;
    low[now] = ord[now];
    bool check = false;
    int outdeg = 0;
    for (auto nx : g[now]) {
        if (nx == par) continue;
        if (!visited[nx]) {
            outdeg++;
            dfs(nx, now, cnt);
            low[now] = min(low[now], low[nx]);
            //???????????????
            if (ord[now] < low[nx]) {
                Bridges.push_back({min(now, nx), max(now, nx)});
            }
            //??¢??????????????????
            if (par != -1 && !check && ord[now] <= low[nx]) {
                check = true;
                Points.push_back(now);
            }
        }
        else {
            low[now] = min(low[now], ord[nx]);
        }
    }
    //???????????????????????\?????¢????????¨???????????????
    if (par == -1 && outdeg >= 2) {
        Points.push_back(now);
    }
    return;
}

void lowlink (int n, vector<vector<int>>& g) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            dfs(i, -1, cnt);
        }
    }
    sort(all(Bridges));
    sort(all(Points));
    return;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    lowlink(n, g);
    /*
    rep(i, Bridges.size()) {
        cout << Bridges[i].fi << " " << Bridges[i].se << endl;
    }
    */
    rep(i, Points.size()) {
        cout << Points[i] << endl;
    }
}

Measured memory_bytes: 6920
import java.util.*;
public class Main{
    public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int m=Math.max(a,b);
    int n=Math.min(a,b);
    int min=Math.min(n,c);
    int max=Math.max(m,c);
    int mid=0;
    String p="null";
    if (a==b|| a==c){
    mid =a;
    }else {
        if(b==c){
        mid =b;
        }else{
            if(a!=max && a!=min){
            mid =a;
            }else {
                if (b!=max && b!=min){
                mid=b;
                }else {
                mid =c;
                }
            }
        }
    }
    p=Integer.toString(max)+Integer.toString(mid);
    int result = Integer.parseInt(p); 
    System.out.println(result+min);
    }
}

Measured memory_bytes: 25300
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, vector<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int x, y;
  cin >> x >> y;

  int ans = 0;
  if (x == 1) ans += 300000;
  if (x == 2) ans += 200000;
  if (x == 3) ans += 100000;
  if (y == 1) ans += 300000;
  if (y == 2) ans += 200000;
  if (y == 3) ans += 100000;
  if (x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
class Main {
 public static void main(String[] args){
  Scanner s = new Scanner(System.in);
  ArrayList<Integer> ary = new ArrayList<Integer>();
  int count = 0;
  while(true){
   ary.add(s.nextInt());
   if(ary.get(count) == 0) break;
   count++;
  }
  for(int i = 0; i < ary.size(); i++){
   if(ary.get(i) != 0) System.out.println("Case " + (i + 1) + ": " + ary.get(i));
  }
 }
}

Measured memory_bytes: 39908