akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    ll h,w,m;
    cin>>h>>w>>m;
    map<int,int>row,col;
    map<pair<int,int>,int>s;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        s[{x,y}]++;
        row[x]++;
        col[y]++;
    }
    ll res=0;
   int rmax=0;int colmax=0;
   int orz;int oc;
    vector<int>ypob,xpob;
   for(auto x:row){
        //cout<<x.second<<endl;
    rmax=max(rmax,x.second);
   }
   for(auto x:col){
       //cout<<x.second<<endl;
    colmax=max(colmax,x.second);

   }
  // cout<<rmax<<" "<<colmax<<endl;
   for(auto x:row){
    if(x.second==rmax)xpob.push_back(x.first);
   }
   for(auto x:col){
     if(x.second==colmax)ypob.push_back(x.first);

   }
   ll cur_res=rmax+colmax-1;
//  for(auto x:xpob)cout<<x<<endl;
  for(auto x:xpob){
       bool ok=true;
    for(auto y:ypob){
        if(!s.count({x,y})){
            cur_res++;
            ok=false;
            break;
        }

    }
    if(!ok)break;
  }
cout<<cur_res<<endl;
    return 0;
}


Measured memory_bytes: 54240
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = -1;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    cout << s.substr(0, 3);
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
bool isPrime[250000];
int main() {
	fill(isPrime, isPrime + 250000, true);
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 0; i * i <= 250000; i++) {
		if (isPrime[i]) {
			for (int j = (i << 1); j < 250000; j += i) {
				isPrime[j] = false;
			}
		}
	}
	int n;
	while (cin >> n, n) {
		int count = 0;
		for (int i = n + 1; i <= 2 * n; i++) {
			if (isPrime[i]) count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n,q,l,r;
int a[100005];
string s;
int main()
{
    cin>>n>>q;
    cin>>s;
    for(int i=1;i<n;i++)
    { 
        if(s[i]=='C'&&s[i-1]=='A') a[i]++;
        a[i]+=a[i-1];
    }
    for(int i=1;i<=q;i++)
    {
        cin>>l>>r;
        l--,r--;
        cout<<a[r]-a[l]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

const vector<ll> d2{0, 1, 0, 2, 0, 1};
const vector<ll> d3{0, 0, 1, 0, 0, 1};
const vector<ll> d5{0, 0, 0, 0, 1, 0};



int main() {
    string s1,s2;
    cin>>s1>>s2;

    ll N = s1.size();
    ll M = s2.size();
    vector<vector<ll>>dp(N+1,vector<ll> (M+1));
  
    rep(i,N){
        dp[i+1][0] = i+1;
    }

    rep(i,M){
        dp[0][i+1] = i+1;
    }

    rep(i,N){
        rep(j,M){
            if(s1[i] == s2[j]){
                dp[i+1][j+1] = min({dp[i][j],dp[i+1][j]+1,dp[i][j+1]+1});
            }else{
                dp[i+1][j+1] = min({dp[i][j]+1 ,dp[i+1][j]+1,dp[i][j+1]+1});
            }
        }
    }

    cout<<dp[N][M]<<endl;
    return 0;
    

}



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

int main() {
    using namespace std;
    ll h;
    cin >> h;
    ll ans     = 0LL;
    ll nanntai = 1LL;
    while (h > 0LL) {
        ans += nanntai;
        h = h / 2LL;
        nanntai *= 2LL;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;
const int MAX_T = 100100;
const long long INF = 1LL << 60;
long long dp[MAX_T][3];

template<class T> void chmin(T & a, T b) {
	if (a > b) a = b;
}

template<class T> void chmax(T & a, T b) {
	if (a < b) a = b;
}

int main() {
	int N; cin >> N;
	long long a[MAX_T][3];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			scanf("%lld", &a[i][j]);
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (k == j) continue;
				chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
			}
		}
	}

	long long res = 0;
	for (int i = 0; i < 3; i++) {
		chmax(res, dp[N][i]);
	}

	cout << res << endl;

	return 0;
}

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

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using ml = map<ll,ll>;

#define ff first
#define ss second
#define endl '\n'
#define ins insert
#define eb emplace_back
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define itr(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while(t--)
#define rep(i,a,n) for(ll i = a ; i < n ; ++i)
#define per(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) itr(x,c) cout << x << " "; cout << endl;
#define dm(m) itr(x,m) cout << x.ff << " -> " << x.ss << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
    ll steps = 0;
    ll n; cin >> n;
    string s; cin >> s;


   	ll i = 0, j = n - 1;

   	while(i < n && j >= 0 && i < j) {
   		while(i < n && s[i] == 'R') ++i;
   		while(j >= 0 && s[j] == 'W') --j;

   		if(i < n && j >= 0 && i < j) {swap(s[i],s[j]); steps++;}
   	}

   	cout << steps;
}

Measured memory_bytes: 3716
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        l: u64,
        r: u64
    };

    let base_i = l % 2019;
    let mut flag_i = false;
    let mut flag_j = false;
    let mut result = 2019;

    for i in l..r {
        if i % 2019 == base_i && flag_j {
            break;
        }

        flag_j = false;
        let base_j = (i + 1) % 2019;

        for j in i + 1..=r {
            if j % 2019 == base_j && flag_j {
                break;
            }
            result = std::cmp::min(result, (i * j) % 2019);
            flag_j = true;
        }

        flag_j = true;
    }

    println!("{}", result);
}


Measured memory_bytes: 2172
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
const int N = 1e9+10;

int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    vector<int>b(n,1);
    vector<int>r(n,0);
    r[0]=1;
    while(m--)
    {
		int a,bb;
		cin>>a>>bb;
		a--,bb--;
		b[a]--;
		b[bb]++;
		r[bb] |=r[a];
		r[a] &=!! b[a];
	}
	cout<<accumulate(r.begin(),r.end(),0)<<nl;
    return 0;
}


Measured memory_bytes: 1024
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};


int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll k,s,ans=0;
    sfl(k),sfl(s);
    for(ll i=0;i<=k;i++){
        for(ll j=0;j<=k;j++){
            if(s-i-j<=k and s-i-j>=0){
                ans++;
            }
        }
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 3764
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, i;
    int[] a;
    n = sc.nextInt();
    a = new int[n];
    for(i = 0;i < n;i++)a[i] = sc.nextInt();
    out.println(count(a, 0, n));

    sc.close();
  }
  private static long count(int[] c, int l, int r){
    int m;
    if(l + 1 >= r){
      if(l < r)return 0;
      return 1;
    }else{
      m = (l + r) / 2;
      return (count(c, l, m) + count(c, m, r) + merge(c, l, m, r));
    }
  }
  private static long merge(int[] c, int l, int m, int r){
    int nl, nr;
    int i, j, k;
    int infi = 1980000000;
    int[] cl, cr;
    long count;
    nl = m - l; nr = r - m;
    cl = new int[nl + 1]; cr = new int[nr + 1];
    for(i = 0;i < nl;i++)cl[i] = c[l + i];
    for(i = 0;i < nr;i++)cr[i] = c[m + i];
    cl[nl] = infi; cr[nr] = infi;
    i = 0; j = 0; count = 0;
    for(k = l;k < r;k++){
      if(cl[i] < cr[j])c[k] = cl[i++];
      else{
        c[k] = cr[j++]; count += (nl - i);
      }
    }
    return count;
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

#define ld long double
#define ll long long
#define ull unsigned long long

#define f first
#define s second

#define endl '\n'
#define pii pair <ll, ll>

#define ios ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair

#define pi 3.14159265358979323846264
#define y1 abacaba

using namespace std;

const int MXN = 1e5 + 30;
const int MAXN = 1e3 + 2;
const ll INF = 1e9 + 7;
const ll BINF = 1e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-15;   
const ll dx[] = {0, 0, 1, -1};      
const ll dy[] = {1, -1, 0, 0};
           
char a, b, c, d;

int f[7];
int ans;

int main(){
    //freopen("input.txt", "r", stdin); 
    cin >> a >> b >> c >> d;
    f[1] = int(a - '0');
    f[2] = b - '0';
    f[3] = c - '0';
    f[4] = d - '0';
    for(int mask = 0; mask < (1 << 3); mask++){
        ans = f[1];
        for(int j = 0; j <= 2; j++){
            if(mask & (1 << j)){
                ans += f[j + 2];
            } else{
                ans -= f[j + 2];
            }
        }
        if(ans == 7){
            cout << f[1];
            for(int j = 0; j <= 2; j++){
                if(mask & (1 << j)){
                    cout << "+" << f[j + 2];
                } else{
                    cout << "-" << f[j + 2];
                }
            }
            cout << "=7";
            return 0;
        }
    }
    return 0;
}

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

constexpr int SIZE = 3;
constexpr int N = SIZE * SIZE;
constexpr int correct = 'a' - 'A';

string pieces[N];

int ans;
int turn[SIZE][SIZE];
int put[SIZE][SIZE];
bool used[N];

inline bool match(char a, char b) {
	return abs(a - b) == correct;
}

void dfs(int x, int y) {
	if(x == SIZE) return dfs(0, y + 1);
	if(y == SIZE) {
		++ans;
		return;
	}

	int &i = put[y][x];
	int &r = turn[y][x];

	for(i = 0; i < N; ++i) {
		if(used[i]) continue;

		for(r = 0; r < 4; ++r) {
			if(x && !match(pieces[i][(r+3)%4], pieces[put[y][x-1]][(turn[y][x-1]+1)%4])) continue;
			if(y && !match(pieces[i][r], pieces[put[y-1][x]][turn[y - 1][x] ^ 2])) continue;

			used[i] = true;
			dfs(x + 1, y);
			used[i] = false;
		}
	}
}


void solve() {
	for(auto &e : pieces) cin >> e;
	ans = 0;
	dfs(0, 0);
	cout << ans << endl;
}

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

	int t;
	cin >> t;
	while(t--) solve();

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1204
D = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
     [[-1,  0], [0, -1], [1,  0], [1, 1], [0, 1], [-1, 1]]]

w, h = gets.split.map(&:to_i)
fld = (h+2).times.map{ [false]*(w+2) }
(1..h).each{ |i| gets.split(" ").each_with_index{ |e, j| fld[i][j+1] = true if e == "1" } }

tmp = (h+2).times.map{ [false]*(w+2) }
arr = []
arr << [0, 0]
tmp[0][0] = true
until arr.empty?
  y, x = arr.shift
  D[y%2].each do |dy, dx|
    u = y + dy; v = x + dx
    next if u < 0 || u > h+1 || v < 0 || v > w+1
    if !fld[u][v] && !tmp[u][v]
      tmp[u][v] = true
      arr << [u, v]
    end
  end
end
fld = fld.flatten.zip(tmp.flatten).map{ |f, t| !(!f & t) }
p fld.map.with_index{ |e, i| D[(i/(w+2))%2].count{ |y, x| !fld[i+y*(w+2)+x] } if e }.compact.reduce(:+)

Measured memory_bytes: 9460
#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
	/* time: O(1), space: O(1) */
	int duplexPrinting(int n) {
		return (n + 1) / 2;
	}
};

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

	Solution sol;
	const int ans = sol.duplexPrinting(n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

int n;
ll DP[2][3002][3002];

ll dp(int z, int r, int m){
    int b = n - z - r;
    if(m == 0)  return 1;
    ll &ans = DP[z][r][m];
    if(ans != -1)   return ans;
    ans = 0;
    if(r > 0){
        //RB
        ans = (ans + dp(z, r, m-1)) % MOD;
        //RR
        ans = (ans + dp(z, r-1, m-1)) % MOD;
    }
    if(b > 0){
        //BR
        ans = (ans + dp(z, r, m-1)) % MOD;
        //BB
        ans = (ans + dp(z, r+1, m-1)) % MOD;
    }
    return ans;
}



int main(){

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

    int m;
    cin>>n>>m;

    memset(DP, -1, sizeof(DP));
    ll ans = 0;
    for(int r=0;r<=n;r++){
        ll temp = dp(0, r, m);
        if(r > 0)   temp -= dp(1, r-1, m);
        ans += temp;
        ans %= MOD;
    }

    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout<<ans;
    return 0;
}











Measured memory_bytes: 141312
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;

const int mxn = 100005;
int n, a[mxn][4];
int ff[mxn][4];

void solution()
{
  ff[1][1] = a[1][1], ff[1][2] = a[1][2], ff[1][3] = a[1][3];
  for(int r = 2; r <= n; r++)
  {
    for(int c = 1; c <= 3; c++) 
    {
      for(int i = 1; i <= 3; i++)
      {
        if( i == c ) continue;
        ff[r][c] = max(ff[r][c], a[r][c] + ff[r - 1][i]);
      }
    }
  }
}

int main() 
{
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) 
  {
    scanf("%d %d %d", &a[i][1], &a[i][2], &a[i][3]);
  }
  solution();
  printf("%d\n", max(ff[n][3], max(ff[n][2], ff[n][1])));
  return 0;
}

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

int tab[100005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, k, q, a;
    cin >> n >> k >> q;
    for(int i=0; i<q; i++)
    {
        cin >> a;
        tab[a]++;
    }
    for (int i = 1; i <= n; i++)
        cout << (k+tab[i]-q > 0 ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    int N,K;
    cin >> N >> K;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = K; i < N; i++) {
        if(A[i] > A[i-K]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 4772
N,M,Q = map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(Q)]
ans = 0
def dfs(n,A,now):
    global ans
    if n == 0:
        ansi = 0
        for a,b,c,d in abcd:
            if A[b-1]-A[a-1]==c:
                ansi+=d
        ans = max(ans,ansi)
    else:
        for i in range(now,M+1):
            dfs(n-1,A+[i],i)

A = []
dfs(N,A,1)
print(ans)

Measured memory_bytes: 9168
#include <stdio.h>
int main(void){
	int n;
	scanf("%d\n",&n);

	int i=0;

	int aaa[26];
	for(i=0;i<26;i++){
		aaa[i]=1000000;
	}
	char s[200];
	int k;
	char c;
	for(k=0;k<n;k++){
		int memo[26];
		for(i=0;i<26;i++){
			memo[i]=0;
		}
		while(1==1){
			scanf("%c",&c);
			if(c=='\n'){
				break;
			}
			memo[c-97]+=1;

		}
		for(i=0;i<26;i++){
			(aaa[i]>memo[i]?aaa[i]=memo[i]:1);
		}
	}
	int j;
	for(i=0;i<26;i++){
		for(j=0;j<aaa[i];j++){
			printf("%c",i+97);
		}
	}

	printf("\n");
	return 0;
}

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

int main() {
    char b;
    cin >> b;
    if(b=='A') cout << 'T' << endl;
    if(b=='T') cout << 'A' << endl;
    if(b=='C') cout << 'G' << endl;
    if(b=='G') cout << 'C' << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//ScannerChar
		char b = sc.findInLine(".").charAt(0);
		char ans = 'a';
		switch (b) {
		case 'A':
			ans = 'T';
			break;
		case 'T':
			ans = 'A';
			break;
		case 'C':
			ans = 'G';
			break;
		case 'G':
			ans = 'C';
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


ll H, W, D,Q;
vector<pair<ll,pair<ll,ll>>> A;
ll B[100000];//次のマスまでの消費コスト

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

	cin >> H >> W >> D;
	A.resize(H*W);

	ll idx = 0;
	FOR(i, 0, H)FOR(j, 0, W) {
		cin >> A[idx].first;
		A[idx].second.first = i;
		A[idx].second.second = j;
		idx++;
	}

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

	for (int i = 0; i + D < H * W; i++) {
		//cout <<" "<< A[i].first << endl;
		B[A[i].first]
			= abs(A[i].second.first - A[i + D].second.first) + abs(A[i].second.second - A[i + D].second.second);
	}

	FOR(i, D+1, H*W + 1) {
		B[i] += B[i - D];
	}


	cin >> Q;
	FOR(i, 0, Q) {
		ll L, R; cin >> L >> R;
		ll ans = 0;
		
		if(L>D)cout << B[R-D]-B[L-D] << endl;
		else if(R>D)cout << B[R-D] << endl;
		else cout << 0 << endl;
	}





	return 0;
}

Measured memory_bytes: 6096
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000

int gcd(int x, int y) {
	if(x > y)swap(x, y);
	if (x <= 0)return y;
	if (y%x == 0)return x;
	return gcd(y%x, x);
}

int main() {
	int n, m, x, k,g;
	scanf("%d %d", &n,&k);
	m = 0;
	g = 0;
	f(i, n) {
		scanf("%d", &x);
		g = gcd(g, x);
		m = max(m, x);
	}
	if (m < k) {
		printf("IMPOSSIBLE\n");
		return 0;
	}
	if (k%g != 0) {
		printf("IMPOSSIBLE\n");
		return 0;
	}
	printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 128
H, W, D = gets.split.map &:to_i
h = {}
H.times{|y|
  a = gets.split.map &:to_i
  a.each_with_index{|n, x|
    h[n] = [x, y]
  }
}
cusum = [0]
(1..D).each{|start|
  sum = 0
  x, y = h[start]
  start.step(H*W, D).each{|n|
    xx, yy = h[n]
    sum += (xx - x).abs + (yy - y).abs
    cusum[n] = sum
    x, y = xx, yy
  }
}
Q = gets.to_i
$<.each{|s|
  l, r = s.split.map &:to_i
  p cusum[r] - cusum[l]
}


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

typedef long long ll;
ll n, m, ans, cnt, d[100050][33];
ll M =1e9 + 7;
int main()
{
	ll i, j;
	cin >> n >> m;
	d[1][0] = 1;
	d[1][1] = 1;
	for (i =2; i <= n + 30; i++) {
		d[i][0] = 1;
		for (j = 1; j <= 30; j++) {
			d[i][j] = (d[i - 1][j - 1] + d[i - 1][j] ) % M;
		}
	}
	ans = 1;
	for (i = 2; i * i <= m;i++) {
		cnt = 0;
		while (m % i == 0) {
			cnt++;
			m /= i;
		}
		if (cnt > 0) ans = (ans * d[n + cnt - 1][cnt]) % M;
	}
	if (m > 1) ans = (ans * d[n][1]) % M;
	cout << ans;
    return 0;
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  int n = 50;
  vector<ll> a(n, n - 1 + k / 50);
  rep(i, k % 50) {
    rep(j, 50) {
      if (i == j) a[j] += 50;
      else a[j]--;
    }
  }
  
  cout << n << endl;
  rep(i, 50) {
    if (i) cout << " ";
    cout << a[i];
  }
  cout << endl;


  
  return 0;
}

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

int main(void){
    double w, h;
    int x, y;
    cin >> w >> h >> x >> y;
    double area = w*h/2;
    int check;
    if(x*2==w && y*2==h)
        check = 1;
    
    else
        check = 0;
    cout << fixed << setprecision(6) << area << ' ' << check << endl;
    return 0;
}

Measured memory_bytes: 256
ary = gets.split(" ").map(&:to_i)
a = ary[0]
b = ary[1]

def max_calc(a, b)
  r = 1
  while r != 0
    r = a % b
    if r == 0
      return b
    else
      a = b
      b = r
    end
  end
end

if a > b
  max_calc = max_calc(a, b)
elsif a < b
  max_calc = max_calc(b, a)
else
  result = a
end

result = (a * b) / max_calc

puts result

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define PI 3.14159265358979
#define MOD 1000000007
#define ERR 0.00000000000001
#define NUM 200010

LL gojou(LL a){
    return a*a*a*a*a;
}

int main(){
    LL x, i, j;
    scanf("%lld",&x);
    for(i=-200;i<=200;i++){
        for(j = -200;j<=200;j++){
            if(pow(i,5)-pow(j,5)==x){
                printf("%lld %lld",i,j);
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 2592
def main():
    n =  int(input())
    ls = []
    for _ in range(n):
        a, b = map(int, input().split())
        ls.append([b,a])
    ls = sorted(ls)
    t=0
    for i in ls:
        t += i[1]
        if t > i[0]:
            print('No')
            exit(0)
    print('Yes')
if __name__ == '__main__':
    main()

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


using namespace std;

int main()
{
    int n;
	string s;
 	cin>>s;
  	n=s.size();
  	if(s[n-1]=='s')
      cout<<s<<"es"<<endl;
  	else
      cout<<s<<"s"<<endl;

    return 0;
}


Measured memory_bytes: 3552
import sys
input = sys.stdin.readline

n,m = map(int,input().split())

res = 0
h = list(map(int,input().split()))

edge = [[] for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)


for i in range(n):
    flag = True
    for e in edge[i]:
        if h[i] <= h[e]:
            flag = False
    if flag:
        res += 1
print(res)


Measured memory_bytes: 89456
#include <iostream>
#include <algorithm>
#include <numeric>

int64_t N, A, B;

int main()
{
	std::cin >> N >> A >> B;

	if ((B - A) & 1) {
		auto X1 = std::min(A - 1, N - B);


		std::cout << X1 + 1 + (B - A - 1) / 2 << std::endl;
	}
	else {
		std::cout << (B - A) / 2 << std::endl;
	}

	return 0;
}


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


int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    cin>>h[0];
    int a=0,mx=0;
    for(int i=1;i<n;i++){
        cin>>h[i];
        if(h[i-1]>=h[i]) a++;
        else {
            mx=max(mx,a);
            a=0;
        }
    }
    cout<<max(mx,a);

    return 0;
}

Measured memory_bytes: 640
def main():
        
    Height, Width, K = map(int, input().split())

    field = []
    ans = 0

    for i in range(Height):
        f = list(input())
        field.append(f)

    for i in range(2 ** Height):
            for k in range(2 ** Width):

                cnt = 0

                for j in range(Height):
                    for l in range(Width):

                        judge_h = (i >> j) & 1
                        judge_w = (k >> l) & 1
                        
                        if (not judge_h and not judge_w):
                            val = field[j][l]
                            if (val == '#'):
                                cnt += 1
                                
                if (cnt == K):
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9216
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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

int main()
{
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = a * x + b * y;
  for (ll i = 2; i < 200010; i += 2)	//cの枚数
  {
    ans = min(ans, c * i + a * max(x - i / 2, 0LL) + b * max(y - i / 2, 0LL));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 384
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n,m = na()
s = [na() for _ in range(n)]
c = [na() for _ in range(m)]

l = []
for i in s:
    for j in c:
        l.append(abs(i[0]-j[0]) + abs(i[1]-j[1]))
    a = l.index(min(l))
    print(a+1)
    l = []


Measured memory_bytes: 3064
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-11 20:19:28
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

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

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

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

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

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

    return ret % mod;
}

int factorial(int n) {
    int ret = 1;
    for (int i = 2; i <= n; i++)
        ret *= i;
    
    return ret;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];

    int a, b;
    a = b = 0;
    vector<int> v(n);
    iota(all(v), 1);
    do {
        
        //v, pを比較
        for (int i = 0; i < n; i++) {
            int diff = v[i] - p[i];
            if (diff < 0) {
                a++;
                break;
            } else if (diff > 0) break;
        }

        //v, qを比較
        for (int i = 0; i < n; i++) {
            int diff = v[i] - q[i];
            if (diff < 0) {
                b++;
                break;
            } else if (diff > 0) break;
        }
        
    } while (next_permutation(all(v)));

    cout << abs(a - b) << endl;

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

c = []
for i in range(N):
    c.append(0)


for i in range(K):
    d = int(input())
    ds = list(map(int,input().split()))
    for j in range(d):
        c[ds[j]-1] += 1

print(c.count(0))


Measured memory_bytes: 67764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int ans = 0;
        for (int i = 0; i< s.length();i++) {
            if (s.charAt(i) == t.charAt(i)) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <fstream>
#include <algorithm>


int main() {
    int a, b, x;
    scanf("%d%d%d", &x, &a, &b);
    int a1 = abs(x - a);
    int b1 = abs(x - b);
    if(a1 > b1)
        printf("B");
    else
        printf("A");
    return 0;
}


Measured memory_bytes: 128
//#include"pch.h"
#include<bits/stdc++.h>
using namespace std;
#define lol(i,n) for(int i=0;i<n;i++)
#define chmax(a,b) a=max(a,b);
typedef long long ll;
#define N 200010
class RAQxRMQ {
private:
	ll dat[2 * N], laz[2 * N];
	ll eval(ll k) {
		if (k < N) {
			laz[k * 2] += laz[k];
			laz[k * 2 + 1] += laz[k];
		}
		dat[k] += laz[k],laz[k]=0;
		return dat[k];
	}
public:
	void init() {
		lol(i, 2 * N)dat[i] = -1e17, laz[i] = 0;
	}
	void add(ll l, ll r, ll x) {
		l += N, r += N + 1;
		for (ll a = l, b = r; a < b; a >>= 1, b >>= 1) {
			if (a & 1)laz[a++] += x;
			if (b & 1)laz[--b] += x;
		}
		for (ll a = l, b = r; a + b; a >>= 1, b >>= 1) {
			dat[a / 2] = max(eval(a), eval(a ^ 1));
			dat[b / 2] = max(eval(b), eval(b ^ 1));
		}
	}
	ll maxi(ll l, ll r) {
		l += N, r += N + 1;
		for (ll d = 20; ~d; d--) {
			eval(l >> d); eval(r >> d);
		}
		ll res = -1e18;
		for (ll a = l, b = r; a < b; a >>= 1, b >>= 1) {
			if (a & 1)chmax(res, eval(a++));
			if (b & 1)chmax(res, eval(--b));
		}
		return res;
	}
	void upd(ll i, ll x) {
		ll val = maxi(i, i);
		add(i, i, max(0LL,x-val));
	}
};
ll n, d[N], q;
vector<ll> v[N];
void outs(ll x) {
	if (x <= -1e10)cout << "# ";
	else cout << x << " ";
}
int main() {
	cin >> n;
	lol(i, n)cin >> d[i];
	cin >> q;
	lol(i, q) {
		ll a, b; cin >> a >> b; a--;
		v[a].push_back(b);
	}
	RAQxRMQ seg; seg.init();
	seg.upd(0, 0);
	lol(i, n) {
		sort(v[i].begin(), v[i].end());
		for (auto to : v[i]) {
			seg.upd(to, seg.maxi(0, to - 1));
			//cout << to << " " << seg.maxi(0, to - 1) << endl;
		}
		//lol(i, 16)outs(seg.maxi(i, i)); cout << endl;
		ll val = (d[i] == 0 ? -1 : +1);
		seg.add(i +1, n+5, val);
	}
	ll ans = -seg.maxi(0, n+5);
	lol(i, n)ans += d[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16896
n = gets.chomp.to_i
s = []
n.times do
  s.push(gets.chomp)
end
ss = s.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h
sss = ss.sort {|a, b| a[1] <=> b[1]}
sss.reverse!
ans = []
num = sss.first[1]
sss.each do |k, v|
  if v == num
    ans.push(k)
  end
end
ans.sort!
ans.each do |a|
  puts a
end


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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
	int a[9];
	fori(9) cin >> a[i];
	int n, b[10];
	cin >> n;
	fori(n) cin >> b[i];

	fori(n) {
		int j = 0;
		for (; j < 9 && b[i] != a[j]; ++j) {
		}
		if (j >= 9) {
			continue;
		}
		a[j] = 0;
	}
	fori(3) {
		if (a[i * 3] + a[i * 3 + 1] + a[i * 3 + 2] == 0) {
			cout << "Yes";
			return 0;
		}
		if (a[i] + a[i + 3] + a[i + 6] == 0) {
			cout << "Yes";
			return 0;
		}
	}
	if (a[0] + a[4] + a[8] == 0 || a[2] + a[4] + a[6] == 0) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a,b = map(int, input().split())
    p = list(map(int, input().split()))
    c,d,e = 0,0,0
    for i in range(n):
        if p[i]<=a:
            c += 1
        elif p[i]>b:
            e += 1
        else:
            d += 1
    print(min(c,d,e))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3436
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int p[2100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	long long ret=0;
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if(p[i]<p[j]){
				if(i<j){
					ret+=(long long)b*(b-1)/2;
					ret%=mod;
				}else{
					ret+=(long long)b*(b+1)/2;
					ret%=mod;
				}
			}
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
char c[5];
bool b=0;
int main()
{
    cin>>c;
    int l=strlen(c);
    for(int i=0;i<l;i++)
        if(c[i]=='7')
        b=1;
    if(b)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  cout << "2018/01/";
  cout << s.at(8) << s.at(9) << endl;
}


Measured memory_bytes: 256
import copy
a=int(input())
b=list(map(int,input().split()))
c=copy.deepcopy(b)
for i in range(a-1):
    if b[i]>b[i+1]:
        b[i+1]=b[i]
ans=0
for i in range(a):
    ans+=b[i]-c[i]
print(ans)

Measured memory_bytes: 33304
N = int(input())
list = input().split()
T = list[0]
A = list[1]
list2 = input().split()
H = []
T_mean = []
minimum = []
for i in range(N):
    H.append(list2[i])
    T_mean.append(int(T)-int(H[i])*0.006)
    minimum.append(abs(T_mean[i] - int(A)))


print(minimum.index(min(minimum))+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='?'){
                s[i] = 'D';
        }
    }
    cout << s << endl;
    
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vvl path(n);
	REP(i, n - 1) {
		ll a; cin >> a;
		path[a - 1].push_back(i + 1);
	}
	function<ll(ll)> dfs = [&](ll cur) {
		vl a;
		for (auto&& x : path[cur]) {
			a.push_back(dfs(x));
		}
		sort(ALL(a));
		reverse(ALL(a));

		ll ans = 0;
		REP(i, a.size()) {
			ans = max<ll>(ans, a[i] + i + 1);
		}
		return ans;
	};
	cout << dfs(0) << endl;


	return 0;
}

Measured memory_bytes: 13568
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  ll n;
  cin >> n;
  ll m = 1e9 + 7;
  ll ans = 1;
  forn(i,n){
    ll j = i + 1;
    ans *= j;
    ans %= m;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

1
1000000000000000000


*/

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vi c(s.length() + 1, 0);
  for (int i = 1; i < s.length(); i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') {
      c[i] = c[i - 1] + 1;
    } else {
      c[i] = c[i - 1];
    }
  }
  vi l(q), r(q);
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }
  // for (int i = 0; i < s.length(); i++) {
  //   printf("%d ", c[i]);
  // }
  // printf("\n");
  for (int i = 0; i < q; i++) {
    cout << c[r[i] - 1] - c[l[i] - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 2256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int oo = 1e9;

struct segment_tree{
	
	
	vector<int> st;
	
	segment_tree(int n) : st(4 * n){
		
	}
	
	void update(int node, int b, int e, int pos, int v){
		if(b == e)
			st[node] = v;
		else{
			int m = (b + e) >> 1;
			int l = node << 1;
			int r = l | 1;
			
			if(pos <= m)
				update(l, b, m, pos, v);
			else
				update(r, m + 1, e, pos, v);
			
			st[node] = min(st[l], st[r]);
		}
	}
	
	int query(int node, int b, int e, int i, int j){
		if(b >= i && e <= j)
			return st[node];
		
		if(b > j || e < i)
			return oo;
		
		int m = (b + e) >> 1;
		int l = node << 1;
		int r = l | 1;
		
		int L = query(l, b, m, i, j);
		int R = query(r, m + 1, e, i, j);
		
		return min(L, R);
	}
	
};

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	
	n++;
	
	string s;
	cin >> s;
	
	segment_tree st(n);
	
	for(int i = 0; i < n; i++){
		if(s[i] == '0')
			st.update(1, 0, n - 1, i, i);
		else
			st.update(1, 0, n - 1, i, oo);
	}
	
	vector<int> ans;

	int pos = n - 1;
	while(pos > 0){
		int hi = pos - 1;
		int lo = max(0, pos - k);
		int p = st.query(1, 0, n - 1, lo, hi);
		
		if(p == oo){
			cout << -1 << endl;
			return 0;
		}
		
		ans.push_back(pos - p);
		pos = p;
	}
	
	reverse(ans.begin(), ans.end());
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i] << " \n"[i + 1 == ans.size()];

	return 0;
}

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

int main(){
    int w, h , x, y, r;
    cin >> w >> h >> x >> y >> r;

    if (( x - r >= 0 && x + r <= w ) && (y - r >= 0 && y + r <= h )) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}




Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
		String str = rd.readLine();
	    String[] sl = str.split(" ");
	    int n = Integer.parseInt(sl[0]);
	    int a = Integer.parseInt(sl[1]);
	    str = rd.readLine();
	    sl = str.split(" ");
	    int x[] = new int[51];
	    long v[][][] = new long[51][51][2501];
	    for(int i = 1; i <= n; i++)
		{
			x[i] = Integer.parseInt(sl[i - 1]);
		}
	    
	    v[1][1][x[1]] = 1;
	    v[1][0][0] = 1;
	    for(int i = 2; i <= n; i++)
	    {
	    	for(int j = 0; j <= i; j++)
	    	{
	    		for(int k = 0; k <= 50 * i; k++)
	    		{
	    			v[i][j][k] += v[i - 1][j][k];
	    		}
	    	}
	    	for(int j = 1; j <= i; j++)
	    	{
	    		for(int k = x[i]; k <= 50 * i; k++)
	    		{
	    			v[i][j][k] += v[i - 1][j - 1][k - x[i]];
	    		}
	    	}
	    }
	    
	    long ans = 0;
	    for(int i = 1; i <= n; i++)
	    {
	    	for(int j = 1; j <= n; j++)
	    	{
	    		ans += v[i][j][a * j] - v[i - 1][j][a * j];
	    	}
	    }
	    
		System.out.println(ans);
		
  	}
}

Measured memory_bytes: 85832
#include <bits/stdc++.h>
using namespace std;
double x[1005];
double y[1005];
int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<n;i++)cin>>y[i];
	double k1,k2,k3,k4;
	k1=k2=k3=k4=0;
	for(int i=0;i<n;i++){
		k1+=abs(x[i]-y[i]);
		k2+=abs((x[i]-y[i])*(x[i]-y[i]));
		k3+=abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
		k4=max(abs(x[i]-y[i]),k4);
	}
	printf("%.10f\n",k1);
	printf("%.10f\n",pow(k2,0.5));
	printf("%.10f\n",pow(k3,1.0/3));
	printf("%.10f\n",k4);
	return 0;
}


Measured memory_bytes: 3380