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

bool ok(int a, int b, int c, int d){
    if(a==0 && b==2 && c==1) return false;
    if(a==2 && b==0 && c==1) return false;
    if(a==0 && b==1 && c==2) return false;
    if(b==0 && c==2 && d==1) return false;
    if(b==2 && c==0 && d==1) return false;
    if(b==0 && c==1 && d==2) return false;
    if(a==0 && c==2 && d==1) return false;
    if(a==0 && b==2 && d==1) return false;
    return true;
}

int main(){
    int M = pow(10,9)+7;
    int N; cin >> N;
    int dp[110][4][4][4];

    for(int n=3; n<110; n++){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                for(int k=0; k<4; k++){
                    dp[n][i][j][k]=0;
                }
            }
        }
    }


    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                if(ok(i,j,k,3)){
                    dp[3][i][j][k] =1;
                }
            }
        }
    }

    for(int n=3; n<100; n++){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                for(int k=0; k<4; k++){
                    for(int l=0; l<4;l++){
                        if( ok(l,i,j,k))
                        dp[n+1][i][j][k] +=dp[n][l][i][j];
                        dp[n+1][i][j][k] =dp[n+1][i][j][k]%M;
                    }
                }
            }
        }
    }

    int ans =0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans +=dp[N][i][j][k];
                ans = ans %M;
            }
        }
    }

    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[4];
int main()
{
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+3+1);
	if(a[2]-a[1]==a[3]-a[2])
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

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

int main(){
  
  string s;
  cin >> s;
  int maxs=753;
  for(int i=0; i<s.size()-2; i++){
  	maxs=min(abs(753-(100*(s[i]-48)+10*(s[i+1]-48)+(s[i+2]-48))),maxs);
  }
  
  
	cout << maxs << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary   
int main()
{
      fast;ll t;t=1;
      while(t--)
      {
            string s;
            cin>>s;
            if((int)s[0]>=97 && (int)s[0]<=122){cout<<"a\n";}
            else{cout<<"A\n";}
      }
}

Measured memory_bytes: 3568
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

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

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll n, k;
    cin>>n>>k;
    vector<ll> v(n);
    for(ll i=0; i<n; i++){
        cin>>v[i];
    }
    vector<ll> dp(k+1);
    dp[0]=0;
    for(ll i=1; i<=k; i++){
        for(ll j: v){
            if(j<=i){
                if(dp[i-j]==0){
                    dp[i]=1;
                    break;
                }
            }
        }
    }
    if(dp[k]){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }
    return 0;
}






Measured memory_bytes: 4012
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();
	int P[] = new int[N];
	for (int i = 0; i < N; i++)
	    P[i] = sc.nextInt();

	int count = 1;
	int min = P[0];
	for (int i = 1; i < N; i++) {
	    if (P[i] < min) {
		min = P[i];
		count++;
	    }
	}

	System.out.println(count);
    }
}

Measured memory_bytes: 64824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int a, b, c, d;

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

    void run() {
        FastReader sc = new FastReader();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        solve();
    }

    void solve() {
        if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22228
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll k,q; cin>>k>>q;
    vector<ll> d(k,0),td(k,0),sum(k+1,0);
    rep(i,k) cin>>d[i];
    rep(i,q){
        ll n,x,m,cnt=0; cin>>n>>x>>m;
        rep(i,k){
            td[i]=d[i]%m;
            sum[i+1]=td[i]+sum[i];
            if(td[i]==0) cnt+=(n-1+k-1-i)/k;
        }
        x%=m;
        ll s=x+(n-1)/k*sum[k]+sum[(n-1)%k];
        cout<<n-1-cnt-(s/m)<<endl;
    }
}


Measured memory_bytes: 384
s = gets
i = 0

while i<s.size
    if (i+1).odd? && s[i]=="L"
        puts "No"
        break
    elsif (i+1).even? && s[i]=="R"
        puts "No"
        break
    end
    i += 1
end

puts "Yes" if i==s.size

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

int main() {
	char t[14];
	scanf("%s", t);
	for(int i=13; i>4; i--){
		t[i] = t[i-1];
	}
	t[4] = 32;
	printf("%s\n", t);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mod 1000003
#define MAX_N 1000005
long long inv[MAX_N];

void GetInv(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}

long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main(){
    GetInv();
    int q; cin >> q;
    vector<long long> fact(1000005, 1);
    for (long long i = 0; i < 1000003; i++) {
        fact[i+1] = fact[i] * (i+1) % mod;
    }
    while (q--) {
        long long x, d, n; cin >> x >> d >> n;
        
        if (d == 0) cout << modpow(x, n) << endl;
        else {
            long long t = inv[d] * x % mod;
            if (t + n - 1 >= 1000003) cout << 0 << endl;
            else {
                long long c = fact[t+n-1] * inv[fact[t-1]] % mod;
                c = c * modpow(d, n) % mod;
                cout << c << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 16512
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
const ll INF = 1e18;

int main() {
  int N,W,i,j;
  cin>>N>>W;
  vector<int> w(N+1),v(N+1);
  for (i=1;i<=N;i++) {
    cin>>w[i]>>v[i];
  }
  vector<vector<ll> > dp(N+1, vector<ll>(1e5+1, INF));
  dp[0][0]=0;
  for (i=1;i<=N;i++) {
    for (j=0;j<=1e5;j++) {
      if (j<v[i]) {
        dp[i][j] = dp[i-1][j];
      } else {
        dp[i][j] = min(dp[i-1][j-v[i]] + w[i], dp[i-1][j]);
      }
    }
  }
  int ans = 1e5;
  while(dp[N][ans] > W) ans--;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 82764
#include<stdio.h>
int main(void){
int N, ch=0;
int A[110];
scanf("%d", &N);
for(int i=0;i<N;i++){
scanf("%d", &A[i]);
if(A[i]%2==1 || A[i]%6==0 || A[i]%10==0){
ch+=1;
}
}
if(ch==N){
printf("APPROVED");
}else{
printf("DENIED");
}
return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> res(4 * 3 * 10, 0);
  for (int i = 0; i < n; i++) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    b--, f--, r--;
    res.at(b * 3 * 10 + f * 10 + r) += v;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        if (k < 9)
          cout << " " << res.at(i * 30 + j * 10 + k);
        else
          cout << " " << res.at(i * 30 + j * 10 + k) << endl;
      }
    }
    if (i == 3) break;
    cout << "####################" << endl;
  }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	int mod = 1e9+7;
	char grid[h][w];
	for(int i =0;i<h;i++)
		for(int j =0;j<w;j++)
			cin>>grid[i][j];
	int dp[h][w]={};
	for(int i =0;i<w;i++)
		if(grid[0][i]!='#')
			dp[0][i]=1;
		else
			break;
	for(int i =0;i<h;i++)
		if(grid[i][0]!='#')
			dp[i][0]=1;
		else
			break;
	for(int i =1;i<h;i++)
	{
		for(int j =1;j<w;j++)
		{
			if(grid[i][j-1]!='#')
				dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
			if(grid[i-1][j]!='#')
				dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
				
		}
	}
	cout<<dp[h-1][w-1]<<'\n';
}


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

bool f(int x){
    int digit = 0;
    while(x){
        digit++;
        x /= 10;
    }
    return digit % 2 == 1;
}

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

    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(f(i)) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
n=int(input())
a=[0]
a+=list(map(int,input().split()))
a+=[0]

arr=np.array(a)

dif=np.diff(arr)
difsum=np.sum(np.abs(dif))
for i in range(1,n+1):
    offset=abs(dif[i]+dif[i-1])-abs(dif[i])-abs(dif[i-1])
    print(difsum+offset)

   


Measured memory_bytes: 22916
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      if (n == 1) {
        System.out.println(0);
        return;
      }

      int[] h = new int[n];
      for (int i = 0; i < n; i++) h[i] = scanner.nextInt();

      int cnt = 0;
      int ans = 0;
      for (int i = 0; i < n - 1; i++) {
        if (h[i] >= h[i+1]) {
          cnt++;
          if (ans < cnt) ans = cnt;
        } else {
          cnt = 0;
        }
      }
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
}

Measured memory_bytes: 48536
#include<bits/stdc++.h>
using namespace std;
long long a[100005];
int main()
{
    int n;
    long long num=1;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(a[0]==0){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        num*=a[i];
        if(1000000000000000000/num<a[i+1]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<num<<endl;
}


Measured memory_bytes: 4412
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
ll fastpower(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y&1)
        res*=x;

        y>>=1;
        x=x*x;
    }
    return res;
}

void swap(ll &a,ll &b)
{
    a ^= b; 
    b ^= a; 
    a ^= b;
}
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    float h,a;
    cin>>h>>a;
    int x=ceil(h/a);
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
ll mo=1000000007;
int main() 
{ 
	ll t1=1;
	//cin>>t1;
	while(t1)
	{
		ll a,b;
		cin>>a>>b;
		cout<<a*b<<endl;
		t1--;
    }
    return 0; 
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	while(true){
		int m, nmin, nmax;
		cin >> m >> nmin >> nmax;
		if(m == 0 && nmin == 0 && nmax == 0)break;
		vector<int> P(m);
		for(int i = 0; i < m; i ++)cin >> P[i];
		int ans = nmin, gap = 0;
		for(int i = nmin; i <= nmax; i ++){
			if(gap <= P[i - 1] - P[i]){
				gap = P[i - 1] - P[i];
				ans = i;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3108
X[2001];i,p,g;main(N){for(;scanf("%d",&N)*N;printf("%d\n",g)){for(g=i=0;i<=N+*X;p=1)scanf("%d",X+i++);for(i=0;i++<*X;g=g|p<N?g:i)p+=X[N+i],p+=p<N?X[p]:0;}}

Measured memory_bytes: 0
#include <iostream>

int main() {
	long long int a, b;
	while( std::cin >> a >> b ) {
		long long int m = ( a >= b ) ? a : b, n = ( a >= b ) ? b : a;
		while( n != 0 ) {
			long long int r = m % n;
			m=n; n=r;
		}
		std::cout << m << " ";
		long long int l = a * b / m;
		std::cout << l << std::endl;
	}
}

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

char s[20];

int f(int x)
{
	int res = 0;
	for (int i = 0; i < 3; ++i) res = res * 10 + s[i + x] - '0';
	return res;
}

int main()
{
	while (scanf("%s", s + 1) != EOF)
	{
		int res = 0x3f3f3f3f, len = strlen(s + 1);
		for (int i = 1; i <= len - 2; ++i) res = min(res, abs(f(i) - 753));
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    // 一行読み込み、空白で分解してusize２つパースする
    // let (n, q) = get!(usize, usize);
    // usize usize u64 をq行読む Vec<(usize, usize,u64)>
    // let lrt = get!(usize, usize, u64; q);
    // A 問題
    // let a = get!(usize);
    // println!("{}",a.pow(3));
    
    // B 問題
    // let n = get!(usize);
    // let a = get!(usize);
    // let b = get!(usize);
    // let c = get!(usize);

    // let _n = 3;
    // let a = vec!(3,1,2);
    // let b = vec!(2, 5, 4);
    // let c = vec!(3,6);
    input!{
        n: usize,
        a: [usize; n],
        b: [usize; n],
        c: [usize; n-1],
    }

    let mut satisfied = 0;
    let mut previous_i = 50;
    for i in a {
        satisfied += b[i-1];
        if i == previous_i + 1 {
            satisfied += c[previous_i-1];
        }
        previous_i = i;
    }
    println!("{}", satisfied);
}


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

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a <= k) {
    cout << "Yay!";
  } else {
    cout << ":(";
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    A,B,C = map(int, lines.pop(0).split(' '))
    res = B // A
    if res > C:
        print(C)
    else:
        print(res)

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3060
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    }
    else if (r < 2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

vector<int> g[N];
bool us[N];

ll dp[N][2];

void dfs(int v, int p = -1) {
	dp[v][0] = 1;
	dp[v][1] = 1;

	for (int i = 0; i < g[v].size(); i++) {
		int to = g[v][i];
		if (to != p) {
			dfs(to, v);
			dp[v][0] *= dp[to][1] % mod;
	 		dp[v][1] *= (dp[to][0] + dp[to][1]) % mod;

	 		dp[v][0] %= mod;
	 		dp[v][1] %= mod;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n;
	cin >> n;

	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	dfs(1);
	cout << (dp[1][0] + dp[1][1]) % mod;
}

Measured memory_bytes: 14592
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

###########

s=slist()
n=len(s)
if s[n-2]==s[n-1]:
    print n-1,n
else:
    for i in range(n-2):
    
        if s[i]==s[i+1]:
            print i+1,i+2
            break
        elif s[i]==s[i+2]:
            print i+1,i+3
            break
    else:
        print -1,-1


Measured memory_bytes: 6780
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>

int main() {
	int n, k, r, s, p;
	std::string t;
	std::cin >> n >> k >> r >> s >> p >> t;

	std::vector<std::array<int, 3>> dp(n, std::array<int, 3>{});

	for (int i = 0; i < k; ++i) {
		dp[i][0] = (t[i] == 's') * r;
		dp[i][1] = (t[i] == 'p') * s;
		dp[i][2] = (t[i] == 'r') * p;
	}
	for (int i = 0; i < k; ++i) {
		for (int j = i + k; j < n; j += k) {
			dp[j][0] = (t[j] == 's') * r + std::max(dp[j - k][1], dp[j - k][2]);
			dp[j][1] = (t[j] == 'p') * s + std::max(dp[j - k][0], dp[j - k][2]);
			dp[j][2] = (t[j] == 'r') * p + std::max(dp[j - k][0], dp[j - k][1]);
		}
	}

	int ans = 0;
	for (int i = 0; i < k; ++i) {
		auto&& arr = *(dp.rbegin() + i);

		ans += *std::max_element(arr.begin(), arr.end());
	}

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


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

ll comb(ll n){
    return n*(n-1)/2;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    UnionFind U(n);
    ll cur=comb(n);
    vector<ll>res;
    rep(i,m){
        res.push_back(cur);
        int c=a[m-1-i];
        int d=b[m-1-i];
        if(U.issame(c,d))continue;  
        ll sa=U.size(c);
        ll sb=U.size(d);          
        cur-=U.size(c)*U.size(d);
        U.merge(c,d);    
    }
    reverse(res.begin(),res.end());
    rep(i,m){
        cout<<res[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define INF 100000000
int main(){
    ll A,B,T;
    cin>>A>>B>>T;
    ll x=T/A;
    cout<<B*x;    
}

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



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	int K;
	string S;
	
	cin >> K >> S;

	if(S.size() > K){
		for(int i=0;i<K;++i){
			cout <<S[i];
		}
		cout <<"...\n";


	}else{
		cout << S<< "\n";
	}



	

	
	


	
	return 0;
}

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

template <int MOD_>  struct modnum {
private:
	using lint = long long;
	lint v;
	static int modinv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - lint(modinv(m, a)) * lint(m) / a);
	}
public:
	static constexpr int MOD = MOD_;
	modnum() : v(0) {}
	modnum(lint v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream &operator<<(std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream &operator>>(std::istream& in, modnum& n) { lint v_; in >> v_; n = modnum(v_); return in; }
	friend bool operator==(const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator!=(const modnum& a, const modnum& b) { return a.v != b.v; }
	modnum inv() const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	modnum operator-() const { return neg(); }
	modnum operator+() const { return modnum(*this); }
	modnum& operator+=(const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator-=(const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator*=(const modnum& o) {
		v = int(lint(v) * lint(o.v) % MOD);
		return *this;
	}
	modnum& operator/=(const modnum& o) { return *this *= o.inv(); }
	friend modnum operator+(const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator-(const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator*(const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator/(const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
template <typename T> T pow(T a, int b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}
using num = modnum<int(1e9)+7>;

int main() {
    cout.tie(nullptr)->sync_with_stdio(false);
    int S; cin >> S;
    vector<num> dp(S+1);
    dp[0] = 1; // there is only one way to form zero
    for (int a = 3; a <= S; ++a) {
        // consider take every posible value in [3, S] to sum S
        for (int b = a; b >= 3; --b) {
            // now we just get each possible contribution to sum S
            dp[a] += dp[b - 3];
        }
    }
    cout << dp[S] << '\n';
}


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

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

   s[5] = ' ';
   s[13] = ' ';

   cout << s << endl;
}

Measured memory_bytes: 764
N, M = map(int, input().split())


K = [[0]*N for i in range(M)]


for i in range(M):
    tmp = list(map(int, input().split()))
    for j in tmp[1:]:
        K[i][j-1] = 1
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    tmp = [0]*M
    for j in range(N):
        if (i >> j) % 2 == 1:
            for k in range(M):
                tmp[k] += K[k][j]
    for j in range(M):
        if tmp[j] % 2 != p[j]:
            break
    else:
        ans += 1


print(ans)


Measured memory_bytes: 3064
A=list(map(str,input().split()))
#print(A)
max_length=0
maximum_number_of_letters=""
max_cnt=0
frequent_word=""
for i in A:
	if len(i)>max_length:
		maximum_number_of_letters=i	
		max_length=len(i)
	if A.count(i)>max_cnt:
		frequent_word=i
		max_cnt=A.count(i)
print(frequent_word,maximum_number_of_letters)

Measured memory_bytes: 7428
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int a = sc.nextInt();

        System.out.println(a < 1200 ? "ABC" : "ARC");
    }
}

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

signed main(){
	string s;cin>>s;
	for(int i=0;i<3;i++)cout<<(s[i]=='1'? '9':(s[i]=='9'? '1':s[i]));
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int a, b, x;

	cin >> a >> b >> x;

	if( x - a <= b && a <= x ) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)
#define print(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char* name, Arg1&& arg1){
    cout << name << ": " << arg1 << '\n';
}

template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

int32_t main(){
    
    fast;
    string a,b,c; cin >> a >> b >> c;
    reverse(all(a));
    reverse(all(b));
    reverse(all(c));

    int turn[]={1,2,3};
    int move = 1;

    while(true){
        
        if(move==1){
            if(a.size()){
                move = turn[a[a.size()-1]-'a'];
                a.pop_back();
            }else{
                cout << "A";
                break;
            }
        }
        
        if(move==2){
            if(b.size()){
                move = turn[b[b.size()-1]-'a'];
                b.pop_back();
            }else{
                cout << "B";
                break;
            }
        }
        
        if(move==3){
            if(c.size()){
                move = turn[c[c.size()-1]-'a'];
                c.pop_back();
            }else{
                cout << "C";
                break;
            }
        }
    }

    
 
 
    return 0;
} 

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		
		LinkedList<Integer> S = new LinkedList<Integer>(); 
		
		int[] dist = new int[totalVertex]; 
		
		dist[s] = 0; 
		for(int i = 1; i < dist.length; i++) {
			dist[i] = Integer.MAX_VALUE; 
		}
		
		while(S.size() < totalVertex) {
			
			int closest = getUnsettledNearest(dist);
			ifSettled[closest] = true;
			S.add(closest);
			
			LinkedList<Integer> neighbors = getUnsettledNeighbors(closest);
			
			for(int x = 0; x < neighbors.size(); x++) {
				int xVertex = neighbors.get(x);
				
				dist[xVertex] = Math.min(dist[closest]+getWeight(closest, xVertex), dist[xVertex]);
				
			}
			
			
		}
		return dist; 
	}
}

public class Main{
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


Measured memory_bytes: 39940
n = int(input())
w = []
Flag = True 
for i in range(n):
  w.append(input())
for i in range(n-1):
  if w[i][-1] != w[i+1][0]:
    Flag = False
if len(w) != len(set(w)):
  Flag = False
print("Yes" if Flag else "No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int i, j;
	int n;
	vector<int>list;


	cin >> n;

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

		list.push_back(num);
	}

	sort(list.begin(), list.end(), greater<int>());

	int num2 = list[0];

	int sum = (num2/2);

	for (i = 1; i < n; i++) {
		sum += list[i];
	}


	cout << sum << endl;










	getchar();
	getchar();
	return 0;
}

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

using namespace std;

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

  int kakutei = 0;
  int kaigai = 0;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] == 'c') {
      cout << "No" << endl;
    }
    else if(s[i] == 'a') {
      if(kakutei < a + b) {
	cout << "Yes" << endl;
	kakutei++;
      }
      else {
	cout << "No" << endl;
      }
    }
    else {
      if(kakutei < a + b && kaigai < b) {
	cout << "Yes" << endl;
	kakutei++;
	kaigai++;
      }
      else {
	cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

void solve(){

    string s; cin>>s;

    ll len = 0;ll ans = 0;
    for(char c:s){
        if(c == 'A' || c == 'C'||c == 'G' || c == 'T'){
            len++;
            ans = max(ans,len);
        }else {
            len = 0;
        }
    }

    cout<<ans<<endl;
}

signed main(){


    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    FOR(tt,1,t){
        solve();
    }
    
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans=0
ans+=b[a[0]-1]
for i in range(1,n):
    ans+=b[a[i]-1]
    if a[i]==a[i-1]+1:
        ans+=c[a[i]-2]
print(ans)


Measured memory_bytes: 3064
N,M = map(int, input().split())
 
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

cnt = 0

for i in range(2 ** N):
    flag = True
    for j in range(M):
        if not([(i >> k-1) & 1  for k in s[j]].count(1) % 2 == p[j]):
            flag = False
    if flag:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef vector<vi> vii;
const int mxN=3e3+5,M=1e9+7;
//did u check when n=1?
//is mxN correct?
int n;
char sig[mxN];
int dp[mxN][mxN];
int mod(int a){int ret=a%M;if(ret<0)ret+=M;return ret;};
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<n;i++)cin>>sig[i];
    dp[1][1]=1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=i;j++){
            /*for(int k=1;k<=i-1;k++){
                if(sig[i-1]=='<'){
                    if(j>k)dp[i][j]+=dp[i-1][k];
                }
                else{
                    if(j<=k)dp[i][j]+=dp[i-1][k];
                }
            }*/
            if(sig[i-1]=='<'){
                dp[i][j]=mod(dp[i-1][j-1]+dp[i][j]);
            }
            else{
                dp[i][j]=mod(dp[i][j]+dp[i-1][i-1]-dp[i-1][j-1]);
            }
            dp[i][j]=mod(dp[i][j]+dp[i][j-1]);
        }
    }
    cout<<mod(dp[n][n]);
}

Measured memory_bytes: 69120
n = int(input())
li = list(map(int, input().split()))

money = 1000
stack = 0

check = [0]*n

for i in range(n-1):
    if li[i] < li[i+1]:
        check[i] = 'up'
    elif li[i] == li[i+1]:
        check[i] = '-'
    else:
        check[i] = 'down'

for i in range(n):
    if check[i] == 'up':

        get_stack = money//li[i]
        money -= get_stack * li[i]
        stack += get_stack
        
    elif check[i] == '-':
        continue
    
    else:
        
        money += stack * li[i]
        stack = 0
        
print(money)

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

typedef pair<char, int> Pci;

struct compare {
    bool operator()(const Pci& a, const Pci& b) {
        return a.second < b.second;
    }
};



int partition(vector<Pci>& v, int l, int r) {
    int x = v[r].second;
    int i = l - 1;
    Pci t;
    for (int j = l; j < r; ++j) {
        if (v[j].second <= x) {
            ++i;
            t = v[i];
            v[i] = v[j];
            v[j] = t;
        }
    }
    t = v[i + 1];
    v[i + 1] = v[r];
    v[r] = t;
    return i + 1;
}
void quicksort(vector<Pci>& v, int l, int r) {
    if (l < r) {
        int m = partition(v, l, r);
        quicksort(v, l, m - 1);
        quicksort(v, m + 1, r);
    }
}



int main() {
    int n;
    cin >> n;
    vector<Pci> v(n), w(n);
    for (int i = 0; i < n; ++i) {
        char c;
        int d;
        cin >> c >> d;
        v[i] = make_pair(c, d);
        w[i] = make_pair(c, d);
    }
    quicksort(v, 0, n - 1);
    stable_sort(w.begin(), w.end(), compare());
    int f = 1;
    for (int i = 0; i < n; ++i) {
        if (v[i].first != w[i].first) {
            f = 0;
            break;
        }
    }
    cout << (f ? "Stable" : "Not stable") << "\n";
    for (int i = 0; i < n; ++i) {
        cout << v[i].first << " " << v[i].second << "\n";
    }
    // cout << "\n";
    // for (int i = 0; i < n; ++i) {
    //     cout << w[i].first << " " << w[i].second << "\n";
    // }

    return 0;
}

Measured memory_bytes: 5160
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索
from collections import deque
mod = 10**9+7
N = 10**6                   # 出力の制限
g1 = [1]*(N+1)              # 元テーブル
g2 = [1]*(N+1)              # 逆元テーブル
for i in range(2, N + 1 ): # 準備
    g1[i] = ( g1[i-1] * i ) % mod
g2[N] = pow(g1[-1], mod-2, mod)
for i in range(N, 0, -1):
    g2[i-1] = ( g2[i] * i ) % mod

def nCr(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

def nPr(n, r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

n, k = map(int, input().split())
graph = [[] for _ in range(n)]
#隣接リストの作成
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    graph[a].append(b)
    graph[b].append(a)

#幅優先探索
q = deque()
seen = [False]*n
parent = [-1]*n
q.append(0)
seen[0] = True
parent[0] = 0
ret = k
while len(q)>0:
    cur = q.popleft()
    if cur == 0:
        cnt = k-1
    else:
        cnt = k-2
    for i in graph[cur]:
        if seen[i]==False:
            seen[i] = True
            #親
            parent[i] = cur
            q.append(i)
            ret *= cnt
            ret %= mod
            cnt -= 1
print(ret)

Measured memory_bytes: 108220
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 1, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007
using namespace std;
int main(){
    FAST
    ll x; cin >> x;
    for(ll i=-1000; i<=1000;i++){
        for(ll j=-1000; j<=1000;j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }


    return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve() {
  int x; cin >> x; cout << (x ^ 1);
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

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

Node *root, *NIL;

Node * find(Node *u, int k)
{
    while(u != NIL && k != u->key)
    {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

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

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

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

int main()
{
    int n, x;
    string com;

    scanf("%d", &n);
    
    for(int i=0; i<n; i++)
    {
        cin >> com;
        if(com[0] == 'f')
        {
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }
        else if (com == "insert")
        {
            scanf("%d", &x);
            insert(x);
        }
        else if (com == "print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }   
    }
    return 0;
}


Measured memory_bytes: 22088
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define F first
#define S second
#define forn(i,n) for(int i = 0; i<n; i++)
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(),x.end()
#define printv(v) for(auto it : v) cout<<it<<" ";cout<<endl;
#define prec(n) fixed<<setprecision(n)
const int mod1 = 1000000007;
const int mod2 = 998244353;
const int N = 1e5;

int main()
{
	optimize

	#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
	#endif

	lli n,x,m;
	cin>>n>>x>>m;
	lli ans = 0;
	lli a = x;
	lli b = x;

	vi rem;

	while(find(all(rem), b) == rem.end())
	{
		rem.pb(b);
		ans += b;
		b = (b*b)%m;
	}

	int sub = 0;
	lli anssub = 0;
	for(int x : rem)
	{
		if(x != b)
		{
			anssub += x;
			sub++;
		}
		else
			break;
	}


	int cycsz = rem.size()-sub;

	ans = anssub + ((n-sub)/cycsz) * (ans-anssub);

	forn(i, (n-sub)%cycsz)
	{
		ans += b;
		b = (b*b)%m;
	}

	cout<<ans<<endl;

	


	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		String S = sc.nextLine();
		
		long sum = 0;
		
		// second challenge
		long R = 0;
		long G = 0;
		long B = 0;
		
		for(int i = 0 ; i < N; i ++) {
			char c = S.charAt(i);
			if(c == 'R') {
				R ++;
			}else if(c == 'G') {
				G ++;
			}else {
				B ++;
			}
		}
		
		sum = R * G * B;
		
		for(int i = 0; i < N - 2; i ++) {
			char first = S.charAt(i);
			for(int j = i + 1; j < N - 1; j ++) {
				if(first == S.charAt(j)) {
					continue;
				}
				char second = S.charAt(j);
				if((2 * j - i) < N && S.charAt(2 * j - i) != first && S.charAt(2 * j - i) != second) {
					sum --;
				}
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 36948