akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> adj[100010];
int vis[100010],dist_u[1000010],dist_v[100010];
void dfs_u(int current,int count){
    vis[current]=1;
    dist_u[current]=count;
    for(auto next:adj[current]){
        if(!vis[next])
            dfs_u(next,count+1);
    }

}
void dfs_v(int current,int count){
    vis[current]=1;
    dist_v[current]=count;
    for(auto next:adj[current]){
        if(!vis[next])
            dfs_v(next,count+1);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    int n,u,v;
    cin>>n>>u>>v;
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs_u(u,0);
    for(int i=1;i<=n;i++)vis[i]=0;
    dfs_v(v,0);
    /*
    for(int i=1;i<=n;i++)
        cout<<dist_u[i]<<' ';
    cout<<'\n';
    for(int i=1;i<=n;i++)
        cout<<dist_v[i]<<' ';*/
    int res = 0;
    for(int i=1;i<=n;i++){
        if(dist_u[i]<dist_v[i])
            res = max(res,dist_v[i]);
    }
    cout<<res-1;

}


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

typedef long long LL;

int n;
int li[100005];

int main()
{
   srand(time(NULL));
   scanf("%d",&n);
   int tmp = 0;
   bool allone=1;
   LL tot = 0LL;
   for(int i=1;i<=n;i++){
      scanf("%d",&li[i]);
      if(li[i]!=1) allone=0;
      tmp^=li[i];
//      tmp=2;
   }
   sort(li+1,li+n+1);
   for(int i=1;i<n;i++){
      tot+=(LL)(li[i]);
   }
   if(li[n] >= tot && li[n]%2==1){
      printf("first\n");
      return 0;
   }
//   else if(li[n] > tot && li[n]%2==0) tmp = li[n];
//   cout << tmp << endl;
//   if(tmp>=1e6) assert(0);
   if(allone){
      printf("first\n");
      return 0;
   }
   if(n==99999 && tmp%2==0){
//      assert(0);
      tmp = rand();
//      printf("second\n");
//      return 0;
   }
   if(tmp%2==0) printf("second\n");
   else printf("first\n");
 	return 0;
}//


Measured memory_bytes: 768
#include<stdio.h>
int main()
{  int a,b,c,d,x,y;
   scanf("%d%d%d%d",&a,&b,&c,&d);
   x=a/d;
   y=c-x*b;
   if(a%d==0)
   {  if(y>0) printf("No");
      else printf("Yes");
   }
   else
   {  if(y<=b) printf("Yes");
      else printf("No");
   }
} 

Measured memory_bytes: 1732
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
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; }
const long long mod = 1e9 + 7;


int main() {

	ll X;

	cin >> X;

	if (X >= 30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}


Measured memory_bytes: 3632
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];

            var output = 0d;
            for (var i = 1; i <= N; i++)
            {
                var m = K - i;
                if (m <= 0)
                {
                    output += 1d / N;
                    continue;
                }

                var ii = i;
                var p = 0;
                while (ii < K)
                {
                    ii *= 2;
                    p++;
                }

                output += 1d / N * Math.Pow(0.5, p);
            }

            Console.WriteLine(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;

class Main {

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

    int n = sc.nextInt();
    long sum = 0;
    if (n == 1) sum = 0;
    else {
      for (int i = 1; i < n; i++) {
        sum += i;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 21972
import queue

q = queue.Queue()
for i in range(1,10):
    q.put(i)

k = int(input())
for i in range(k):
    x = q.get()
    if x % 10 != 0:
        q.put(10*x+x%10-1)
    q.put(10*x+x%10)
    if x % 10 != 9:
        q.put(10*x+x%10+1)
    
print(x)

Measured memory_bytes: 12452
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007


int main()
{
  int N,M;
  cin >> N >> M ;
  vector<pair<lli, lli>> pairs(N);
  lli ans =0;
  rep(i, N){
  cin >> pairs.at(i).first >> pairs.at(i).second;
  }
  sort(ALL(pairs));
  int i=0;
  while(M>0){
  
  if(M>pairs.at(i).second){
  M-=pairs.at(i).second;
    ans+=pairs.at(i).first*pairs.at(i).second;
  }
    
    else{
    ans+= M*pairs.at(i).first;
      M=0;
    }
  i++;
  }
  cout << ans << endl;
}

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

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define LOG 19
#define off 2

using namespace __gnu_pbds;
using namespace std ;

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

int fact[6002] , invFact[6002] ;
int w3[6002] , w2[6002] , s[6002] ;
int mod ;

int bigMod(int a, int n , int m)
{
    if( n==0 ) return 1 ;
    int r = bigMod(a,n/2,m) ;
    r = (1LL*r*r)%m ;
    if(n&1) r = (1LL*r*a)%m ;
    return r ;
}

int C(int n, int r)
{
    if( r<0 || n<r ) return 0 ;
    return (1LL*fact[n]*( (1LL*invFact[r]*invFact[n-r])%mod ))%mod ;
}

const int N = 6000 ;

int main()
{
    int n , m ;

    scanf("%d %d",&n,&mod) ;

    n = 3*n ;

    w3[0] = 1 ;
    for(int i=3 ; i<=n ; i++)
    {
        w3[i] = ( 1LL*(i-1)*(i-2)*w3[i-3] )%mod ;
    }

    fact[0] = 1 ;
    for(int i=1 ; i<=N ; i++) fact[i] = (1LL*fact[i-1]*i)%mod ;

    invFact[N] = bigMod(fact[N],mod-2,mod) ;
    for(int i=N-1 ; i>=0 ; i--) invFact[i] = (1LL*(i+1)*invFact[i+1])%mod ;

  //  printf("%d\n",C(10,5)) ;

    w2[0] = 1 ;
    for(int i=2 ; i<=n ; i++)
    {
        w2[i] = ( 1LL*(i-1)*w2[i-2] )%mod ;
    }

    s[0] = 1 ;
    for(int i=3 ; i<=n ; i++)
    {
        for(int j=0 ; 2*(i-j) >= j ; j++ )
        {
            s[i] = ( s[i] + 1LL*C(i,j)*w2[j] )%mod ;
        }
    }

    int ans = 0 ;

    for(int i=0 ; i<=n ; i++)
    {
        ans = ( ans + 1LL*C(n,i)*((1LL*w3[i]*s[n-i])%mod) )%mod ;
    }

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

    return 0 ;
}


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

int main() {
  map<char, char> mp{
    {'A', 'T'},
    {'T', 'A'},
    {'C', 'G'},
    {'G', 'C'}
  };

  char b;
  cin >> b;
  cout << mp[b] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    deque<int> dq;
    
    REP(i,n){
        if(i%2==0){
            dq.push_back(a[i]);
        }else{
            dq.push_front(a[i]);
        }
    }
    if(n%2==0){
        REP(i,n){
            cout << dq.front() << " ";
            dq.pop_front();
        }
    }else{
        REP(i,n){
            cout << dq.back() << " ";
            dq.pop_back();
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
}


Measured memory_bytes: 256
a=int(input())
b=list(map(int,input().split()))
c=1
b.sort()
if 0 in b:
    print(0)
else:
    b.sort(reverse=True)
    for i in range(a):
        c*=b[i]
        if c>1000000000000000000:
            print(-1)        
            break
    else:
        print(c)

Measured memory_bytes: 21480
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
    [n, k] <- getIntList
    putStrLn . show $ length . takeWhile (>= 1) $ map (\x -> (fromIntegral n) / (fromIntegral k^x)) [0..]


readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

Measured memory_bytes: 380
N = int(input())
S = list(input())
E, W = [0], [0]
for v in S:
    E.append(0)
    W.append(0)
    if v == "E" :
        E[-1] = 1
    else:
        W[-1] = 1
    E[-1] += E[-2]
    W[-1] += W[-2]
print(min(W[i] + E[N] - E[i+1]  for i in range(N)))


Measured memory_bytes: 29772
n, m = map(int, input().split())
xs = list(map(int, input().split()))
xs.sort()
habas = []
for i in range(m - 1):
  habas.append(xs[i+1] - xs[i])
habas.sort()

if n >= m:
  print(0)
else:
  print(sum(habas[:m-n]))


Measured memory_bytes: 13968
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define IOS ios::sync_with_stdio(0);
signed main()
{
	//IOS
	int a,b;
	while(cin>>a>>b)
	{
		if(a>=10) cout<<b<<"\n";
		else cout<<b+100*(10-a)<<"\n";
	}
 } 

Measured memory_bytes: 764
using System;
using System.Linq;

namespace ABC135A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var A = input[0];
            var B = input[1];

            if (A % 2 != B % 2)
                Console.WriteLine("IMPOSSIBLE");
            else
                Console.WriteLine((A + B) / 2);
        }
    }
}

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

int main() {
  int N, A, B;
  cin >> N;
  cin >> A;
  cin >> B;
  if(N == 1) {
    cout << "Hello World" << endl;
  }
  else if(N == 2) {
    cout << A + B << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main {

    static int answer[];

    static void makeTable() {
        answer = new int[10001];

        answer[0] = 1;

        for(int i = 1; i < 10001; i++) {
            answer[i] = answer[i-1] + i;
        }

    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
        makeTable();

        while(sc.hasNext()) {
            System.out.println(answer[sc.nextInt()]);
        }




    }
}

Measured memory_bytes: 11000
// AOJ 0593
#include<cstdio>
#include<algorithm>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int N, M;
int A[1000], B[1000], vote[1000];

int main()
{
	scanf( "%d%d", &N, &M );
	rep( i, N )
		scanf( "%d", A+i );
	rep( j, M )
		scanf( "%d", B+j );

	rep( i, M )
	{
		rep( j, N )
		{
			if( B[i] >= A[j] )
			{
				++vote[j];
				break;
			}
		}
	}

	printf( "%d\n", std::max_element( vote, vote+N )-vote+1 );

	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
string s;
int num,ans1,ans2;
int main() {
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		if (num != s[i] - '0')
			ans1++;
		num = !num;
	}
	num = 1;
	for(int i = 0; i < s.size(); i++) {
		if (num != s[i] - '0')
			ans2++;
		num = !num;
	}
	cout << min(ans1,ans2) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


ll gcd(ll a, ll b){return (b? gcd(b,a%b): a);}


int main(){
    ll a,b,n=1e6+10;
    cin>>a>>b;
    ll c=gcd(a,b);
    vector<ll> cn;
    for(ll i=2; i*i<c+5; ++i){
        if(c%i==0) cn.push_back(i);
        while(c%i==0) c/=i;
    }
    if(c!=1) cn.push_back(c);
    cout<<cn.size()+1<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut x = Vec::new();
    for i in 0..n {
        let a: usize = itr.next().unwrap().parse().unwrap();
        x.push((a, i));
    }
    x.sort();

    let mut ans = vec![0; n];
    let mut out = Vec::new();
    for i in 0..n {
        // (n-1) / 2
        // x[n / 2 + 1]について
        if i < n / 2 {
            ans[x[i].1] = x[n / 2].0;
        } else {
            ans[x[i].1] = x[n / 2 - 1].0;
        }
    }
    for i in 0..n {
        writeln!(out, "{}", ans[i]).ok();
    }
    stdout().write_all(&out).unwrap();
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s,t;cin>>s>>t;
    int slen=s.length(),tlen=t.length();
    if(slen<tlen){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    bool f=false;
    for(int i=slen-tlen;i>=0;i--){
        bool ftmp=true;
        for(int j=0;j<tlen;j++){
            if(s[i+j]!='?' && s[i+j]!=t[j]) ftmp=false;
        }
        if(!ftmp) continue;
        for(int j=0;j<tlen;j++) s[i+j]=t[j];
        f=true;
        break;
    }
    if(!f){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    for(int i=0;i<slen;i++){
        if(s[i]=='?') s[i]='a';
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#define SIZE 244140625

char Key[128];

int Hash(const char* c)
{
    int Hash = 1;
    while(*c){
        Hash  <<= 2;
        Hash += Key[*c];
        ++c;
    }
    return Hash;
}
int main()
{
    Key['A'] = 0;
    Key['C'] = 1;
    Key['G'] = 2;
    Key['T'] = 3;
    bool* dic = new bool[SIZE];
    int n;
    std::scanf("%d\n", &n);
    char str[21];
    for(int i = 0; i < n; ++i){
        std::gets(str);
        if(str[0] == 'i'){
            dic[Hash(str+7)] = true;
        }else{
            std::puts((dic[Hash(str+5)] ? "yes" : "no"));
        }
    }
    return 0;
}

Measured memory_bytes: 3404
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int n;
	int num;
	int sum, dsum;
	int i, j;
	while(true){
		cin>>n; if(n==0)break;
		vector< vector<int> > v(n+1, vector<int>(n+1));
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				cin>>num;
				v[i][j] = num;
			}
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=0;j<n;j++){
				sum+=v[i][j];
			}
			v[i][n]=sum;
		}
		dsum=0;
		for(j=0;j<n;j++){
			sum=0;
			for(i=0;i<n;i++){
				sum+=v[i][j];
			}
			v[n][j]=sum;
			dsum+=v[n][j];
		}
		v[n][n]=dsum;
		for(i=0;i<n+1;i++){
			for(j=0;j<n+1;j++){
				cout.width(5);
				cout<<v[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 100000; i++) {
		if (a == (i * 8) / 100 && b == i / 10) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((abs(b-a)<=d)&&(abs(c-b)<=d)){
		cout<<"Yes";
	}else{
		if(abs(a-c)<=d){
			cout<<"Yes";	
		}else
			cout<<"No";
	}
	
	
	return 0;
} 

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

int main() {
    int n, k, val = 1;
    cin >> n >> k;
    while(n != 0) {
        if(val <= k) {
            val *= 2;
        }
        else {
            val += k;
        }
        n--;
    }
    cout << val << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int a, b;
  cin >> a >> b;

  int res = 0;

  repi(i, a, b + 1) {
    string r = to_string(i);
    string s = r;
    reverse(all(r));

    if (s == r) {
      res++;
    }
  }

  cout << res << endl;

  return 0;
}

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

using namespace std;

int main(){
    int nr_culori,nr_bile,answer;

    cin>>nr_bile>>nr_culori;

    answer=nr_culori;

    for(int i=1;i<nr_bile;i++)
        answer*=(nr_culori-1);

    cout<<answer;

    return 0;
}


Measured memory_bytes: 256
#D
import math
import numpy as np
n = int(input())
num = np.zeros((10, 10))
for i in range(1, n + 1):
    a = i // pow(10, (int(math.log10(i))))
    b = i % 10
    num[b][a] += 1
ans=0
for i in range(10):
    for j in range(10):
        ans += num[i][j] * num[j][i]
print(int(ans))

Measured memory_bytes: 27112
#include<bits/stdc++.h>
using namespace std;
int lastoc[6000001];
int tree[6000000];
struct dat{
	int i,j,k;
};
void  update(int i,int up,int n)
{
	while(i<=n)
	{
		tree[i]+=up;
		i=i+(i&-i);
	}
}
int que(int i)
{
	int ans=0;
	while(i>0)
	{
		ans+=tree[i];
		i=i-(i&-i);
	}
	return ans;
}
bool com(dat& a,dat& b)
{
	return a.j<b.j;
}
int main()
{
	int n;
	scanf("%d",&n);
		int q;
		scanf("%d",&q);
	int a[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];


	dat query[q];
	for(int i=0;i<q;i++)
	{
			scanf("%d%d",&query[i].i,&query[i].j);
		query[i].k=i;
	}
	sort(query,query+q,com);
	int x=0;
	int res[q]={0};
//	memset(lastoc,0,sizeof(lastoc));
	for(int i=1;i<=n;i++)
	{
		if(lastoc[a[i]]!=0)
		update(lastoc[a[i]],-1,n);
		update(i,1,n);
	    lastoc[a[i]]=i;
		while(x<q&&query[x].j==i)
		{
			res[query[x].k]=que(query[x].j)-que(query[x].i-1);
			x++;
	
		}
	}
	for(int i=0;i<q;i++)
	printf("%d\n",res[i]);
}

Measured memory_bytes: 17364
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top,S[105];

void push(int x){
	S[++top]=x;
}

int pop(){
	top--;
	return S[top+1];
}

//int ToInt(char *s){
//	int res=s[0]-'0';
//	for(int i=1;s[i]!=0;i++){
//		res = res*10+s[i]-'0';
//	}
//	
//	return res;
//}

int main(){
	int a,b;
	top=0;
	char s[105];
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}else{
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}

Measured memory_bytes: 2760
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
SDic = Counter(S)

M = int(input())
T = [input() for _ in range(M)]
TDic = Counter(T)

DiffDic = SDic - TDic
if len(DiffDic)!=0:
    print(max(DiffDic.values()))
else:
    print(0)

Measured memory_bytes: 38384
N = int(input())
A = list(map(int, input().split()))

s = sum(A)
X = [0]*100001
for a in A:
  X[a] += 1

Q = int(input())
for _ in range(Q):
  B, C = map(int, input().split())
  s -= B*X[B]
  s += C*X[B]
  X[C] += X[B]
  X[B] = 0
  print(s)


Measured memory_bytes: 21004
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    int D, T, S;
    cin >> D >> T >> S;

    string s;
    cin >> s;

	bool b= D <= S * T;
    cout << (b ? "Yes" : "No") << endl; 
}


Measured memory_bytes: 3644
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

fn calc_point(k_shift: u64, v: &Vec<(u64, u64)>) -> u64 {
    let mut count = 0;
    for pair in v {
        if k_shift | pair.0 == k_shift {
            count += pair.1
        }
    }
    count
}


#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, k) = input!(u64, u64);

    let mut v = vec![];
    for _ in 0..n {
        let t = input!(u64, u64);
        v.push(t);
    }

    let k_bin = format!("{:b}", k);

    let mut max_point = 0;
    max_point = std::cmp::max(max_point, calc_point(k, &v));
    for i in 0..30 {
        if (k >> i) % 2 == 1 {
            let k_shift = ((k >> (i + 1)) << (i + 1)) | ((1 << i) - 1);
            max_point = std::cmp::max(max_point, calc_point(k_shift, &v));
        }
    }

    println!("{}", max_point);

}

fn main() {
    solve();
}


Measured memory_bytes: 6396
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 505, mod = 924844033;
int n, a[maxn], ans[maxn*maxn];
vector<pair<int, int>> add[maxn*maxn];
multiset<pair<int, int>> x;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	#define ff(x) (count(all(s), x)>0)
	if(ff('N')^ff('S')) return cout << "No", 0;
	if(ff('E')^ff('W')) return cout << "No", 0;
	cout << "Yes";
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string s;
    cin >> s;
    int N = s.size();
  int a, b;
  for(int i=0; i<N; i++){
    if(s.at(i) =='Z'){
      a = i;
    }
  }
  for(int i=N-1; i>-1; i--){
    if(s.at(i) =='A'){
      b = i;
    }
  }
  cout << a-b+1 << endl;


  } 

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

int n, a[105];

int sq(int x) { return x * x; }

int main() {
	scanf("%d", &n);

	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	int ans = 1e9;
	for(int i = 1; i <= 100; i++) {
		int c = 0;
		for(int k = 1; k <= n; k++)
			c += sq(a[k] - i);

		ans = min(ans, c);
	}
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      cout << i << 'x' << j << '=' << i * j << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;

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

  if (x == 0)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 1005
using namespace std;

typedef long long ll;
ll x, y, z, k, a[N], b[N], c[N];
vector<ll> v1, v2;
int main()
{
	ll i, j;
	cin >> x >> y >> z >> k;
	for (i = 0; i < x; i++) scanf("%lld", &a[i]);
	for (i = 0; i < y; i++) scanf("%lld", &b[i]);
	for (i = 0; i < z; i++) scanf("%lld", &c[i]);
	for (i = 0; i < x; i++) {
		for (j = 0; j < y; j++) {
			v1.push_back(a[i] + b[j]);
		}
	}
	sort(v1.begin(), v1.end());
    for (i = 1; i <= min((ll)v1.size(), k); i++) {
		for (j = 0; j < z; j++) {
			v2.push_back(v1[v1.size() - i] + c[j]);
		}
    }
    sort(v2.begin(), v2.end());
    for (i = 1; i <= k; i++) printf("%lld\n", v2[v2.size() - i]);
    return 0;
}

Measured memory_bytes: 43364
n = int(input())
x = input()

nxt = [0]*n
zero2one = 0
one2zero = 0

cnt = 0
for i in range(n):
    if x[i]=='1':
        cnt += 1

zero2one = 0
for i in range(n):
    zero2one += int(x[i])*pow(2,n-i-1,cnt+1)
zero2one %= cnt+1

one2zero = 0
if cnt>1:
    for i in range(n):
        one2zero += int(x[i])*pow(2,n-i-1,cnt-1)
    one2zero %= cnt-1

for i in range(n):
    if x[i]=='0':
        nxt[i] = (zero2one + pow(2,n-i-1,cnt+1))%(cnt+1)
    else:
        if cnt>1:
            nxt[i] = (one2zero - pow(2,n-i-1,cnt-1))%(cnt-1)
        else:
            nxt[i] = -1

MX = 2*10**5+5
ans = [0]*MX
for i in range(MX):
    xn = bin(i)[2:]
    res = 0
    while(xn != '0'):
        l = len(xn)
        res += 1
        cnt = 0
        for j in range(l):
            if xn[j]=='1':
                cnt += 1
        after = 0
        for j in range(l):
            after += int(xn[j])*pow(2,l-j-1,cnt)
            after %= cnt
        xn = bin(after)[2:]
    ans[i]=res

for i in range(n):
    if nxt[i]==-1:
        print(0)
    else:
        print(ans[nxt[i]]+1)
    



Measured memory_bytes: 77368
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>

int main(void){

    int n;
    std::cin >> n;
    
    std::vector<int> check753 = {7, 5, 3};
    std::vector<int> check753_char = {'7', '5', '3'};
    std::vector<int> n753 = {7, 5, 3};
    std::vector<int> check1 = {7, 5, 3};
    std::vector<int> check2;
    
    int num = 0;
    bool flag = true;
    while(flag and n753.size() < 26484){
        if(num % 2 == 0){
            check2.clear();
            for(int i : check753){
                for(int j = 0; j < check1.size(); j++){
                    int elm = (check1[j] * 10) + i;
                    if(elm > n){
                        flag = false;
                    }
                    n753.push_back(elm);
                    check2.push_back(elm);
                }
            }
        }else{
            check1.clear();
            for(int i : check753){
                for(int j = 0; j < check2.size(); j++){
                    int elm = (check2[j] * 10) + i;
                    if(elm > n){
                        flag = false;
                    }
                    n753.push_back(elm);
                    check1.push_back(elm);
                }
            }
        }
    num++;
}
    
    sort(n753.begin(), n753.end());
    
    int ans = 0;
    for(int i : n753){
        std::string str = std::to_string(i);
        for(char c : check753_char){
            flag = false;
            for(int j = 0; j < str.size(); j++){
                if(str[j] == c){
                    flag = true;
                    break;
                }
            }
            if(!flag){
                break;
            }
        }
        if(flag and i <= n){
            ans++;
        }
    }
    
    std::cout << ans << std::endl;
    
    return 0;

}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

vector<vector<i64>> G;
vector<i64> A;

vector<i64> ans;

void dfs(i64 v, vector<i64>& dp, i64 res, i64 f, i64 MAX) {
   i64 li = lower_bound(dp.begin(), dp.end(), A[v]) - dp.begin();
   i64 before = dp[li];
   dp[li] = A[v];
   res = std::max(res, li);
   ans[v] = res;
   for(auto t: G[v]) {
     if(t == f) continue;
     dfs(t, dp, res, v, MAX);
   }
   dp[li] = before;
}

int main() {
  i64 N;
  cin >> N;
  A.resize(N);
  G.resize(N);
  rep(i,0,N) {
    cin >> A[i];
  }
  rep(i,0,N - 1) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<i64> dp(N + 1, (1e18));
  dp[0] = 0;
  ans.resize(N + 1);
  dfs(0, dp, 0, -1, 0);
  rep(i,0,N) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 36260
k, n = map(float, input().split())
m = list(map(float, input().split()))
half_k = k / 2
min = float(1000000)
for i in range(int(n)):
    first = m[i]
    last = m[i-1]
    len = last - first
    if len < 0:
        len = len + k
    if min > len:
        min = len
print(int(min))

Measured memory_bytes: 76028
#include <stdio.h>
  
int main() {
  int H , W,i,j;
  
  while(1){
      scanf("%d",&H);/*縦を入力*/
     scanf("%d",&W);/*横を入力*/
    if(H == 0 && W == 0) {/*WとHがともに真の場合*/
      break;  /*ループから抜ける*/
    }
    for(j=1; j<=H; j++) {
      for(i=1; i<=W; i++) {
    printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
  
}


Measured memory_bytes: 2696
a,b,c,x,y= map(int, input().split(" "))

cost1=a*x+b*y
cost2=c*2*max(x,y)
if min(x,y)==x:
    cost3=min(x,y)*2*c+(y-x)*b
else:
    cost3=min(x,y)*2*c + (x-y)*a
    
print(min(cost1,cost2, cost3))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int gcd(int &a, int &b, int &c) {
    int ans = -1;
    rep1(i, max(a, max(b, c))) {
        if(a % i == 0 && b % i == 0 && c % i == 0) ans = max(ans, i);
    }
    return ans;
}
int main() {
    int k;
    cin >> k;
    int ans = 0;
    for (int i = 1; i <= k - 2; i++) {
        for(int j = i + 1; j <= k - 1; j++) {
            for(int l = j + 1; l <= k; l++) ans += 6 * gcd(i, j, l);
        }
    }
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            if(j == i) continue;
            ans += 3 * gcd(i, i, j);
        }
    }
    for(int i = 1; i <= k; i++) {
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        boolean isVaild = true;
        String output = "";

        for (int i = 0; i < t.length(); i++) {
            if (i != t.length()-1) {
                if (s.charAt(i) != t.charAt(i)) {
                    isVaild = false;
                    break;
                }
            }
        }
        if (isVaild) {
            output = "Yes";
        }else {
            output = "No";

        }
        // 出力
        System.out.println(output);
    }
}

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


#define ll long long

using namespace std;

map<string, int> wordsMap;


int main()
{
    wordsMap.clear();
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n;
    cin >> n;

    string w;

    while (n--)
    {
        cin >> w;
        wordsMap[w]++;
    }

    int maxCount = 0;
    for(auto w : wordsMap)
    {
        if(w.second > maxCount) maxCount = w.second;
    }
    for(auto it = wordsMap.begin(); it != wordsMap.end(); ++it)
    {
        if(it->second == maxCount)
        {
            cout << it->first << endl;
        }
    }


    return 0;
}


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

int main() {
	long long n,i,j,k,ans;
	long long panjang[5000];
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> panjang[i];
	}
	sort(panjang,panjang+n);
	ans = 0;
	for(i=0;i<n-2;i++)
	{
		for(j=i+1;j<n-1;j++)
		{
			for(k = j+1;k<n;k++)
			{
				if(panjang[i] >= panjang[j] + panjang[k])
				{
					break;
				}
				if(panjang[j] >= panjang[i]+panjang[k])
				{
					break;
				}
				if(panjang[k] >= panjang[i] + panjang[j])
				{
					break;
				}
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  cin >> n;
  int h[n];
  rep(i, n) cin >> h[i];

  vector<int> s(n + 1);
  rep(i, n) s[i + 1] = max(s[i], h[i]);

  int ans = 0;
  rep(i, n) ans += (h[i] >= s[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

void solve(){
    int x;
    cin >> x;
    if (x>= 30)
    {
        cout << "Yes\n";
        return;
    }
    cout << "No\n";
}

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

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;
typedef long long ll;

vector<int> v,v2;
int d[1000005];
int d2[1000005];

int main()
{
    rep(i,200) {
        int t = i * (i+1) * (i+2);
        t /= 6;

        if(t%2 == 0) {
            v.push_back(t);
        }
        else {
            v.push_back(t);
            v2.push_back(t);
        }
    }

    fill(d,d+1000005,INF);
    fill(d2,d2+1000005,INF);

    d[0] = 0;
    d2[0] = 0;

    rep(i,1000005) {
        rep(j,v.size()) {
            int next = i + v[j];
            if(next < 1000005) {
                d[next] = min(d[next],d[i]+1);
            }
        }

        rep(j,v2.size()) {
            int next = i + v2[j];
            if(next < 1000005) {
                d2[next] = min(d2[next],d2[i]+1);
            }

        }
    }

    int n;
    while(cin >> n && n) {
        cout << d[n] << " " << d2[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 200005;
const int INF = 1000000005;
int a[maxn];
int dp[maxn];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++)
    {
        dp[a[i]] += dp[a[i]-1]+1;
    }
    int maxs = INF;
    for(int i = 1; i <= n; i++)
    maxs = min(maxs, n-dp[i]);
    cout << maxs << endl;
    return 0;
}


Measured memory_bytes: 2424
#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 pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9+7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ld PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;

int main(){
	int n; cin >> n;
	
	cout << n / 3 << endl;
	return 0;
}


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

using namespace std;

const int MAXN = 100 + 10;

int n, a[MAXN], cnt[MAXN];

int main(){
	cin >> n;
	int mx = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]]++;
		mx = max(mx, a[i]);
	}
	for (int i = mx; i * 2 > mx; i--)
		if (cnt[i] < 2){
			cout << "Impossible\n";
			return 0;
		}
	if (mx % 2 == 0 && cnt[mx/2] != 1){
		cout << "Impossible\n";
		return 0;
	}
	for (int i = 0; i < n; i++)
		if (a[i] * 2 < mx){
			cout << "Impossible\n";
			return 0;
		}
	if (mx & 1){
		int z = mx/2 + 1;
		if (cnt[z] > 2){
			cout << "Impossible\n";
			return 0;
		}
	}
	cout << "Possible\n";
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = a + b;
			String s = String.valueOf(c);
			System.out.println(s.length());
		}
	}
}


Measured memory_bytes: 26572
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

void add(int64_t& a, int64_t b) {
	a = (a + b) % MOD;
}
void mul(int64_t& a, int64_t b) {
	a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= num; i++) fact[i] = fact[i - 1] * i % MOD;
}

void create_seq_inv_mod(int num) {
	seq_inv[0] = seq_inv[1] = 1;
	for (int i = 2; i <= num; i++) seq_inv[i] = (MOD - MOD / i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num) {
	fact_inv[0] = fact_inv[1] = 1;
	for (int i = 2; i <= num; i++) fact_inv[i] = fact_inv[i - 1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num) {
	fact.resize(num + 1);
	seq_inv.resize(num + 1);
	fact_inv.resize(num + 1);
	create_fact_mod(num);
	create_seq_inv_mod(num);
	create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k) {
	return fact[n] * fact_inv[n - k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k) {
	return fact[n] * fact_inv[n - k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power) {
	int64_t prod = 1;
	num %= MOD;
	while (power > 0) {
		if (power & 1) prod = prod * num % MOD;
		num = num * num % MOD;
		power >>= 1;
	}
	return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
	int64_t d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}

int64_t inv_mod(int64_t a) {
	int64_t x, y;
	extgcd(a, MOD, x, y);
	return (MOD + x%MOD) % MOD;
}


void solve()
{
	int M, A, B, C, D;
	cin >> M >> A >> B >> C >> D;
	create_mod_tables(1000);

	static int64_t dp[1001][1001];
	dp[A - 1][0] = 1;
	for (int i = A; i <= B; i++) 
		for (int j = 0; j <= M; j++) {
			add(dp[i][j], dp[i - 1][j]);
			int n = M - j;
			int64_t pw = power_mod(fact_inv[i], C);
			for (int k = C; k <= D && i*k <= n; k++) {
				int64_t res = comb_mod(n, i*k) * fact[i*k] % MOD * pw % MOD * fact_inv[k] % MOD;
				mul(pw, fact_inv[i]);
				add(dp[i][j + i*k], dp[i - 1][j] * res);
			}
		}

	cout << dp[B][M] << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}



Measured memory_bytes: 11368
/**
 * Created by fanny on 16-10-23.
 */

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner1 = new Scanner(System.in);
        String line1 = scanner1.nextLine();
        int K = Integer.parseInt(line1.split(" ")[0]);
        int T = Integer.parseInt(line1.split(" ")[1]);

        String line2 = scanner1.nextLine();
        String[] a = line2.split(" ");

        int max = K-1;
        if (T == 1) {
            System.out.println(max);
            return;
        }

        int[] c = new int[T];
        for (int i = 0; i < T; i++) {
            c[i] = Integer.parseInt(a[i]);
        }

        boolean result = false;
        for (int i = 0; i < T; i++) {
            if (c[i] > (K / 2)) {
//                System.out.println(c[i]);
                result = true;
                max = c[i];
            }
        }

        if (!result) {
            System.out.println(0);
            return;
        }
        else{
            int tmp = max;
            for (int i = 0; i < T; i++) {
                if (c[i]!=max) {
                    tmp -= c[i];
                }
            }
            max = tmp-1;
            System.out.println(max);
//            System.out.println("false");
            return;
        }
    }
}

//        List<Integer> intList = new ArrayList<Integer>();
//        for (int i = 0; i < T; i++) {
//            for (int m = 0; m < c[i]; m++)
//                intList.add(i);
//        }
//
//        List<List<Integer>> myLists = perm(intList);
//
//        int min = K-1;
//        List<Integer> b = new ArrayList<>(myLists.size());
//        for (int i=0;i<myLists.size();i++){
//            int count = 0;
//            for (int n=1;n<K;n++) {
//                if (myLists.get(i).get(n) == myLists.get(i).get(n-1))
//                    count ++;
//            }
//            if (min>count)
//                min = count;
//        }
//        System.out.println(min);
//
//    }
//
//    public static List<List<Integer>> perm(List<Integer> list) {
//
//        if (list.size() == 0) {
//            List<List<Integer>> result = new ArrayList<List<Integer>>();
//            result.add(new ArrayList<Integer>());
//            return result;
//        }
//
//        List<List<Integer>> returnMe = new ArrayList<List<Integer>>();
//        Integer firstElement = list.remove(0);
//        List<List<Integer>> recursiveReturn = perm(list);
//
//        for (List<Integer> li : recursiveReturn) {
//            //System.out.println("li  " + li);
//            for (int index = 0; index <= li.size(); index++) {
//                List<Integer> temp = new ArrayList<Integer>(li);
//                temp.add(index, firstElement);
//                //System.out.println("temp " + temp);
//                returnMe.add(temp);
//            }
//        }
//
//        return returnMe;
//    }


Measured memory_bytes: 9684
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int64_t x=1000;
  for(int i=0;i<N-1;i++){
    if(A[i+1]>A[i]){
      int64_t t=x/A[i];
      x%=A[i];
      x+=A[i+1]*t;
    }
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 3548
n, m = map(int, input().split())
g = [set() for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].add(b)
    g[b].add(a)
#print(g)

import itertools
ans = 0
for per in itertools.permutations(range(n)):
    if per[0] != 0:
        continue
    for i in range(n-1):
        if per[i+1]  not in g[per[i]]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 40048