akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  vvi cnt(200010);
  rep(i,N) {
    cnt[A[i]].push_back(i);
  }
  vi dp(N+1,0);
  dp[0] = 1;
  rep(i,N) {
    int p = lower_bound(rng(cnt[A[i]]),i)-cnt[A[i]].begin();
    if(p+1 < sz(cnt[A[i]])) {
      int r = cnt[A[i]][p+1];
      if(r != i+1) {
        dp[r] += dp[i];
        dp[r] %= MOD;
      }
    }
    dp[i+1] += dp[i];
    dp[i+1] %= MOD;
  }
  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 12800
N, M = map(int, input().split())
i = 1
lis = []
while M//i>=N and i<=M**0.5:
  if M % i == 0:
    lis.append(i)
  i += 1
for l in lis[::-1]:
  ans = M//l
  if M//ans>=N:
    lis.append(ans)
print(lis[-1])

Measured memory_bytes: 3060
n,k=raw_input().split();u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()));z=u[0];n=list(n)
for i,d in enumerate(n):
 if d in u:continue
 n[i:]=[next(e for e in u if e>d)]+[z]*(len(n)-i-1)
 for j in range(i-1,-1,-1):
  if n[j+1]<':':break
  n[j:j+2]=[next(e for e in u if e>n[j]),z]
 else:
  if n[0]>'9':n=[u[1 if'1'>z else 0]]+[z]*len(n)
print"".join(n)

Measured memory_bytes: 2696
#include<iostream>
#include<cinttypes>
int main() {
	std::uint32_t x;
	std::cin >> x;

	auto put = [](uint32_t x) {
		for (int i{31}; i>=0 ; --i) {
			std::cout << ((x >> i)&1? 1:0);
		}
		std::cout << "\n";
	};

	put(x);
	put(~x);
	put(x << 1);
	put(x >> 1);
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <complex>
#define INF 1000000009
#define LINF 1000000000000000009
#define EPS 1e-10
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main(){
	ll a, b, c, d, e, f, g;
	cin >> a >> b >> c >> d >> e >> f >> g;
	ll t = min({ a,d,e });
	a -= t; d -= t; e -= t;
	ll ans = 3 * t + a / 2 * 2 + b + d / 2 * 2 + e / 2 * 2;
	if (t != 0) {
		t--;
		a++; d++; e++;
		chmax(ans, 3 * t + a / 2 * 2 + b + d / 2 * 2 + e / 2 * 2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String ans = "No";
    if (S.contains("N") && S.contains("S") && S.contains("E") && S.contains("W")) {
      ans = "Yes";
    }
    if (S.contains("N") && S.contains("S") && !S.contains("E") && !S.contains("W")) {
      ans = "Yes";
    }
    if (!S.contains("N") && !S.contains("S") && S.contains("E") && S.contains("W")) {
      ans = "Yes";
    }
    System.out.println(ans);
  }
}

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

int main(){
  long x,min,m;
  cin>>x;
  for(int i=sqrt(x);i>0;i--){
    if(x%i==0){
        m=x/i;
        min=m-1+i-1;
        break;
    } 
  }
  cout<<min;
}

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

int main(void){
  int N;
  int *a;
  int i;
  int k;
  scanf("%d",&N);
  a = (int *)malloc(N * sizeof(int));
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
    a[i]--;
  }
  k=a[0];
  if(k!=1){
    for(i=1;i<N;i++){
      k=a[k];
      if(k==1){
	printf("%d\n",i+1);
	return 0;
      }
    }
  }
  else {
    printf("1\n");
    return 0;
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    int w,h,n;cin>>w>>h>>n;
    int lim[4]={0,w,0,h};
    rep(i,n){
        int x,y,a;cin>>x>>y>>a;
        if(a%2){lim[a-1]=max(lim[a-1],a<3?x:y);}
        else {lim[a-1]=min(lim[a-1],a<3?x:y);}
    }
    cout<<(max(lim[1]-lim[0],0)*max(lim[3]-lim[2],0))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[3][205], b[205] = {0};
	int i, n, k, i2;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (i2 = 0; i2 < 3; i2++)
			scanf("%d", &a[i2][i]);
		}
	for (k = 0; k < 3; k++){
		for (i = 0; i < n; i++){
			for (i2 = 0; i2 < n; i2++){
				if (i == i2)continue;
				if (a[k][i] == a[k][i2])break;
			}
			if (i2 == n)b[i] += a[k][i];
		}
	}
	for (i = 0; i < n; i++){
		printf("%d\n", b[i]);
	}
	return 0;
	
}

Measured memory_bytes: 600
al=[chr(i) for i in range(65, 65+26)]
N=int(input())
S=list(input())

for index,num in enumerate(S):
    b=al.index(num)
    c=b+N
    if c>25:
        c-=26
    S[index]=al[c]
a="".join(S)
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>


using namespace std;

int main(){
	int m = 0;
	while(cin >> m && m != 0){
		vector<pair<int, int> > src;
		vector<pair<int, int> > sub;
		pair<int, int> prev;
		for(int i = 0; i < m; i++){
			pair<int, int> tmp;
			cin >> tmp.first >> tmp.second;
			src.push_back(tmp);
			
			if(i){
				if(!sub.empty()) sub.push_back(pair<int, int>(sub[i - 2].first + (prev.first - tmp.first), sub[i - 2].second + (prev.second - tmp.second)));
				else sub.push_back(pair<int, int>(prev.first - tmp.first, prev.second - tmp.second));
			}
			prev = tmp;
		}

		int n;
		cin >> n;
		vector<pair<int, int> > table;
		for(int i = 0; i < n; i++){
			pair<int, int> tmp;
			cin >> tmp.first >> tmp.second;
			table.push_back(tmp);
		}

		bool discover = false;
		int index = -1;
		for(int i = 0; i < n; i++){
			int count = 0;
			for(int j = 0; j < sub.size(); j++){
				for(int k = 0; k < n; k++){
					if(table[i].first - sub[j].first == table[k].first && table[i].second - sub[j].second == table[k].second) count++;
				}			
			}
			if(count == sub.size()){
				discover = true;
				index = i;
				break;
			}
		}

		if(discover){
			cout << table[index].first - src[0].first << " " << table[index].second - src[0].second << endl;
		}

	}
	

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int res = 0;
    for (int i = a ; i <= b; i++) {
        if(c % i == 0) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
	vector<vector<int>> add = { {0,1,2,3,4,5,6,7,8,9},
								{0,10,7,4,1,11,8,5,2,12},
								{0,9,5,1,10,6,2,11,7,3},
								{0,12,11,10,9,8,7,6,5,4},
								{0,3,6,9,12,2,5,8,11,1},
								{0,4,8,12,3,7,11,2,6,10} };

	string s;
	cin >> s;
	int n = s.size();

	// a[x][y] 1-origin x桁目、あまりy
	vector<vector<long long>> a;
	a.resize(n + 1);
	for (int i = 0; i < n + 1; i++) a[i].resize(13);
	a[0][0] = 1;
	for (int i = 1; i < 13; i++) a[0][i] = 0;

	char c;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 13; j++) a[i][j] = 0;

		int p = (i-1) % 6;
		c = s[n - i];
		if (c == '?') {
			for (int j = 0; j < 13; j++) {
				for (int k = 0; k < 10; k++) {
					int e = add[p][k];
					a[i][(j + e) % 13] += a[i-1][j];
					a[i][(j + e) % 13] = a[i][(j + e) % 13] % MOD;
				}
			}
		}
		else {
			int cc = c - '0';
			int e = add[p][cc];
			for (int j = 0; j < 13; j++) {
				a[i][(j + e) % 13] += a[i-1][j];
				a[i][(j + e) % 13] = a[i][(j + e) % 13] % MOD;
			}
		}
	}

	cout << a[n][5] << endl;

	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  double A, B;
  cin >> A >> B;
  int dA = ceil(100 * A / 8);
  int dB = ceil(100 * B / 10);
  int uA = floor(100 * (A+1) / 8);
  int uB = floor(100 * (B+1) / 10);
  if(8 * uA == 100 * (A + 1)) {
    uA--;
  }
  uB--;
  int d = max(dA, dB);
  int u = min(uA, uB);
  if(d > u) {
    cout << -1 << endl;
    return 0;
  }
  cout << d << endl;
  return 0;
}

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

int main(){
    ll int n,min=100000,a[3001],b[3001];
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> a[i];
        if(i==0){
            b[0]=a[0];
        }else{
            b[i]=b[i-1]+a[i];
        }
    }
    for(int i=0;i<n-1;i++){
        if(min>abs(b[n-1]-2*b[i])){
            min=abs(b[n-1]-2*b[i]);
        }
    }
    cout << min;
}

Measured memory_bytes: 3600
import math

def prime_factor2(n):
    i = 2
    factors = {}
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1
    if n > 1:
        if n in factors:
            factors[n] += 1
        else:
            factors[n] = 1
    return factors

def kai(n):
    return math.factorial(n)

def H(n, r):
    rtn = 1
    for i in range(n+r-1, n-1, -1):
        rtn *= i
    rtn //= kai(r)
    return rtn


N, M = map(int, input().split())

prime = prime_factor2(M)

ans = 1
for v in prime.values():
    h = H(N, v) % (10**9 + 7)
    ans  =  ans * h

ans = ans % (10**9 + 7)
ans = int(ans)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for (int i=a;i<=b;i++)
#define maxn 100007
using namespace std;

int m, n;
priority_queue<ll> heap;

void open() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
}

void read() {
    cin >> n >> m;
    ll a;
    For(i,1,n) {
        cin >> a;
        heap.push(a);
    }
}

void solve() {
    while (m--) {
        ll u = heap.top()/2; heap.pop();
        heap.push(u);
    }
    ll res=0;
    while (!heap.empty()) {
        res+=heap.top();
        heap.pop();
    }
    cout << res;
}

int main()
{
    open();
    read();
    solve();
    return 0;
}

Measured memory_bytes: 1400
program test
implicit none

integer(8) :: n,m,i,j,k,sosuu(32000)=1,temp,sosuu_list(32000)=0,soinsuu_list(32000)=0,count,rest,ans=1,value
integer(8) :: sosuu_list2(32000),soinsuu_list2(32000),count2,bits(32000)=0
read(*,*) n,m

! まず、Mを素因数分解をする
! 次に、N以上を満たす最小のMの約数を探しYとする
! 答えはM/Y

! 素数判定
sosuu(1)=0
do i=2,32000
	if(sosuu(i) == 0)then
		goto 100
	else
		temp = 2*i
		do while(temp <= 32000)
			sosuu(temp) = 0
			temp = temp + i
		enddo
	endif
	100 continue
enddo

! 素数リスト
count=0
do i=2,32000
	if(sosuu(i) == 1)then
		count = count + 1
		sosuu_list(count) = i
	endif
enddo

! 素因数分解をする
rest = m
do i=1,count
	do while(mod(rest,sosuu_list(i))==0)
		rest = rest/sosuu_list(i)
		soinsuu_list(i) = soinsuu_list(i) + 1
	enddo
enddo

count2=0
do i=1,count
	if(soinsuu_list(i) >= 1)then
		count2 = count2 + 1
		sosuu_list2(count2) = sosuu_list(i)
		soinsuu_list2(count2) = soinsuu_list(i)
	endif
enddo

! 最後に残ったrestが素数かもしれない
if(rest >= 2)then
	count2 = count2 + 1
	sosuu_list2(count2) = rest
	soinsuu_list2(count2) = 1
endif

if(m >= 2) then
do
	value = 1
	do i=1,count2
		value = value * sosuu_list2(i) ** bits(i)
	enddo
		
	if(M/value >= N )then
		ans = max(ans,value)
	endif
	
	bits(1) = bits(1) + 1
	do i=1,count2
		if(bits(i) > soinsuu_list2(i)) then
			if(i == count2)then
				goto 200
			else
				bits(i) = 0
				bits(i+1) = bits(i+1) + 1
			endif
		endif
	enddo
	
enddo
200 continue
endif

write(*,*) ans

end program

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

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

    int count = 0;

    for(int i = 0; i < S.size(); i++){
        for(int j = 0; j < S.size(); j++){
            if(S.at(i) == S.at(j)){
                count++;
            }
        }
    }

    if(count == S.size()){
        cout << "yes" << endl;
    }
    else{
        cout << "no" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;
  
int main() {
  string s;
  cin >> s;
  if(s=="AAA" || s=="BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
 
  cin.tie(0);
  ios::sync_with_stdio(false);

  bool cnt=0,ans=0;
  string s;
  cin>>s;
 
  for(int i=0; i<s.size(); i++){
    if(s[i]=='C') cnt=true;
    if(s[i]=='F' && cnt==true){
      ans++;
      break;
    }
  }
 
  if(ans==true) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
int A,B;
string s[105];

int main(void)
{
  int A,B;
  cin >> A >> B;
  for (int i = 0; i < 100; ++i)
    {
      for (int j = 0; j < 100; ++j)
	{
	  if(i==0) s[i]+='#';
	  else if(i==99) s[i]+='.';
	  else
	    {
	      if(j%2==0)s[i]+='#';
	      else s[i]+='.';
	    }
	}
    }
  A--;B--;
  if(B>0)
    {
  for(int i=97;i>=0;i-=2)
    {
      for (int j = 0; j < 100; j+=2)
	{
	  s[i][j]='.';
	  B--;
	  if(B==0) break;
	}
      if(B==0) break;
    }
    }
  if(A>0)
    {
      for(int i=2;i<100;i+=2)
	{
	  for(int j=1;j<=100;j+=2)
	    {
	      s[i][j]='#';
	      A--;
	      if(A==0) break;
	    }
	  if(A==0) break;
	}
    }
  cout << 100 << ' ' << 100 << endl;
  for (int i = 0; i < 100; ++i)
    {
      cout << s[i] << endl;
    }
  
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())
V = {i: [] for i in range(1, N + 1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1, N + 1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)


propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1, N + 1)))

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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    
    sum += r -l + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int N,ans = 0;
    cin >> N;

    repc(i, 1, N + 1){
        int div = 0;
        repc(j, 1, N + 1){
            if(i % j == 0){
                div++;
            }
        }

        if(i % 2 != 0 && div == 8){
            ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<algorithm>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
#define mod  998244353
const int N = 1e5 + 10;
const int M = 2e6 + 1005;
char a[305][305];int b[305][305];
int c[305];
int main()
{
    //freopen("input.txt","r",stdin);
    int n,m,k;
    cin>>n>>m>>k;
    int cnt = 0;
    for(int i = 1;i <= n;++i){
        for(int j = 1;j<= m;++j){
            cin>>a[i][j];
            if(a[i][j] == '#') b[i][j] = ++cnt,c[i] ++;
        }
    }
    for(int i = 1;i <= n;++i){
            if(c[i]){//按行
                for(int p = 1;p <= m;++p){
                    if(b[i][p]){
                        int color = b[i][p];
                        int l = p-1;
                        while(l>=1&&!b[i][l]) b[i][l--] = color;
                        l = p + 1;
                        while(l <= m&&!b[i][l]) b[i][l++] = color;
                    }
                }
            }

    }
    for(int i = 1;i <= n;++i){//按列
         for(int p = 1;p <= m;++p){
             if(!b[i][p]){
               int l = i;
               while(l>=1&&!b[l][p]) l--;
               if(l >=1 ) {b[i][p] = b[l][p];continue;}
               l = i;
               while(l <= n&&!b[l][p]) l++;
               if(l <= n) {b[i][p] = b[l][p];continue;}
            }
         }
    }
    for(int i = 1;i<= n;++i){
        for(int j =1 ;j <= m;++j){
            cout<<b[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int n,k,i,j,t;
int a,b;
cin>>n;
t=0;
for (i=1; i<=n; i++)
  {
  cin>>a>>b;
  t=t+b-a+1;
  }
cout<<t<<endl;
return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
#include<list>

using namespace std;

/*
n m
a1 b1
...
aM bM

n: vertex
m: edge
*/

int n, m;
int main(){
  scanf("%d %d", &n, &m);
  list<pair<int, int>> edge;
  for(int i = 0; i < m; i++){
    int a,b;
    scanf("%d %d", &a, &b);
    pair<int, int> p(a, b);
    edge.push_front(p);
  }

  queue<list<int>> que;
  list<int> ini;
  ini.push_front(1);
  que.push(ini);

  int ans = 0;
  while(!que.empty()){
    list<int> path = que.front();
    que.pop();

    if(path.size() >= n){
      ans++;
      continue;
    }

    int back = path.back();
    //printf("back = %d\n", back);

    for(int i = 1; i <= n; i++){
      if(find(path.begin(), path.end(), i) != path.end()) continue;

      //printf("i = %d\n", i);

      bool f = false;
      for( auto &e : edge ){
        if((e.first == back && e.second == i) || (e.first == i && e.second == back))
          f = true;
      }
      if(!f) continue;

      list<int> path1 = path;
      path1.push_back(i);
      que.push(path1);
    }
  }

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



Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define sf scanf
#define pf printf
#define pi acos(-1)
#define time_save ios_base::sync_with_stdio(false); cin.tie(NULL);

ll vis[100005],n,m;
vector<ll>vec[100005];

void dfs(ll n)
{
    if(vis[n]==1)
        return;
    vis[n]=1;
    for(ll i=0;i<vec[n].size();i++)
    {
        ll v=vec[n][i];
        if(vis[v]==0)
        {
            dfs(v);
        }
    }
}
int main()
{
    //time_save;
    cin>>n>>m;
    ll a,b;
    for(ll i=0;i<m;i++)
    {
        cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
            cnt++;
        }
    }
    cout<<cnt-1<<endl;
    return 0;
}


Measured memory_bytes: 11100
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<MAX; i++){
		fac[i] = fac[i-1]*i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}


ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
	ll n,x; cin >> n >> x;
	comInit();
	vl a(n); rep(i,n) cin >> a[i];
	sort(rall(a));
	vvl dp(n+1,vl(x+1,0));
	dp[0][x] = 1;
	rep(i,n){
		rep(j,x+1){
			dp[i+1][j%a[i]] += inv[n-i] * dp[i][j];
			dp[i+1][j] += ((n-1-i)*inv[n-i])%mod * dp[i][j];
			dp[i+1][j%a[i]] %= mod;
			dp[i+1][j] %= mod;
		}
	}
	ll ans = 0;
	rep(i,x+1){
		ans += dp[n][i] * fac[n] % mod * i;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 170624
#pragma GCC optimize(2)
#include <bits/stdc++.h>

namespace __temp_inbuilt{
	int read(void){
		int res = 0, sign = 1;
		char ch = std::getchar();
		while(!std::isdigit(ch)){
			if(ch == '-')
				sign = -1;
			ch = std::getchar();
		}
		while(std::isdigit(ch))
			res = res * 10 + ch - 48, ch = std::getchar();
		return sign * res;
	}
	
	template<class Tp>
		void write(const Tp &x){
			if(x > 9)
				write(x / 10);
			std::putchar(x % 10 + 48);
	}
}

using __temp_inbuilt::read;

template<class Tp>
	void writeln(const Tp &x){
		if(x < 0)
			std::putchar('-');
		__temp_inbuilt::write(x > 0 ? x : -x);
		std::putchar('\n');
	}

template<class Tp>
	void writesp(const Tp &x){
		if(x < 0)
			std::putchar('-');
		__temp_inbuilt::write(x > 0 ? x : -x);
		std::putchar(' ');
	}

template<class Tp>
	void write(const Tp &x){
		if(x < 0)
			std::putchar('-'), x = -x;
		__temp_inbuilt::write(x);
	}

typedef long long ll;
typedef unsigned long long ull;
typedef double rl;
typedef long double RL;

const rl PI = 3.1415926535898, E = 2.71828182845904;

namespace contest{
	const int MAXN = 2e5 + 19;
	
	int n, d, x[MAXN], y[MAXN];
	
	int main(){
		n = read(), d = read();
		for(int i = 1; i <= n; ++i)
			x[i] = read(), y[i] = read();
		int ans = 0;
		for(int i = 1; i <= n; ++i){
			if((ll)x[i] * x[i] + (ll)y[i] * y[i] <= (ll)d * d)
				++ans;
		}
		writeln(ans);
		return 0;
	}
}

int main(){
	contest::main();
	return 0;
}

Measured memory_bytes: 5112
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;


int N;
ll T[1002];
ll A[1002];


int main(){
    cin>>N;
    rep(i,N) cin>>T[i]>>A[i];
    ll t[1002]={};
    ll a[1002]={};
    t[1]=T[1]; a[1]=A[1];
    rep(i,N-1){
            t[i+1]=(max(((t[i]-1)/T[i+1]+1),((a[i]-1)/A[i+1])+1))*T[i+1];
            a[i+1]=(max(((t[i]-1)/T[i+1]+1),((a[i]-1)/A[i+1])+1))*A[i+1];
    }
    cout<<t[N]+a[N]<<endl;

    return 0;
}

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

using namespace std;
#define int long long
int n, dp[5005][5005], m;

string s;

const int mod = 1e9 + 7;

int BinPow(int x, int k){
    if(k == 0)
        return 1;
    else if(k == 1)
        return x;
    else{
        int sum1 = BinPow(x, k/2) % mod;
        sum1 = (sum1 * sum1)%mod;
        if(k % 2 != 0){
            sum1 = (sum1 * x)%mod, sum1 %= mod;
        }
        return sum1;
    }
}

signed main(){
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    cin >> s;
    m = s.length();
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= n; j++){
            if(!dp[i][j]) continue;
            if(j == 0){
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= mod;
            }
            else{
                dp[i + 1][j - 1] += dp[i][j];
                dp[i + 1][j - 1] %= mod;
            }
            dp[i + 1][j + 1] += 2 * dp[i][j];
            dp[i + 1][j + 1] %= mod;
        }
    }
    int sum1 = BinPow(2, m);
    cout << (BinPow(sum1, mod - 2) * dp[n][m])%mod << "\n";
}

Measured memory_bytes: 193920
#include <iostream>
using namespace std;
int main() {
char f;
cin>>f;
if( f=='a')
{
cout<<"vowel";return 0;
}
if(f=='e')
{
 cout<<"vowel";return 0;
}
if(f=='i')
{
    cout<<"vowel";return 0;
}
if(f=='o')
{
    cout<<"vowel";return 0;
}
if(f=='u')
{
    cout<<"vowel";return 0;
}
else
{
    cout<<"consonant";
}
	return 0;
}


Measured memory_bytes: 256
def abc070_b():
    a, b, c, d = map(int, input().split())

    if c <= a < b <= d:
        return b - a

    if a <= c < d <= b:
        return d - c

    if a <= c < b <= d:
        return b - c

    if c <= a < d <= b:
        return d - a

    if b <= c or d <= a:
        return 0


if __name__ == '__main__':
    print(abc070_b())


Measured memory_bytes: 3060
import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(a+b+c>=22?"bust":"win");




    }
    }



Measured memory_bytes: 21844
N=gets.to_i
ary=gets.split.map(&:to_i)

pos_prev = 0
count = 0
type = :NONE
1.upto(N-1) do |n|
  case type
  when :NONE
      if ary[n] == ary[pos_prev]
        pos_prev = n
        next
      end
      if ary[n] < ary[pos_prev]
      type = :DEC
    else
      type = :INC
    end
  when :INC
    if ary[n] < ary[pos_prev]
      count += 1
      type = :NONE
    end
  when :DEC
    if ary[pos_prev] < ary[n]
      count += 1
      type = :NONE
    end
  end
  pos_prev = n
end
puts count + 1


Measured memory_bytes: 8460
la = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

n = int(input())
flag = 0

lm = []

while n >= 1:
    m = n % 26
    if m != 0:
        lm.insert(0, m)
        n = (n-m)//26
    else:
        lm.insert(0, 26)
        n = n//26 - 1
    flag += 1

l = []

for i in range(flag):
    l.append(la[lm[i]-1])

#print(flag)
print(''.join(l))

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

#define ll long long
typedef pair <int, int> ii;
typedef pair <ll, int> lli;
#define ar array
#define pb push_back
#define fi first
#define se second
#define sz size
#define mp make_pair
#define nl '\n'
#define all(x) (x).begin(), (x).end()
#define int_max numeric_limits<int>::max()
#define int_min numeric_limits<int>::min()
#define ll_max numeric_limits<ll>::max()
#define ll_min numeric_limits<ll>::min()

#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 im(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// custom sort example
//sort(all(a), [ ]( const auto& c, const auto& d) {
	//if (c.fi.se != d.fi.se) {
		//return c.fi.se < d.fi.se; // lower first
	//}
	//if (c.fi.fi != d.fi.fi) {
		//return c.fi.fi > d.fi.fi; // higher first
	//}
	//return c.se > d.se; // higher first
//});

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
auto lbf(const std::set<std::pair<T, T>>& s, T first)
{
   static constexpr T min = std::numeric_limits<T>::min();

   return s.lower_bound({first, min});
}

int MOD = 1000000007;

ll pw(ll n, ll k) {
	ll r = 1;
	for(; k; k >>= 1) {
		if(k&1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	ll n, res;
	cin >> n;
	if (n == 1) {
		cout << 0 << nl;
	} else {
		res = pw(10, n);
		res = (res - pw(9, n) + MOD) % MOD;
		res = (res - pw(9, n) + MOD) % MOD;
		res = (res + pw(8, n)) % MOD;
		cout << res << nl;
	}
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,a,b,c;
string s;
int main(){
  cin>>n>>m;
  vector<int> h(n);
  for(;i<n;i++)cin>>h[i];
  vector<bool> x(n);
  for(i=0;i<n;i++)x[i]=true;
  for(i=0;i<m;i++){
    cin>>a>>b;a--;b--;
    if(h[a]<=h[b])x[a]=false;
    if(h[b]<=h[a])x[b]=false;
  }
  for(i=0;i<n;i++)if(x[i])c++;
  cout<<c;
}

Measured memory_bytes: 3788
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B, C, D = map(int, input().split())
if A%C == 0:
    wid = A
else:
    wid = (A//C + 1) * C
if wid > B:
    c_num = 0
else:
    c_num = (B-wid) // C + 1

if A%D == 0:
    wid = A
else:
    wid = (A//D + 1) * D
if wid > B:
    d_num = 0
else:
    d_num = (B-wid) // D + 1

E = lcm(C, D)
if A%E == 0:
    wid = A
else:
    wid = (A//E + 1) * E
if wid > B:
    e_num = 0
else:
    e_num = (B-wid) // E + 1

print(B - A - (c_num + d_num - e_num) + 1)

Measured memory_bytes: 5244
#include <stdio.h>

int main(){
    
    int x, y, t;
    while(1){
        scanf("%d %d", &x, &y);
        if (x == 0 && y==0) break;
        
        if (x > y){
            
            t = x;
            x = y;
            y = t;
            
        }
        
        printf("%d %d\n", x, y);
    }
    
}

Measured memory_bytes: 1812
import java.util.Scanner;

class Main{
	public static void main (String[]arge){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
			int b = scan.nextInt();
				//int c = scan.nextInt();
		System.out.println(a * b + " " + (a + b) * 2);
	}
}


Measured memory_bytes: 26132
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;

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

long long max(long long a,long long b){
	return (a>b)? a:b;
}
int j_k_bit_1or0(int j,int k){

}

int main (){
	long long NNN,MMM,maxx=0,p=0,sum=0;
	cin >> NNN >> MMM;
	long long a[3][NNN];
	rep(i,NNN){
		rep(j,3){
			cin >> a[j][i];
		}
	}

	vector <long long> temp[8];
	rep(i,8){
		rep(j,NNN){
			rep(k,3){
				if(i & (1 << k)) p += a[k][j];
				else p -= a[k][j];			
			}
			cout << endl;
			temp[i].push_back(p);
			p=0;
		}
		sort(temp[i].rbegin(),temp[i].rend());
		sum=0;
		rep(k,MMM){
			sum += temp[i][k];
		}
		maxx = max(sum,maxx);
	}
	cout << maxx << endl;

	return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC128
{
    class D
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();
            int N = a[0], K = a[1];
            int[] V = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();

            int max = int.MinValue;

            for(int i = 0; i <= K/2; i++)
            {
                int np = K - i;
                for(int j = 0; j <=np; j++)
                {
                    for (int m = 0; m <= np - j; m++)
                    {
                        if (j + m > N) continue;
                        List<int> jewels = new List<int>();
                        jewels.AddRange(V.Take(j));
                        jewels.AddRange(V.Skip(N - m));

                        jewels.Sort();

                        int sum = 0;
                        for (int k = 0; k < jewels.Count; k++)
                        {
                            if (k < i && jewels[k] < 0) continue;
                            sum += jewels[k];
                        }
                        if (sum > max) max = sum;
                    }
                }
            }

            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 17572
# include<bits/stdc++.h>
# define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
 
int main () {
  int n;
  map<string, int> mp;
  cin >> n;
  int ma = 0;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
    ma = max(ma, mp[s]);
  }
  
  for (auto a : mp) if (a.second == ma) cout << a.first << endl;
  
  return 0;
}

Measured memory_bytes: 25344
#include <iostream>
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    if (n%2==0){
        if (n/2>=k){
            cout<<"YES"<<endl;
        }
        else cout<<"NO"<<endl;
    }
    if (n%2==1){
        if (n/2+1>=k){
            cout<<"YES"<<endl;
        }
        else cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
N,M = map(int,input().split())
PS = []
for i in range(M):
    PS.append(input().split())
    PS[i][0] = int(PS[i][0])

WA = [0 for i in range(N+1)]
AC = [0 for i in range(N+1)]

for i in range(M):
    if PS[i][1] == "WA":
        if AC[PS[i][0]] == 0:
            WA[PS[i][0]] += 1
    else:
        AC[PS[i][0]] = 1

pen,cor = 0,0
for i in range(N+1):
    if AC[i] == 1:
        pen += WA[i]
    cor += AC[i]

print(str(cor)+" "+str(pen))


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

using namespace std;

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

	if (a > b) { return gcd(b, a % b); }

	return gcd(a, b % a);
}

long long lcm(long long a, long long b)
{
	return a / gcd(a, b) * b;
}

vector<int> G; // i --> G[i] Graph

vector<bool> visited;

vector<vector<int> > cycles;

void rec(int p)
{
	visited[p] = true;

	cycles.back().push_back(p);

	if (!visited[G[p]])
	{
		rec(G[p]);
	}
}

int extgcd(int a, int b, int &x, int &y)
{
	int d = a;

	if (b != 0)
	{
		d = extgcd(b, a % b, y, x);

		y -= (a / b) * x;
	}
	else
	{
		x = 1; y = 0;
	}

	return d;
}

int modinv(int a)
{
	int x, y;

	extgcd(a, 1000000007, x, y);

	return (1000000007 + x % 1000000007) % 1000000007;
}

int main()
{
	int V, Q;

	scanf("%d", &V);
	scanf("%d", &Q);

	G = vector<int>(V);

	for (int i = 0; i < V; i++)
	{
		scanf("%d", &G[i]); G[i]--; // 1 -> 0 indexed
	}

	visited = vector<bool>(V, false);

	for (int i = 0; i < V; i++)
	{
		if (!visited[i])
		{
			cycles.push_back(vector<int>());

			rec(i);
		}
	}

	vector<int> val(V, 0), num(V, 0);

	for (int i = 0; i < cycles.size(); i++)
	{
		int sum = 0;

		for (int j = 0; j < cycles[i].size(); j++)
		{
			sum += cycles[i][j] + 1;
		}

		for (int j = 0; j < cycles[i].size(); j++)
		{
			val[cycles[i][j]] = sum;

			num[cycles[i][j]] = cycles[i].size();
		}
	}

	vector<vector<int> > sum(V, vector<int>(41));

	sum[0][num[0]] = 1;

	for (int i = 1; i < V; i++)
	{
		sum[i][num[i]] = 1;

		for (int j = 1; j <= 40; j++)
		{
			sum[i][j] += sum[i - 1][j];
		}
	}

	vector<int> sum2(V);

	sum2[0] = (1LL * modinv(num[0]) * val[0]) % 1000000007;

	for (int i = 1; i < V; i++)
	{
		sum2[i] = (sum2[i - 1] + 1LL * modinv(num[i]) * val[i]) % 1000000007;
	}

	int l, r;

	for (int i = 0; i < Q; i++)
	{
		scanf("%d", &l); l--; // 1 -> 0 indexed
		scanf("%d", &r); r--;

		long long rep = 1; int c;

		for (int i = 2; i <= 40; i++)
		{
			c = sum[r][i];

			if (l != 0)
			{
				c -= sum[l - 1][i];
			}

			if (c != 0)
			{
				rep = lcm(rep, i);
			}
		}

		int ret = sum2[r] + 1000000007;

		if (l != 0)
		{
			ret -= sum2[l - 1];
		}

		ret %= 1000000007;

		ret = 1LL * rep % 1000000007 * ret % 1000000007;

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 24752
#import <Foundation/Foundation.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

int main() {
	int n;
	scanf("%d", &n);
	int a[100];
	int sum = 0;
	rep(i, n) {
		scanf("%d", a + i);
		sum += a[i];
	}
	int min = 100000;
	int ans = -1;
	rep(i, n) {
		int diff = ABS(n * a[i] - sum);
		if (diff < min) {
			ans = i;
			min = diff;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 7120
n = int(input())
p = []
for i in range(n):
    ptemp = int(input())
    p.append(ptemp)

q = [0 for i in range(n)]
for i in range(n):
    q[p[i]-1] = i

ans = 0
i = 0
temp = 1
while i < n-1:
    if q[i] > q[i+1]:
        if temp > ans:
            ans = temp
        temp = 1
    else:
        temp += 1
    i += 1
if temp > ans:
    ans = temp
print(n-ans)
    

Measured memory_bytes: 18888
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if (A <= C && C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int num[] = new int[3];
	for ( int i = 0; i < 3; i++ ) {
	    num[i] = sc.nextInt();
	}

	int cnt5 = 0;
	int cnt7 = 0;
	for ( int i = 0; i < 3; i++ ) {
	    if ( num[i] == 5 ) cnt5++;
	    else if ( num[i] == 7 ) cnt7++;
	}
	if ( cnt5 == 2 && cnt7 == 1 ) {
	    System.out.println("YES");
	}else {
	    System.out.println("NO");
	}
	
    }
}


Measured memory_bytes: 23636
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 200005;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()
int32_t main()
{ 
  IOS

  int x,n;
  cin>>x>>n;
  map<int,int> marked;
  int p[n+1];
  for(int i =  1;i<=n;i++){
    cin>>p[i];
    marked[p[i]] = 1;
  }
  int mini = 1e6;
  int ans = -1;
  for(int i = -500;i<=500;i++){
    if(!marked[i]){
      if(abs(i-x)<mini){
        ans = i;
        mini = abs(i-x);
      }
    }
  }
  cout<<ans<<endl;
  




}

Measured memory_bytes: 3720
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
ans = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      ans[i][j] = '#'
      if i > 0 and j > 0:
        if ans[i-1][j-1] != '#':
          ans[i-1][j-1] += 1
      if i > 0:
        if ans[i-1][j] != '#':
          ans[i-1][j] += 1
      if i > 0 and j <= W - 2:
        if ans[i-1][j+1] != '#':
          ans[i-1][j+1] += 1
      if j > 0:
        if ans[i][j-1] != '#':
          ans[i][j-1] += 1
      if j <= W - 2:
        if ans[i][j+1] != '#':
          ans[i][j+1] += 1
      if i <= H - 2 and j > 0:
        if ans[i+1][j-1] != '#':
          ans[i+1][j-1] += 1
      if i <= H - 2:
        if ans[i+1][j] != '#':
          ans[i+1][j] += 1
      if i <= H - 2 and j <= W - 2:
        if ans[i+1][j+1] != '#':
          ans[i+1][j+1] += 1
for i in range(H):
  A = [str(a) for a in ans[i]]
  A = ''.join(A)
  print(A)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc084.contest.atcoder.jp/tasks/arc084_a>
問題文============================================================
 今年もすぬけ祭の季節がやってきました。
 りんごさんは、まず手始めにすぬけ君召喚の儀式を執り行おうと思っています。
 儀式には祭壇が必要で、祭壇は上部、中部、下部の 3 つのカテゴリーのパーツ 1 つずつからなります。
 
 祭壇の 3 カテゴリーのパーツがそれぞれ N 個ずつあります。
 i 個目の上部のパーツのサイズは Ai 、i 個目の中部のパーツのサイズは Bi 、i 個目の下部のパーツのサイズは Ci です。
 
 祭壇を作るにあたっては、中部のパーツのサイズは上部のパーツのサイズより真に大きく、
 下部のパーツのサイズは中部のパーツのサイズより 真に大きくなければなりません。
 逆に、この条件を満たす任意の 3 つのピースを組み合わせて祭壇を作ることができます。
 
 りんごさんが作ることのできる祭壇は何種類あるでしょうか。
 ただし、2 つの祭壇が異なるとは、上部、中部、下部に使われるピースのうち 少なくとも 1 つが異なることを言います。
 
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N),B(N),C(N);
    for(auto& in:A) cin >> in;
    for(auto& in:B) cin >> in;
    for(auto& in:C) cin >> in;
    sort(A.begin(),A.end()); sort(B.begin(),B.end()); sort(C.begin(),C.end());
    ll ans = 0;
    for(int i = 0; i < N;i++){
        auto ue = lower_bound(A.begin(),A.end(),B[i]);
        auto sita = upper_bound(C.begin(),C.end(),B[i]);
        if(ue == A.begin()) continue;
        ans += (ue - A.begin()) * (C.end() - sita);
    }
    cout << ans << endl;
	return 0;
}


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

typedef long long ll;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n), s(n);
	for(int i=0; i<n; i++) cin >> a[i];

	s[0] = a[0];
	// 偶数番目を正、奇数番目を負にする（０オリジン）
	ll cnte=0;
	for (int i = 0; i < n; i++) {
		if(i!=0) s[i] = s[i-1] + a[i];
		if (i % 2 == 0) {
			if (s[i] <= 0) {
				cnte += 1-s[i];
				s[i] = 1;
			}
		}
		else {
			if (s[i] >= 0) {
				cnte += 1+s[i];
				s[i] = -1;
			}
		}
	}

	s[0] = a[0];
	// 奇数番目を正、偶数番目を負にする
	ll cnto=0;
	for (int i = 0; i < n; i++) {
		if(i!=0) s[i] = s[i-1] + a[i];
		if (i % 2 == 0) {
			if (s[i] >= 0) {
				cnto += 1+s[i];
				s[i] = -1;
			}
		}
		else {
			if (s[i] <= 0) {
				cnto += 1-s[i];
				s[i] = 1;
			}
		}
	}

	cout << min(cnte,cnto) << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    int k, a ,b;
    cin >> k >> a >> b;
    repbtw(i, a, b){
        if(i % k == 0) {
            pr("OK");
            return 0;
        }
    
    }
    pr("NG");
    return 0;
}



Measured memory_bytes: 3636