akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>

#define SIZE 201000

using namespace std;


int main(){
	vector <int> table(SIZE, 1), prime;
	int k = 0;
	for(int i = 2; i < SIZE; i++){
		if(table[i] == 0)
			continue;
		prime.push_back(i);
		k++;
		for(int j = 2; i * j < SIZE; j++){
			table[i * j] = 0;
		}
	}
	
	
	
	
	while(1){
		int N, P;
		
		cin >> N >> P;
		if(N == -1 && P == -1)
			break;
		
		int under;
		for(under = 0; under < k; under++){
			if(prime[under] > N)
				break;
		}
		
		vector <int> ans;
		
		for(int i = under; i < under + 100; i++)
			for(int j = i; j < under + 100; j++)
				ans.push_back(prime[i] + prime[j]);
		
		
		sort(ans.begin(), ans.end());
		
		cout << ans[P - 1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int mod = 1000000007;
	long long int n, k;
	long long int ans = 0LL;
	//long long int scnt = 0LL;
	//long long int lcnt = 0LL;
	long long int a[2005];
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){
				ans += k*(k+1)/2;
				ans %= mod;
			}
			if(a[i]<a[j]){
				ans += k*(k-1)/2;
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl x(n);
    rep(i, n) {
        cin >> x[i];
    }

    ll ans = INF;
    exrep(p, 1, 100) {  // 座標pで集会を開くとする
        ll now = 0; 
        rep(i, n) {
            now += (x[i] - p)*(x[i] - p);
        }
        chmin(ans, now);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int n;
	cin>>n;
	map<int,int> mp;
	rep(i,n){
		int a;cin>>a;
		rep(i,3) mp[a+i-1]++;
	}
	int ans=0;
	itr(i,mp) ans=max(ans,i->second);
	cout<<ans<<endl;
}

Measured memory_bytes: 6144
import sys
 
A, V = [int(x) for x in input().strip().split(" ")]
B, W = [int(x) for x in input().strip().split(" ")]
T = int(input().strip())
 
if V <= W:
    print("NO")
    sys.exit(0)
 
distance = abs(A - B)
diff = abs(V - W)
 
t, distance = divmod(distance, diff)
T -= t
if distance == 0 and T >= 0:
    print("YES")
    sys.exit(0)
elif T > 0:
    print("YES")
    sys.exit(0)
print("NO")
sys.exit(0)


Measured memory_bytes: 9028
#include <bits/stdc++.h>
typedef long long ll;
using std::cout ;
using std::endl ;
using std::cin ;
using std::string ;
using std::vector ;
using std::pair ;
#define rep(i,n) for(int i=0, i##_end=(n); i<i##_end; i++)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
template<class T>bool updatemMax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool updateMin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif


int main()
{
    double R;
    cin >> R;
    
    double pi = 3.14159;
    
    cout << (2*pi*R) << endl;
}


Measured memory_bytes: 3800
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var min = int.MaxValue;
        for(var i = 1; i <= num / 2; i++)
        {
            var a = i.ToString();
            var b = (num - i).ToString();
            var d1 = 0;
            var d2 = 0;
            for (var j = 0; j < a.Length; j++)
                d1 += ToInt32(a.Substring(j,1));
            for (var j = 0; j < b.Length; j++)
                d2 += ToInt32(b.Substring(j,1));
            min = Min(min, d1 + d2);
        }
        WriteLine(min);
    }
}


Measured memory_bytes: 17356
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

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

    int n;
    cin >> n;

    int ans = 0;
    for (int i = n;; i++) {
        char a, b, c;
        a = to_string(i).at(0);
        b = to_string(i).at(1);
        c = to_string(i).at(2);

        if (a == b && b == c) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long


signed main(){
    string S;
    cin >> S;
    
    string L,R;
    L = S.substr(0,S.length()/2);
    R = S.substr((S.length()+1)/2);
    reverse(R.begin(),R.end());
    
    int ans = 0;
    for(int i=0;i<=L.length();i++){
        if(L[i]!=R[i]){
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Deque;
import java.util.LinkedList;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int k = sc.nextInt();

		Deque<Pair> deque = new LinkedList<>();
		boolean[] visited = new boolean[k];
		deque.offer(new Pair(1, 1));
		while (!deque.isEmpty()) {
			Pair p = deque.poll();
			if (p.node == 0) {
				System.out.println(p.sumDigits);
				return;
			}
			visited[p.node] = true;
			int add1 = (p.node + 1) % k;
			int multi10 = (p.node * 10) % k;
			if (!visited[add1]) {
				deque.offerLast(new Pair(add1, p.sumDigits + 1));
			}
			if (!visited[multi10]) {
				deque.offerFirst(new Pair(multi10, p.sumDigits));
			}
		}
	}

	public static class Pair {
		int node;
		int sumDigits;

		Pair(int node, int sumDigits) {
			this.node = node;
			this.sumDigits = sumDigits;
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

}


Measured memory_bytes: 42708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str = "";
        try {
            str = reader.readLine();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
      
      int right = str.length()-1;
      int left = 0;
      
      int ret = 0;
      
      while(left<right){
        char leftchr = str.charAt(left);
        char rightchr = str.charAt(right);
        if(leftchr != rightchr) ret++;
        left++;
        right--;
        
      }
      
      System.out.println(ret);
      
    }
}

Measured memory_bytes: 23124
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn is_tarou_win(tarou_card: String, hanako_card: String) -> bool {
    let mut return_value: bool = false;
    let tarou_length = tarou_card.len();
    let hanako_length = hanako_card.len();
    for (index, tarou_char) in tarou_card.chars().enumerate() {
        let hanako_char: char = hanako_card[index..].chars().next().unwrap();
        if tarou_char != hanako_char {
            return_value = (tarou_char as u8) > (hanako_char as u8);
            break;
        }
        if (index + 1) == tarou_length || (index + 1) == hanako_length {
            return_value = tarou_length > hanako_length;
            break;
        }
    }
    return return_value;
}

fn main() {
    let count: u32 = read();
    let mut tarou_score: u32 = 0;
    let mut hanako_score: u32 = 0;

    for _ in 0..count {
        let tarou_card: String = read();
        let hanako_card: String = read();

        if tarou_card == hanako_card {
            tarou_score += 1;
            hanako_score += 1;
        } else if is_tarou_win(tarou_card, hanako_card) {
            tarou_score += 3;
        } else {
            hanako_score += 3;
        }
    }
    println!("{} {}", tarou_score, hanako_score);
}



Measured memory_bytes: 5028
def main():
    A, B, C = map(int, input().split())
    k = max(A, B, C)
    while True:
        if (3 * k - (A + B + C)) % 2 != 0:
            k += 1
            continue
        break
    print((3 * k - (A + B + C)) // 2)


main()


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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
ll n,k,l,c1[200005],c2[200005],mark[200005];
vll nb1[200005],nb2[200005];

void dfs1(ll st,ll ct){
    mark[st]=1;
    c1[st]=ct;
    for(ll v:nb1[st]){
        if(!mark[v]) dfs1(v,ct);
    }
}

void dfs2(ll st,ll ct){
    mark[st]=1;
    c2[st]=ct;
    for(ll v:nb2[st]){
        if(!mark[v]) dfs2(v,ct);
    }
}
map<pll,ll> co;

int main()
{
    cin>>n>>k>>l;
    rep(i,1,k){
        ll u,v;cin>>u>>v;
        nb1[u].pb(v);nb1[v].pb(u);
    }
    rep(i,1,l){
        ll u,v;cin>>u>>v;
        nb2[u].pb(v);nb2[v].pb(u);
    }
    ll ct=1;
    rep(i,1,n){
        if(!mark[i]) dfs1(i,ct++);
    }
    rep(i,1,n) mark[i]=0;
    ct=1;
    rep(i,1,n){
        if(!mark[i]) dfs2(i,ct++);
    }
    rep(i,1,n) co[mp(c1[i],c2[i])]++;
    rep(i,1,n) cout<<co[mp(c1[i],c2[i])]<<" ";
}


Measured memory_bytes: 32000
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int[] hundou = new int[10];
		hundou[0] = 1;
		for(int i = 1; i < 10; i++){
			hundou[i] = 2 * hundou[i-1];
		}
 
		while(sc.hasNext()){
			boolean[] use = new boolean[10];
			int target = sc.nextInt();
			int lastindex = 0;

			for(int i = 9; 0 <= i; i--){
				if(target >= hundou[i]){
					use[i] = true;
					target -= hundou[i];
					if(i >= lastindex){
						lastindex = i;
					}
				}else{
					use[i] = false;
				}
			}

			for(int i = 0; i < 10; i++){
				if(use[i] && i == lastindex){
					System.out.println(hundou[i]);
				}else if(use[i]){
					System.out.print(hundou[i]);
					System.out.print(" ");
				}
			}
 		}
	}
}

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

vector<int> g[200005];
ll val[200005];

void dfs(int p, int c, ll sum){
  val[c] += sum;
  for(auto v : g[c]){
    if(v!=p){
      dfs(c, v, val[c]);
    }
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,q;
  cin>>n>>q;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(int i=0;i<q;i++){
    int p,x;cin>>p>>x;
    p--;
    val[p] += x;
  }
  dfs(-1, 0, 0);

  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<val[i];
  }
  cout<<endl;

  return 0;
}


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

using namespace std;

long long n;

int main(){
	cin>>n;
	long long a=n%10;
	if(a==3) cout<<"bon"<<endl;
	else if(a==0||a==1||a==6||a==8)cout<<"pon"<<endl;
	else cout<<"hon"<<endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int goods[] = new int[N];
		int popular = 0;
		int sum = 0;

		for (int i = 0; i < N; i++) {
			goods[i] = scan.nextInt();
			sum = sum + goods[i];
		}

		for (int i = 0; i < N; i++) {
			if(goods[i] >= sum * ((double) 1 / (4 * M))) {
				popular++;
			}
		}

		if (popular >= M) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		scan.close();
	}
}


Measured memory_bytes: 23380
#include <iostream>

int main (){
  int h, w;
  std::cin >> h >> w;

  while ((h!=0)&&(w!=0))
    {
      for (int i=0; i<h; i++)
        {
          if ((i==0) || (i==h-1))
            {
              for (int j=0; j<w; j++)
                std::cout << '#';   
            }
          else
            {
              for (int j=0; j<w; j++)
                {
                  if ((j==0) || (j==(w-1)))
                    std::cout << '#';
                  else
                    std::cout << '.';
                }
            }
          std::cout << std::endl;
        }
      std::cout << std::endl;
      std::cin >> h >> w;
    }
}



Measured memory_bytes: 3084
import java.util.Scanner;

class Main
{
	public static void main ( String[] args ) {
		
		Scanner  sc = new Scanner ( System.in );
		StringBuilder str = new StringBuilder ();
		
		boolean [][] cards = new boolean[ 4 ][ 13 ];
		
		int n = sc.nextInt ();
		
		for ( int i = 0; i < n; i++ ) {
			String art = sc.next ();
			int rank = sc.nextInt ();
			
			if ( art.equals ( "S" ) ) {
				cards[ 0 ][ rank - 1 ] = true;
			} else if ( art.equals ( "H" ) ) {
				cards[ 1 ][ rank - 1 ] = true;
			} else if ( art.equals ( "C" ) ) {
				cards[ 2 ][ rank - 1 ] = true;
			} else {
				cards[ 3 ][ rank - 1 ] = true;
			}
		}
		for ( int i = 0; i < 4; i++ ) {
			for ( int j = 0; j < 13; j++ ) {
				if ( !cards[ i ][ j ] ) {
					if ( i == 0 ) {
						System.out.println ( "S " + ( j + 1 ) );
					} else if ( i == 1 ) {
						System.out.println ( "H " + ( j + 1 ) );
					} else if ( i == 2 ) {
						System.out.println ( "C " + ( j + 1 ) );
					} else {
						System.out.println ( "D " + ( j + 1 ) );
					}
				}
			}
		}
	}
}

Measured memory_bytes: 26056
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		string s;
		cin >> s;
		int res = 0;
		for (int i=0 ; i<(int)s.length() ; i++)
		if (s[i]=='1') res++;
		cout << res << endl;
		return 0;  
}  


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  rep(i, 3) cout << a[i] << (i == 3 - 1 ? "\n" : " ");
  return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include<stdio.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=105;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007
vector<int>v[100001];
int vis[100001];
int f[100001];
int dfs(int node)
{
  vis[node]=1;
  if(v[node].empty())
    return 0;
  for(int child:v[node])
  {
    if(vis[child]==0)
    {
      f[node]=max(f[node],1+dfs(child));
    }
    else
      f[node]=max(f[node],1+f[child]);
  }
  return f[node];
}
int main()
{
  
 int n,m,i,j,k;
cin>>n>>m;
for(i=0;i<m;i++)
{
  cin>>k>>j;
  v[k].pb(j);
}

for(i=1;i<=n;i++)
{
 if(vis[i]==0)
   k= dfs(i);
     
  
}
int ans=0;
for(i=1;i<=n;i++)
ans=max(ans,f[i]);


cout<<ans;
}

Measured memory_bytes: 7808
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.nextInt();

            out.println((x - z) / (y + z));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23380
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    
    if N == 1:
        print(1)
        sys.exit()
    
    ans = 0
    ansans = 0
    for i in range(1, N+1):
        tmp = 0
        han = i
        aaa = i
        while True:
            if han % 2 == 0:
                han = han / 2
                tmp += 1
            else:
                break
        if tmp > ans:
            ans = tmp
            ansans = aaa
            
    print(ansans)
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38544
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main()  {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	S := scanner.Text()
	scanner.Scan()
	T := scanner.Text()

	scanner.Scan()
	A, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	B, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	U := scanner.Text()
 
	if S == U {
		fmt.Println(A - 1, B)
	} else if T == U {
		fmt.Println(A, B - 1)
	} else {
		fmt.Println(A , B)
	}
}

Measured memory_bytes: 1832
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>
//#include <ctime>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 500100, MAXK = 20;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}



int main() {
    setIO();
	//setIO("lmio_1991_3e1_seka_01");

    int n;
    ll d;
     cin >> n >> d;
     int ans = 0;
    REP(n) {
        ll x, y; cin >> x >> y;
        if (x*x + y*y <= d*d) ans++;
    }
    cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3660
import sys
import math
from collections import Counter
get_string = lambda: sys.stdin.readline().strip()
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
get_int = lambda: int(sys.stdin.readline())

#----------------------------------------------------------------------#

n=get_int()
a=get_list()
freq=Counter(a)
ans=0
for key,val in freq.items():
    if val>key:
        ans+=val-key
    elif key>val:
        ans+=val
print(ans)
        
    
        
        



Measured memory_bytes: 64544
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 


void solve(){
	string s;
	cin>>s;
	int cnt=0;
	FOR(i, 0, sz(s)) if(s[i]=='A') cnt++;
	if(cnt==0 || cnt==3) cout<<"No";
	else cout<<"Yes";	
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int count = 0;
        for (int i = Math.min(a, b); i >= 0; i--) {
            if (a % i == 0 && b % i == 0) {
                count++;
            }

            if (count == k) {
                System.out.println(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 25044
k = int(input())

if k == 0:
    print("2\n1 1")
    exit(0)

if k == 1:
    print("2\n2 0")
    exit(0)

n = min(50,k)
a = [i for i in range(n)]
c = k // n

for i in range(n):
    a[i] += c

for i in range(k % n):
    a[i] += n
    for j in range(n):
        if i != j:
            a[j] -= 1

print(n)
for i in a:
    print(i, end=' ')
print()


Measured memory_bytes: 3064
///https://www.cnblogs.com/Basasuya/archive/2018/09/12/9637401.html
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

struct Node{
    int a, b, c;
    Node(int _a=0, int _b=0, int _c=0):a(_a), b(_b), c(_c) {}
};

vector<Node> vc;

int main()
{
    int L=read();
    int tmp=L;
    int cnt=0;
    while(tmp){
        tmp>>=1;
        cnt++;
    }
    for(int i=1;i<cnt;i++){
        vc.push_back(Node(i,i+1,0));
        vc.push_back(Node(i,i+1,(1<<i-1)));
    }
    tmp=L;
    int tmp2=0;
    bool ok=true;
    for(int i=cnt-1;i>=0;i--){
        if((tmp>>i)&1){
            tmp-=(1<<i);
            if(!ok){
                vc.push_back(Node(i+1,cnt,tmp2));
            }
            tmp2+=1<<i;ok=false;
        }
    }
    printf("%d %d\n", cnt, (int)vc.size());
    for(int i = 0; i < (int)vc.size(); ++i) {
        printf("%d %d %d\n", vc[i].a, vc[i].b, vc[i].c);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
typedef unsigned long long wolf;
char S[310000];
char T[310000];
long long pow[310000];
wolf P=1299709;
//long long mod=1145148931919LL;
int main(){
	scanf("%s%s",S,T);
	int n=strlen(S);
	int m=strlen(T);
	pow[0]=1;
	for(int i=1;i<310000;i++)pow[i]=pow[i-1]*P;
	//for(int i=0;i<10;i++)printf("%lld\n",pow[i]);
	vector<wolf>v;
	wolf val=0;
	for(int i=0;i<m;i++)val=(val+(T[i])*pow[i]);
	for(int i=0;i<m;i++){
		for(int j=0;j<26;j++){
			if(T[i]-'a'==j)continue;
			wolf tmp=(val-(T[i])*pow[i]);
			v.push_back((tmp+pow[i]*('a'+j)));
		//	printf("%d %d: %lld\n",i,j,(tmp+pow[i]*j)%mod);
		}
		for(int j=0;j<26;j++){
			if(T[i]-'A'==j)continue;
			wolf tmp=(val-(T[i])*pow[i]);
			v.push_back((tmp+pow[i]*('A'+j)));
		//	printf("%d %d: %lld\n",i,j,(tmp+pow[i]*j)%mod);
		}
	}
	std::sort(v.begin(),v.end());
	int ret=0;
	wolf now=0;
	for(int i=n-1;i>=0;i--){
		now=now*P;
		if(i<n-m)now=(now-(S[i+m])*pow[m]);
		now=(now+(S[i]));
		if(i<=n-m&&binary_search(v.begin(),v.end(),now))ret++;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 71248
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n,ww;
    scanf("%ld%ld", &n, &ww);

    vector<long> w(n), v(n);
    vector<long> zz[4];
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld%ld", &w[i], &v[i]);
        zz[w[i]-w[0]].push_back(v[i]);
    }
    for(i=0; i<4; i++) {
        sort(zz[i].rbegin(), zz[i].rend());
    }

    vector<long> szz[4];
    long k;
    for(k=0; k<4; k++) {
        szz[k].resize(zz[k].size()+1);
        szz[k][0]=0;
        for(i=0; i<(long)zz[k].size(); i++) {
            szz[k][i+1]=szz[k][i]+zz[k][i];
        }
    }

    long j,m;
    ll ans=0;
    for(i=0; i<=(long)zz[0].size(); i++) {
        ll cst0=i*w[0];
        if(cst0>ww) continue;
        ll sum0=szz[0][i];
        for(j=0; j<=(long)zz[1].size(); j++) {
            ll cst1=cst0+(w[0]+1)*j;
            if(cst1>ww) continue;
            ll sum1 = sum0+szz[1][j];
            for(k=0; k<=(long)zz[2].size(); k++) {
                ll cst2=cst1+(w[0]+2)*k;
                if(cst2>ww) continue;
                ll sum2 = sum1+szz[2][k];
                for(m=0; m<=(long)zz[3].size(); m++) {
                    ll cst3=cst2+(w[0]+3)*m;
                    if(cst3>ww) continue;
                    ll sum3 = sum2+szz[3][m];
                    ans = MAX(ans, sum3);
                }
            }
        }
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, M;
    cin >> N >> M;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());

    ll left = 0, right = 2 * 1e5 + 1;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll cnt = 0;
        int j = N - 1;
        for (int i = 0; i < N; i++) {
            while (j >= 0 && A[i] + A[j] < mid) --j;
            cnt += j + 1;
        }
        if (cnt < M) {
            right = mid;
        }
        else {
            left = mid;
        }
    }

    Vl csum(N + 1);
    for (int i = 0; i < N; i++) {
        csum[i + 1] = csum[i] + A[i];
    }
    ll cnt = 0;
    ll ans = 0;
    int a = N - 1;
    for (int i = 0; i < N; i++) {
        while (a >= 0 && A[a] + A[i] <= left) --a;
        int num = a + 1;
        cnt += num;
        ans += csum[a + 1] + A[i] * num;
    }
    ans += left * (M - cnt);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

ll gcd(ll a, ll b) {
    if (b == 0)return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
int main() {
    init();

    ll a, b, c, d; cin >> a >> b >> c >> d;
    --a;
    ll y = b, x = a;
    y -= b / c + b / d;
    y += b / lcm(c, d);
    x -= a / c + a / d;
    x += a / lcm(c, d);
    cout << y - x << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

int main() {
	in(ll, N, K);
	--N; --K;
	out(N / K + !!(N%K));
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */



#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <limits>




#include <ostream>
#include <sstream>


using namespace std;

class C {
public:

  int sgn(long long int val) {
    if (val == 0) {
      return 0;
    }
    if (val < 0) {
      return -1;
    }
    return 1;
  }

  void solve(std::istream &in, std::ostream &out) {
    ios::sync_with_stdio(false);
    int n;
    in >> n;
    vector<long long int> a(n), p(n);
    for (int i = 0; i < n; ++i) {
      in >> a[i];
    }
    long long int steps = 0;
    long long int steps2 = 0;

    if (a[0] == 0) {
      p[0] = 1;
      ++steps;
    }else{
      p[0] = a[0];
    }

    for (int i = 0; i < n - 1; ++i) {
      p[i + 1] = p[i] + a[i + 1];
      if (sgn(p[i]) != -sgn(p[i + 1])) {
        steps += abs(p[i + 1]) + 1;
        p[i + 1] = -sgn(p[i]);
      }
    }
    steps2 = abs(a[0]) + 1;
    p[0] = -sgn(p[0]);
    for (int i = 0; i < n - 1; ++i) {
      p[i + 1] = p[i] + a[i + 1];
      if (sgn(p[i]) != -sgn(p[i + 1])) {
        steps2 += abs(p[i + 1]) + 1;
        p[i + 1] = -sgn(p[i]);
      }
    }
    steps = min(steps, steps2);
    out << steps << endl;
  }

};


int main() {
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

long long prime = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, s;
    cin >> n >> s;
    vector<int> as(n);
    for (auto& a : as) {
        cin >> a;
    }
    vector<vector<long long>> count(n + 1, vector<long long>(s + 1, 0));
    count[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        count[i + 1][0] = 1;
        for (int t = 0; t <= s; ++t) {
            count[i + 1][t] += count[i][t];
            if (t >= as[i]) {
                count[i + 1][t] += count[i][t - as[i]];
            }
            count[i + 1][t] %= prime;
        }
    }
    long long total_sum = 0;
    for (int i = 1; i <= n; ++i) {
        total_sum += count[i][s];
    }
    total_sum %= prime;
    cout << total_sum << endl;
    return 0;
}


Measured memory_bytes: 70784
#include<stdio.h>

int temp[200005];
long long count = 0 ;

void mergeSort(int *arr, int left, int right){
	if(left == right) return;
	if(left >= right) return;
	int mid = (left+right)/2;
	
	mergeSort(arr, left, mid);
	mergeSort(arr, mid+1, right);
	
	int x = left;	
	int n = mid;
	
	int y = mid+1;
	int m = right;
	
	int i = left;
	while(x <=n && y <= m){
		if(arr[x] <= arr[y]){
			temp[i++] = arr[x++];
		}
		else{
			count += (n+1)-x;
//			printf("-->%d %d %d<--\n", n, x ,count);
			temp[i++] = arr[y++];
		}
	}
	
	while(x <= n){
		temp[i++] = arr[x++];
	}
	while(y <= m){
		temp[i++] = arr[y++];
	}
	
	for(int j = left; j<=right; j++){
		arr[j] = temp[j];
	}
}

int main(){
	int n;
	int arr[200005];
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &arr[i]);
	}
	
	mergeSort(arr, 0, n-1);
	printf("%lld\n", count);
	
	return 0;
}


Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define sc(x) scanf("%d", &x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define fastio ios::sync_with_stdio(0),cin.tie(0)
template<class T>T gcd(T a, T b){return b?gcd(b, a%b):a;}
const int mod = 1e9+7;
const int maxn = 1e5+10;
char s[maxn];
ll dp[maxn][3];

ll qpow(ll a, ll n)
{
    ll ret = 1;
    while(n){
        if(n&1)ret = ret*a%mod;
        a = a*a%mod;
        n >>= 1;
    }
    return ret;
}

int main()
{
    scanf("%s", s+1);
    int n = strlen(s+1), cnt = 0;
    for(int i = 1; i <= n; i++){
        if(s[i] == 'A'){
            dp[i][0] = dp[i-1][0]+qpow(3, cnt);
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'B'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1]+dp[i-1][0];
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'C'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
            dp[i][2] = dp[i-1][2]+dp[i-1][1];
        }
        else{
            dp[i][0] = 3*dp[i-1][0]+qpow(3, cnt);
            dp[i][1] = 3*dp[i-1][1]+dp[i-1][0];
            dp[i][2] = 3*dp[i-1][2]+dp[i-1][1];
            cnt++;
        }
        for(int j = 0; j < 3; j++){
            dp[i][j] %= mod;
            //printf("dp[%d][%d][%d]=%lld\n", i, j, k, dp[i][j][k]);
        }
    }
    printf("%lld\n", dp[n][2]%mod);
    return 0;
}




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

int main(){
  string s;
  cin >> s;
  if(s == "Sunny") cout << "Cloudy" << endl;
  else if(s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

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();
        if(a == b){
            System.out.println(c);
        }else if(b == c){
            System.out.println(a);
        }else{
            System.out.println(b);
        }
    }
}

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

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

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

void solve(void)
{
  int res = 0;
  int n;
  double d;
  cin>>n>>d;
  for (int i = 0; i < n; i++)
  {
    double x,y;
    cin>>x>>y;
    double dist = sqrt(x*x + y*y);
    if(dist <= d)res++;
  }
  cout<<res<<endl;
  
  
  return;
}

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

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

  return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  
  int x;
  
  for (int i =0; i<N; i++){
    cin >> x;
    
    if (2*x <= K){
      ans += 2*x;
    }
    else{
      ans += 2*(K-x);
    }
  }
  cout << ans <<endl;
}
  

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n,m;cin>>n>>m;
    V<Pll>ab;
    V<ll>B[100010];
    for(ll i=0;i<m;i++){
        ll a,b;cin>>a>>b;
        a--;b--;
        B[b].pb(a);
        ab.pb(mp(a,b));
    }
    ll ans=0;
    ll last_break=-1;
    for(ll i=1;i<n;i++){
        for(ll j=0;j<B[i].size();j++){
            if(last_break<B[i][j]){
                last_break=i-1;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------




































Measured memory_bytes: 6768