akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1100000
#define mod 1000000007
using namespace std;
int n, m, k, bin[25], f[N], g[N][25], map[25][25], x, y, z, sum, LOG[N], ans, ff, L, last;
int main(){
	scanf("%d%d%d", &n, &m, &k);
	bin[0]=1; for(int i=1; i<=n; i++)bin[i]=bin[i-1]<<1;
	LOG[0]=-1; for(int i=1; i<=bin[n]; i++)LOG[i]=LOG[i>>1]+1;
	for(int i=1; i<=m; i++)
		for(int j=1; j<=n; j++)map[i][j]=2;
	for(int i=1; i<=k; i++){scanf("%d%d%d", &x, &y, &z); map[x][y]=z^1;}
	if(n==1){printf("1"); return 0;} n--;
	memset(g, 0, sizeof(g)); sum=1;
	for(int owo=1; owo<=m; owo++){
		memset(f, 0, sizeof(f));
		for(int s=0; s<=bin[n]-1; s++){
			ff=1;
			for(int i=1; i<=n; i++)if(((s&bin[n-i])?1:0)==map[owo][i]){ff=0; break;}
			if(!ff)continue;
			for(int i=1; i<=n; i++)if(!(s&bin[i-1])){
				f[s]+=g[((s+bin[i-1])>>(i-1))<<(i-1)][1]; if(f[s]>=mod)f[s]-=mod;
			}
			f[s]=sum-f[s]; if(f[s]<0)f[s]+=mod;
		}
		sum=0;
		for(int s=0; s<=bin[n]-1; s++){sum+=f[s]; if(sum>=mod)sum-=mod;}
		memset(g, 0, sizeof(g));
		for(int s=bin[n]-1; s; s--){
			L=n-LOG[s&(-s)]; g[s][L]=f[s];
			for(int i=1; i<=n-L; i++){g[s][L]+=g[s+bin[n-L-i]][L+i]; if(g[s][L]>=mod)g[s][L]-=mod;}
		}
		for(int s=1; s<=bin[n]-1; s++){
			L=n-LOG[s&(-s)]; last=n;
			for(int i=L-1; i; i--){
				g[s][i]=g[s][i+1];
				if(!(s&bin[n-L+i])){
					if(last==n)continue;
					g[s][i]+=g[s+bin[n-L+i]-bin[last]][i+1]; if(g[s][i]>=mod)g[s][i]-=mod;
				}else last=n-L+i;
			}
		}
	}
	ans=0; for(int i=0; i<=bin[n]-1; i++){ans+=f[i]; if(ans>=mod)ans-=mod;}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 116224
import java.util.*;
import java.math.*;

public class Main {
	public static int x, maxn, d;
	public static void main(String ards[])
	{
		Scanner cin = new Scanner(System.in);
		long h = cin.nextLong();
		long w = cin.nextLong();
		if(h == 1 || w == 1){
			System.out.println(1);
		}
		else{
			long ans = 0, x = 0;
			if(w%2 == 0) x = w/2;
			else x = ((long)w/2)+1;
			
			if(h%2 == 0) ans = (h/2) * w;
			else ans = (((long)h/2)*w)+x;
			
	        System.out.println(ans);
		}
	}
}

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

int main()
{
    int n;
    cin>>n;
    int idx=1;
    for(int i=1800;i>=400;i-=200)
    {
        if(n>=i)
        {
            cout<<idx<<endl;
            return 0;
        }
        idx++;
    }
}


Measured memory_bytes: 3648
A, B, C = map(int, input().split())
max_num = max(A, B, C)
count = A + B + C
ans = 0
while True:
    if count % 3 == 0 and count / 3 >= max_num:
        break
    else:
        count += 2
        ans += 1
print(ans)


Measured memory_bytes: 38464
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
		    String s = sc.next();
		    if ("nobiro".equals(s)) {
		        x = Math.max(0, x + a);
		    } else if ("tidime".equals(s)) {
		        x = Math.max(0, x + b);
		    } else if ("karero".equals(s)) {
		        x = 0;
		    }
		}
		System.out.println(x);
	}
}



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

int main(void){
int rep;
int64_t cyclepow=1;
int64_t divisor =1000000007;
cin>>rep;

for(int i=rep;i>0;i--){
  cyclepow=cyclepow*i%divisor;
}
cout<<cyclepow<<endl;
return 0;
}


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

int main() {
	int N;cin>>N;
	int h = -1;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		int a;cin>>a;
		if (a >= h)
		{
			ans++;
			h = a;
		}
	}

	cout<<ans<<endl;
;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); // 問題数
		int m = sc.nextInt(); // 提出回数
		int[] ac = new int[n];
		int[] wa = new int[n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			String s = sc.next();
			if (s.equals("AC") && ac[a - 1] == 0) {
				ac[a - 1]++;
				continue;
			}
			if (s.equals("WA") && ac[a - 1] == 0) {
				wa[a - 1]++;
			}
		}
		
		int sumA = 0;
		int sumB = 0;
		for (int i = 0; i < n; i++) {
			sumA += ac[i];
			if (ac[i] > 0) {
				sumB += wa[i];
			}
		}
		
		System.out.println(sumA);
		System.out.println(sumB);
	}
}


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

using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
int n;
vector<vector<int>> matrix;
vector<int> dp;

ll count(int k, int mask)
{
	if (dp[mask] == -1)
	{
		dp[mask] = 0;
		for (int i = 0; i < n; ++i)
		{
			if (mask & (1 << i))
			{
				dp[mask] += count(k - 1, mask & ~(1 << i)) * matrix[i][k - 1];
				dp[mask]%=MOD;
			}
		}
	}
	return dp[mask];
}

int main()
{
	IOS
	cin >> n;
	matrix.assign(n + 1, vector<int>(n + 1));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin >> matrix[i][j];
		}
	}

	dp.assign((1 << (n + 1)) + 5, -1);
	int mask = 0;
	for (int i = 0; i < n; ++i)
	{
		mask |= (1 << i);
	}
	dp[0] = 1;
	cout << count(n,mask);

	return 0;
}


Measured memory_bytes: 16640
import collections
n = str(input())
ans,m,div = 0,0,[]
for i,j in enumerate(reversed(n)):
    m=(m+int(j)*pow(10,i,2019))%2019
    div.append(m)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    string X;
    cin >> X;
    int N = X.size(), S = 0, T = 0;
    rep(i, N) {
        if (X[i] == 'S') S++;
        if (X[i] == 'T') {
            if (S > 0) {
                S--;
            } else {
                T++;
            }
        }
    }
    cout << S + T << endl;
}

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

string check(int mf, int r) {
    string check_;
    if (mf < 30) check_ = "F";
    else if (mf < 50) {
        if (r >= 50) check_ = "C";
        else check_ = "D";
    } 
    else if (mf < 65) check_ = "C";
    else if (mf < 80) check_ = "B";
    else check_ = "A";

    return check_;
}

int main () {
    int m, f, r;
    cin >> m >> f >> r;
    vector <string> data;
    
    while (m != -1 || f != -1 || r != -1) {
        int mf;
        if (m == -1 || f == -1) mf = -1;
        else mf = m + f;

        data.push_back(check(mf, r));
        cin >> m >> f >> r;
    }

    for (int i = 0; i < data.size(); i++) {
        cout << data[i] << endl;
    }
}


Measured memory_bytes: 3148
// ITP1_4_A:   A / B Problem
#include <stdio.h>
#include <stdlib.h>

#define PI  3.141592653589793

int main()
{
	double r;

	scanf("%lf", &r);
	printf("%lf %lf\n", PI*r*r, 2*PI*r);
	return 0;
}


Measured memory_bytes: 2100
N,M = map(int,input().split())
H_list = list(map(int,input().split()))
A_list = [0] * M
B_list = [0] * M
C_list = [0] * N
for i in range(M):
    A_list[i],B_list[i] = map(int,input().split())
for a,b in zip(A_list,B_list):
    if H_list[a-1] < H_list[b-1]:
        C_list[a-1] = -1
    elif H_list[a-1] > H_list[b-1]:
        C_list[b-1] = -1
    elif H_list[a-1] == H_list[b-1]:
        C_list[a-1] = C_list[b-1] = -1
print(C_list.count(0))

Measured memory_bytes: 87500
N, D = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
    for j in range(i):
        d = sum((x - y)**2 for x, y in zip(P[i], P[j]))
        x = int(d**.5)
        if x**2 == d:
            ans += 1
print(ans)

Measured memory_bytes: 3060
N = int(input())

Sum_1 = N * (N + 1) // 2
Sum_3 = (N // 3) * (N // 3 + 1) // 2 * 3
Sum_5 = (N // 5) * (N // 5 + 1) // 2 * 5
Sum_15 = (N // 15) * (N // 15 + 1) // 2 * 15

print(Sum_1 - Sum_3 - Sum_5 + Sum_15)

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

int main() {

  int N, K, ans=0;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0; i<N; i++) {
    cin >> h.at(i);
    if(h.at(i) >= K) ans++;
  }
   
  cout << ans << endl;
  
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  ll n;
  cin >> n;
  if(n%2==0)printf("%d",n);
  else printf("%d",2*n);
}

Measured memory_bytes: 256
#include<stdio.h>

int LIS(void);

int h[201],r[201],m,n;

int main(void)
{
  int i,j,t;
  while(1)
    {
      scanf("%d",&n);
      if(n==0)break;

      for(i=0;i<n;i++)
	scanf("%d%d",&h[i],&r[i]);

      scanf("%d",&m);

      for(i=n;i<n+m;i++)
	scanf("%d%d",&h[i],&r[i]);


       for(i=0;i<n+m;i++)
	{
	  for(j=0;j<n+m;j++)
	    {
	      if(h[i]<h[j])
		{
		  t=h[i];
		  h[i]=h[j];
		  h[j]=t;
		  t=r[i];
		  r [i]=r[j];
		  r[j]=t;
		}
	      if(h[i]==h[j] && r[i]<r[j])
		{
		  t=h[i];
		  h[i]=h[j];
		  h[j]=t;
		  t=r[i];
		  r [i]=r[j];
		  r[j]=t;
		}
	    }
	}
       printf("%d\n",LIS());

    }
  return 0;
}

int LIS(void)
{
  int i,j,k,L[201],max=0;
  
  for(i=0;i<201;i++)
    L[i]=1;

  for(i=1;i<n+m;i++)
    {
      j=i-1;
      /*if(r[j]<r[i] && h[j]<h[i])
	{
	  L[i]=L[j]+1;
	}
      else 
      {*/
	  for(k=0;k<i;k++)
	    {
	      if(r[k]<r[i] && h[k]<h[i] && L[k]>=L[i])L[i]=L[k]+1;
	    }
	  //	}
    }
  
  for(i=0;i<n+m;i++)
    if(max<L[i])max=L[i];

  return max;
}

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

int main() {
    int k, x;
    cin >> k >> x;
    if (x <= k*500) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
typedef pair<char, int> P;

const int M = 1e5;
char s[M + 1], t[M + 1];
P sr[M];
int dist[M][26];

int main() {
    scanf("%s", s);
    scanf("%s", t);
    int ls = strlen(s);
    
    for (int i = 0; i < ls; i++) {
        sr[i] = P(s[i], i);
    }
    sort(sr, sr + ls);

    for (int i = 1; i < ls; i++) {
        if (dist[0][s[i] - 'a'] == 0) dist[0][s[i] - 'a'] = i;
    }
    if (dist[0][s[0] - 'a'] == 0) dist[0][s[0] - 'a'] = ls;

    for (int i = 1; i < ls; i++) {
        for (int j = 0; j < 26; j++) {
            dist[i][j] = max(dist[i - 1][j] - 1, 0);
        }
        int a = upper_bound(sr, sr + ls, P(s[i], i)) - sr;
        if (a < ls && sr[a].first == s[i]) {
            dist[i][s[i] - 'a'] = sr[a].second - i;
        } 
        else {
            a = upper_bound(sr, sr + ls, P(s[i], -1)) - sr;
            dist[i][s[i] - 'a'] = ls + sr[a].second - i;
        }
    }

    if (dist[0][t[0] - 'a'] == 0) {
        printf("-1\n");
        return 0;
    }

    int pre = (s[0] == t[0]) ? 0 : dist[0][t[0] - 'a'];
    long res = pre + 1;
    for (int i = 1; i < strlen(t); i++) {
        int d = dist[pre][t[i] - 'a'];
        if (d == 0) {
            printf("-1\n");
            return 0;
        }
        pre = (pre + d) % ls;
        res += d;
    }

    printf("%ld\n", res);
    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n;
std::cin >> n;
std::vector<int> a;
int odd = 0;
int even = 0;
for(int i = 0; i < n; i++){
    int temp;
    std::cin >> temp;
    a.pb(temp);
    if(temp % 2 == 0){
        even++;
    } else {
        odd++;
    }
}

if(odd >= 1){
    std::cout << "first" << std::endl;
} else {
    std::cout << "second" << std::endl;
}

return 0;
}

Measured memory_bytes: 1400
import sys
# counter dictionary
c_dict = dict(a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, k=0, l=0, m=0, n=0, o=0, p=0, q=0, r=0, s=0, t=0, u=0, v=0, w=0, x=0, y=0, z=0)

# inputs
text = sys.stdin.read().lower()

# loop
for ch in text:
    ch = ch.lower()
    if ch in c_dict:
        c_dict[ch] += 1

# output
for k, v in c_dict.items():
    print('{} : {}'.format(k, v))


Measured memory_bytes: 5560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main(){
	int a,b,k,i,j;
	cin>>a>>b>>k;
	if(2*k>=(b-a+1)){
		for(i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}else{
		for(i=0,j=a;i<k;i++,j++){
			cout<<j<<endl;
		}
		for(i=0,j=b-k+1;i<k;i++,j++){
			cout<<j<<endl;
		}
	}
}

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

int main() {
  int S;
  cin >> S;
  
  if(S/100<13 && S/100>0){
    if(S%100<13 && S%100>0){
      cout << "AMBIGUOUS" << endl;
    }
    else if(S%100>12 || S%100==0){
      cout << "MMYY" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
  else if(S/100>12 || S/100==0){
    if(S%100<13 && S%100>0){
      cout << "YYMM" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
  else{
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll ans[200005]={0};
int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> array;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    array.push_back(a);
  }
  sort(array.begin(),array.end());
  vector<P> order;
  for(int i=0;i<m;i++){
    ll b,c;
    cin>>b>>c;
    order.push_back(P(c,b));
  }
  sort(order.begin(),order.end(),greater<P>());
  ll aidx=0,oidx=0;
  while(oidx<order.size()&&aidx<array.size()){
    if(array[aidx]<order[oidx].first){
      array[aidx]=order[oidx].first;
      order[oidx].second--;
      if(order[oidx].second<=0) oidx++;
    }
    aidx++;
  }
  ll ans=0;
  for(int i=0;i<n;i++) ans+=array[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(100);
  int i;
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  double c=0;
  for(i=0;i<n;i++){
    c += a.at(i);
  }
  c = round(c/n);
  int d=0;
  for(i=0;i<n;i++){
    d += pow((c-a.at(i)),2);
  }
  cout << d << "\n";
  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++)

typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;

  if (a >= 13) cout << b << endl;
  else if (a < 6) cout << "0" << endl;
  else cout << b/2 << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
import collections
import copy
import math
def input(): return sys.stdin.readline().strip()
N ,K= map(int,input().split())
S = input()
cuts = 0
for i in range(N-1):
    if S[i] != S[i+1]:
        cuts += 1
print(min(N-1,N-1-cuts+2*K))


Measured memory_bytes: 39920
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,ll>;
using Graph= vector<vector<ll>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
 ll n, k;
 cin>>n>>k ;
 vector<ll> A(n) ;
 vector<ll> ans(n) ;
 bool ok=true ;
 rep(i,n) {
   cin>>A[i] ;
   if(A[i]>0) ok=false ;
 }
  
   rep(j,min(100ll,k)){
     rep(i,n){
      ll a=i-A[i] ;ll b=i+A[i] ;
      if(a<0) a=0 ; ans[a] ++ ;
      if(b<n-1) ans[b+1]-- ; 

     }
    rep(i,n){
      if(i==0) A[i]=ans[i] ;
      else A[i]=A[i-1]+ans[i] ;
     ans[i]=0 ;
    }
   }
  
  rep(i,n) cout<<A[i]<<endl ;
  
  return 0;
  }

Measured memory_bytes: 6424
package main

import "fmt"

func main() {
	var x1, x2, x3, x4, x5 int
	fmt.Scan(&x1, &x2, &x3, &x4, &x5)

	slice := []int{x1, x2, x3, x4, x5}

	for v, s := range slice {
		if s == 0 {
			fmt.Println(v + 1)
		}
	}
}


Measured memory_bytes: 1752
from collections import deque
N = int(input())
G = {}
for i in range(N-1):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(a)
hist = [-1 for _ in range(N+1)]
heapF = deque([(1,0)])
hist[1] = 0
heapS = deque([(N,0)])
hist[N] = 1
turn = 0
while heapF or heapS:
    if turn%2==0:
        while heapF:
            cur = heapF.popleft()
            if cur[1]==turn//2:
                for x in G[cur[0]]:
                    if hist[x]<0:
                        heapF.append((x,cur[1]+1))
                        hist[x] = 0
            else:
                heapF.append(cur)
                break
    else:
        while heapS:
            cur = heapS.popleft()
            if cur[1]==turn//2:
                for x in G[cur[0]]:
                    if hist[x]<0:
                        heapS.append((x,cur[1]+1))
                        hist[x] = 1
            else:
                heapS.append(cur)
                break
    turn += 1
n = hist.count(0)
m = hist.count(1)
if m>=n:
    print("Snuke")
else:
    print("Fennec")

Measured memory_bytes: 28868
from fractions import gcd

a, b, c, d = map(int, input().split(" "))


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


def sj(base, i1, i2):
    cz = base // i1
    dz = base // i2
    cd = base // lcm(i1, i2)
    return base - (cz + dz - cd)


print(sj(b, c, d) - sj(a - 1, c, d))


Measured memory_bytes: 5076
n= int(input())
l=list(map(int,input().split()))
d={}
ans=0
for i in range(n):
    
    if i-l[i] in d:
        ans+=d[i-l[i]]
    if i+l[i] in d:
        d[i+l[i]]+=1
    else:
        d[i+l[i]]=1
print(ans)

Measured memory_bytes: 111656
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <vector>
#include <set>
#include <map>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DV_NUM (100000007)

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main()
{
    int N,M;

    cin >> N >> M;

    vector<int> A(N);

    FOR(i,0,N) cin >> A[i];

    int sumVote=0;

    FOR(i,0,N) sumVote += A[i];

    int count = 0;

    FOR(i,0,N){
        if((double)A[i] >= (double)sumVote/(4*M) ){
            count++;
        }
    }

    if (count >= M){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;  
    }
    
    return 0;
} 

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int a, b;
    cin >> a >> b;

    cout << (a < 10 and b < 10 ? a * b : -1) << '\n';
    return 0;
}


Measured memory_bytes: 3636
package main

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

type store struct {
	price int
	n     int
}

type stores []store

func (a stores) Len() int {
	return len(a)
}

func (a stores) Less(i, j int) bool {
	return a[i].price < a[j].price
}

func (a stores) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make(stores, n)
	for i := range a {
		sc.Scan()
		a[i].price, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		a[i].n, _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(a)
	ans := int64(0)
	rem := m
	for _, e := range a {
		if rem == 0 {
			break
		}
		i := min(rem, e.n)
		ans += int64(i * e.price)
		rem -= i
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main(void) { int N, M; cin >> N >> M; const int NMMAX = 50; int A[NMMAX], B[NMMAX]; for (int i = 0; i < M; ++i) { cin >> A[i] >> B[i];
 }
int road[NMMAX]; for (int i = 0; i < N; ++i) { road[i] = 0; } for (int i = 0; i < M; ++i) { road[A[i] - 1] += 1;
road[B[i] - 1] += 1; } for (int i = 0; i < N; ++i) { cout << road[i] << endl; }   }

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  string str;
  str="APPROVED";
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>k;
    if(k%2==0){
      if(k%3==0){
      }
      else if(k%5==0){
      }
      else{
        str="DENIED";
        break;
      }
      
    }
  }
  cout<<str;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {

    int N, K;
    cin >> N >> K;
    vector<double> P(N);

    rep(i, N) {
        int a;
        cin >> a;
        P[i] = (1 + a) / 2.0;
    }

    double ans = 0, now = 0;
    rep(i, K) now += P[i];
    ans = now;

    rep(i, N - K) {
        now -= P[i];
        now += P[i + K];
        ans = max(ans, now);
    }

    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int x = 0;
		int answer = 0;
		
		int n = in.nextInt();
		String s = in.next();
		
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'I') {
				x++;
			} else {
				x--;
			}
			answer = Math.max(answer, x);
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 20820
S = input()
L = [0] * len(S)
now = 0
RorL_count = 0
for i in range(len(S)):
    if (i == len(S) - 1 and S[now] == 'R'):
        if ((i - now) % 2 == 0):
            L[i] += (RorL_count // 2)
            L[i - 1] += (RorL_count // 2)
        else:
            L[i - 1] += (RorL_count // 2 + 1)
            L[i] += (RorL_count // 2)
        L[i] += 1
        break
    elif (i == len(S) - 1 and S[now] == 'L'):
        RorL_count += 1
        if ((i - now) % 2 == 0):
            L[now] += (RorL_count // 2 + 1)
            L[now - 1] += (RorL_count // 2)
        else:
            L[now] += (RorL_count // 2)
            L[now - 1] += (RorL_count // 2)
        break

    if (S[now] == 'R'):
        if (S[i] == 'L'):
            if ((i - now) % 2 == 0):
                L[i] += (RorL_count // 2)
                L[i - 1] += (RorL_count // 2)
            else:
                L[i - 1] += (RorL_count // 2 + 1)
                L[i] += (RorL_count // 2)
            RorL_count = 1
            now = i
        else:
            RorL_count += 1
            continue
    else:
        if (S[i] == 'R'):
            if ((i - now) % 2 == 0):
                L[now] += (RorL_count // 2)
                L[now - 1] += (RorL_count // 2)
            else:
                L[now] += (RorL_count // 2 + 1)
                L[now - 1] += (RorL_count // 2)
            RorL_count = 1
            now = i
        else:
            RorL_count += 1
            continue
strL = []
for i in L:
    strL.append(str(i))
print(' '.join(strL))


Measured memory_bytes: 17120
def f(i):
  if i == W-1:
    for j in range(W-2):
      if s[j] == s[j+1] == 1:
        return
    global x
    for j in range(W):
      if j == 0:
        if s[0] == 1:
          x[0][1] += 1
        else:
          x[0][0] += 1
      elif j == W - 1:
        if s[W-2] == 1:
          x[W-1][W-2] += 1
        else:
          x[W-1][W-1] += 1
      else:
        if s[j-1] == 1:
          x[j][j-1] += 1
        elif s[j] == 1:
          x[j][j+1] += 1
        else:
          x[j][j] += 1 
    return
  s[i] = 1
  f(i + 1)
  s[i] = 0
  f(i + 1)

H,W,K=map(int, input().split())
MOD = pow(10, 9) + 7
s = [0] * (W - 1)
x = [[0] * W for _ in range(W)]
if not W == 1:
  f(0)
else:
  print(1)
  exit()
dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1
for i in range(1,H+1):
  for j in range(W):
    for l in range(W):
      dp[i][j]+=dp[i-1][l]*x[l][j]
      dp[i][j]%=MOD
print(dp[H][K-1])

Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll arr[n];
	for(int i = 0; i < n;++i){
		cin >> arr[i];
	}
	ll maxi = arr[0];
	ll ans = 0;
	for(int i = 1; i < n;++i){
		if(arr[i] < maxi){
			ans += maxi - arr[i];
			arr[i] = maxi;
		}
		maxi = max(arr[i],maxi);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 5172
#include <iostream>
#include <vector>
#include <algorithm>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

class PrimeTest{
private:
	std::vector<bool> is_prime_;					//nが素数かどうかをis_prime[n]で判定
	std::vector<unsigned int> prime_numbers_;		//素数の集合

public:
	PrimeTest();

	~PrimeTest();

	const std::vector<unsigned int>& get_prime_numbers() const;

	bool is_prime(unsigned int n);

};

PrimeTest::PrimeTest(){
	is_prime_.push_back(false);	//0
	is_prime_.push_back(false);	//1
	is_prime_.push_back(true);	//2
	is_prime_.push_back(true);	//3

	prime_numbers_.push_back(2);
	prime_numbers_.push_back(3);
}
PrimeTest::~PrimeTest(){}

const std::vector<unsigned int>& PrimeTest::get_prime_numbers() const{
	return prime_numbers_;
}

bool PrimeTest::is_prime(unsigned int n){
	if(n >= is_prime_.size()){
		unsigned int i_s = is_prime_.size();
		is_prime_.resize(n + 1, false);

		//i_sからnまでの各数が素数かどうか判定
		for(unsigned int i = i_s; i <= n; i++){
			unsigned int max_val = int(sqrt((double)i));
			bool b = true;
			for(unsigned int j = 0; j < prime_numbers_.size(); j++){
				if(prime_numbers_[j] > max_val){ break;}
				if(i % prime_numbers_[j] == 0){
					b = false;
					break;
				}
			}
			if(b){
				prime_numbers_.push_back(i);
				is_prime_[i] = true;
			}
		}

	}
	return is_prime_[n];
}

int main(){
	int n;
	int result = 0;
	PrimeTest prime_test;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

	for(;;){
#if INPUT_FROM_FILE
		ifs >> n;
#else
		std::cin >> n;
#endif
		if(n == 0){ break; }

		result = 2;
		n -= 1;
		for(int i = 3; n > 0; i += 2){
			if(prime_test.is_prime(i)){
				result += i;
				n--;
			}
		}
		
		std::cout << result << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)
#define fore(i,x) for(int i = head[x] ; i ; i = e[i].next)
#define mp make_pair
#define pb push_back
#define int long long
#define PII pair<int,int>
#define maxn 1000005
#define ll long long 
#define fi first
#define int ll
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const int MOD=1e9+7;
int n,m,L;
int fac[maxn],inv[maxn],bin[maxn];
int f[maxn],a[maxn];
void pre()
{ fac[0]=1;
  rep(i,1,maxn-1) fac[i]=(fac[i-1]*i)%MOD;
  inv[1]=1; inv[0]=1;
  rep(i,2,maxn-1) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
  rep(i,1,maxn-1) inv[i]=(inv[i-1]*inv[i])%MOD;
 }

ll cal(int n,int m)
{if(n<m) return 0;
 if(n==0&&m==0) return 1;
return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
signed main()
{ pre();
  cin>>n>>m; L=(1<<n);
  rep(i,0,n) bin[i]=(1<<i);
  rep(i,1,m) cin>>a[i];
  sort(a+1,a+m+1);
  f[0]=1;	
  repd(i,m,1)//背包 
  { for(int sta=(1<<n)-1;sta!=0;sta--)
     {for(int j=0;j<n;j++) if(sta&bin[j])
       {int tmp=(f[sta^bin[j]]*cal(L-a[i]-sta+bin[j],bin[j]-1))%MOD;
        tmp=tmp*fac[bin[j]]%MOD;     
	    f[sta]=(f[sta]+tmp)%MOD;	
       }
	 }
  	
  }

 int ans=0;
 rep(i,0,(1<<n)-1)
 { int cur=(f[i]*fac[L-i-1])%MOD;
    if(__builtin_popcount(i)&1) ans=(ans-cur+MOD)%MOD;
    else  ans=(ans+cur)%MOD;
 }	
  cout<<(ans*L)%MOD<<endl;
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

// combination nCk+ % MOD
const ll MOD = 1e9 + 7;
// return a^b O(log b)
template<typename T>
T mypow(T a, T b){
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

int main(){
    ll m, n;
    cin >> m >> n;
    ll res = mypow(m, n);
    cout << res << endl;
    return 0;
}


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

using namespace std;

#define EPS (1e-10)

struct Point {
    int x, y;

    Point() {}
    Point (int x, int y) : x(x), y(y) {}
    
    Point operator - (const Point &p) const {
        return Point(x - p.x, y - p.y);
    }
};

int cross(const Point &a, const Point &b)
{
    return a.x * b.y - b.x * a.y;
}

bool sortY(const Point &p1, const Point &p2)
{
    if (p1.y != p2.y) {
	return (p1.y < p2.y);
    } 
    return (p1.x < p2.x);
}

typedef vector<Point> Polygon;

Polygon convex_hull(Polygon &ps)
{
    sort(ps.begin(), ps.end(), sortY);
    int N = ps.size(), k = 0;
    Polygon qs(N * 2);
    for (int i = 0; i < N; i++) {
	while (k > 1 && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) < 0) {
            k--;
	}
	qs[k++] = ps[i];
    }
    for (int i = N - 2, t = k; i >= 0; i--) {
	while (k > t && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) < 0) {
            k--;
	}
	qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}

int main()
{
    int N;
    cin >> N;
    Polygon qs(N);
    for (int i = 0; i < N; i++) {
        cin >> qs[i].x >> qs[i].y;
    }
    
    qs = convex_hull(qs);
    N = qs.size();
    
    cout << N << endl;
    for (int i = 0; i < N; i++) {
        cout << qs[i].x << " " << qs[i].y << endl;
    }
    return 0;
}

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

int main() {
    long long a[100010];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    int zero = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) zero++;
    }
    if (zero > 0) {
        cout << "0" << endl;
        return 0;
    }

    long long prod = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] <= 1000000000000000000 / prod) {
            prod *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << prod << endl;
}

Measured memory_bytes: 4412
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);


typedef vector<ll> vl;
typedef vector<vl> vvl;

int get_index(vi &vec,int item){
	int ret=find(ALL(vec),item)-vec.begin();
	return ret;
}

int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

void fill(vvl &f,ll id,int y,int x,vvi &visited,int h,int w){
	visited[y][x]=1;
	REP(d,4){
		int yy=y+dy[d];
		int xx=x+dx[d];
		if(yy>=0&&xx>=0&&yy<h&&xx<w&&!visited[yy][xx]&&f[yy][xx]==id){
			fill(f,id,yy,xx,visited,h,w);
		}
	}
}

int main(){
	int n;
	while(cin>>n,n){
		vi l(n),t(n),r(n),b(n);
		vi xs,ys;
		REP(i,n){
			cin>>l[i]>>t[i]>>r[i]>>b[i];
			swap(t[i],b[i]);
			xs.push_back(l[i]);
			xs.push_back(r[i]);
			ys.push_back(t[i]);
			ys.push_back(b[i]);
		}
		sort(ALL(xs));
		sort(ALL(ys));
		xs.erase(unique(ALL(xs)),xs.end());
		ys.erase(unique(ALL(ys)),ys.end());
		int h=(ys.size()+2)*2,w=(xs.size()+2)*2;
		vvl f(h,vl(w));
		REP(i,n){
			FOR(y,(get_index(ys,t[i])+1)*2+1,(get_index(ys,b[i])+1)*2+1){
				FOR(x,(get_index(xs,l[i])+1)*2+1,(get_index(xs,r[i])+1)*2+1){
					f[y][x]|=(1LL<<i);
				}
			}
		}
		int ans=0;
		vvi visited(h,vi(w));
		REP(i,h){
			REP(j,w){
				if(!visited[i][j]){
					ans++;
					fill(f,f[i][j],i,j,visited,h,w);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4628
#include <iostream>
using namespace std;
int main()
{
int time=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++){
    if(i+1>s.size()/2){
        break;
    }
    if(s[i]!=s[s.size()-i-1]){
        time++;
    }
}
cout<<time;
return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


#define MOD 1000000007

int n;
int a[200000];

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

	cin >> n;
	rep(i, n)cin >> a[i];


	long long s = 0;
	rep(i, n)s += a[i];
	long long ans = 0;

	s %= MOD;
	rep(i, n) {
		s -= a[i];
		s = (s + MOD) % MOD;

		ans += a[i] * s;
		ans %= MOD;
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = 1;
		int w = 1;
		while (h != 0 || w != 0) {
			h = scanner.nextInt();
			w = scanner.nextInt();
			for (int i = 0; i < h; ++i) {
				if (i == 0 || i == h - 1) {
					for (int c = 0; c < w; ++c) {
						System.out.print("#");
					}
				} else {
					System.out.print("#");
					for (int c = 0; c < w - 2; ++c) {
						System.out.print(".");
					}
					System.out.print("#");
				}
				System.out.println("");
			}
			if (h != 0 || w != 0) {
				System.out.println("");
			}
		}

	}
}



Measured memory_bytes: 34660
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<u32> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();

    println!("{}", v[1] * (v[1] - 1).pow(v[0] - 1));
}



Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=30010;

ll pt(int e){
	ll ans=1;
	rep(_,e)ans*=10;
	return ans;
}

int main(){
	set<ll> st;
	rep(i,15){
		if(i==0)rep1(k,9)st.insert((ll)k);
		else if(i<=10){
			rep(k,i*10)st.insert( (ll)(k+1)* pt(i)-1);
		}
		else if(i<=14){
			rep(k,(i-1)*10)st.insert( (ll)(k+1)* pt(i)-1);
		}
	}
	int K;
	cin>>K;
	int tmp=K;
	for(auto it=st.begin(); it!=st.end(); it++){
		cout<<*it<<endl;
		tmp--;
		if(tmp==0) break;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int K,N; cin >> K >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    int ans=A[0]+(K-A[N-1]);
    rep(i,N-1){
        chmax(ans,A[i+1]-A[i]);
    }
    cout << K-ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
int a,n,tp,tq;
 
void rec(int p,int q,int an,int &cnt,int k,int total)
{
  if(total > a)return;
  if(an > n)return;
  if(p*tq > tp*q)return;
  if(((n-an)*q+k*p)*tq < tp*k*q)return;
  if(p == tp && q == tq)
    {
      cnt++;
      return;
    }
 
  for(int i=k;q*i<=a;i++)
    {
      int A = p*i+q,B = q*i;
      if(total*i > a)continue;
      int gcd1 = __gcd(A,B);
      A /= gcd1;
      B /= gcd1; 
      rec(A,B,an+1,cnt,i,total*i);
    }
}
 
int main()
{
 
  while(1)
    {
      scanf("%d %d %d %d",&tp,&tq,&a,&n);
      if(!(tp|tq|a|n))break;
      int gcd1 = __gcd(tp,tq);
      tp /= gcd1;
      tq /= gcd1;
      int theNumber = 0;
      for(int i=1;i<=a;i++)
    {
      if(i > a)continue;
      rec(1,i,1,theNumber,i,i);
    }
      printf("%d\n",theNumber);
    }
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, C;
  scanf("%d %d", &N, &C);
  vector<int> start(N), end(N), channel(N);
  for (int i = 0; i < N; ++i) {
    int s, t, c;
    scanf("%d %d %d", &s, &t, &c);
    start[i] = s * 2 - 1;
    end[i] = t * 2;
    channel[i] = c;
  }

  int upper = 1e5 * 2 + 5;
  vector<int> recorder(upper, 0);
  for (int c = 1; c <= C; ++c) {
    vector<int> in_use(upper, 0);
    for (int i = 0; i < N; ++i) {
      if (channel[i] != c) { continue; }
      ++in_use[start[i]];
      --in_use[end[i]];
    }
    for (int i = 1; i < upper; ++i) {
      in_use[i] += in_use[i - 1];
    }
    for (int i = 0; i < upper; ++i) {
      if (in_use[i] > 0) { ++recorder[i]; }
    }
  }

  int ans = *max_element(recorder.begin(), recorder.end());
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	cout << min(b, a * n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 1e4 + 10;//;
ll dp[N][110][3];
string s;
ll d;
//ll mara[N] ;

ll F(int pos,int mod,bool isbig)
{
    if(pos >= s.size() )
        return mod == 0;
    ll &r = dp[pos][mod][isbig] ;

    if(r != -1) return r;

    r = 0;
    if(isbig)
    {
        for(int i = 0; i <= 9; i++)
        {
            r += F(pos+1, (mod +  i) % d, isbig);
            r %= MOD;
        }

    }
    else{
        for(int i = 0; i <= (s[pos] - '0'); i++)
        {
            if( (s[pos] - '0') == i) {
                r += F(pos+1, (mod + i) % d, isbig) ;
                r %= MOD;
            }
            else{
                r += F(pos+1,(mod +  i) % d, 1);
                r %= MOD;
            }

        }
    }
    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof dp);
    cin >> s >> d;
    //mara[0] = 1 % d;

//    for(int i = 1; i < N ; i++)
//        mara[i] = (mara[i-1] * 10) % d;

    cout <<  (F(0,0,0) - 1 + MOD ) % MOD << endl;
    //for(int i = 1; i <= )
    return 0;
}




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

int ARRAY_MAX = 100000;

int main(){
    int n; cin >> n;
    int array[ARRAY_MAX] = {0};
    for(int i = 0; i<n; ++i){
        int tmp; cin >> tmp;
        ++array[tmp];
    }
    int ans = 0;
    for(int i = 0; i<ARRAY_MAX-2; ++i){
        int tmp = array[i] + array[i+1] + array[i+2];
        if(tmp > ans)ans = tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import sys
import string

counter = {c: 0 for c in string.ascii_letters}
input_str = sys.stdin.read()

for char in input_str:
    char = char.lower()
    if char in string.ascii_letters:
        counter[char] += 1

for c in string.ascii_lowercase:
    v = 0 if c not in counter else counter[c]
    print('{} : {}'.format(c, v))



Measured memory_bytes: 6680
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll n,c,k;
ll a[300010];
ll ans;
int main(){
	scanf("%lld",&n);
	rep(i,0,3*n)scanf("%lld",a+i);
	sortdown(a,3*n);
	
	ll ans=0;
	repp(i,1,2*n,2)ans+=a[i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 4860
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,i,j,p,m,s;
    cin>>a>>b>>c>>d;
    long long w,x,y,z;
    w=a*c;
    x=b*c;
    y=a*d;
    z=b*d;
    p=max(w,x);
    m=max(p,y);
    s=max(m,z);
    cout<<s;
    
    
}




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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return move(x); }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	auto A=vecin(N);
	vll B(62,0);

	REP(i,N){
		ll V=A[i];
		ll index = 0;
		while(V){
			if(V&1ll) B[index]++;
			index++;
			V/=2ll;
		}
	}
	
	ll S=0,C=1;
	REP(i,62){
		S += ((C%atcoder_mod)*((B[i]*(N-B[i]))%atcoder_mod))%atcoder_mod;
		S %= atcoder_mod;
		C *= 2ll;
	}
	out(S);
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	deque<char>d;
	char s[maxn],c[2];
	scanf("%s",s+1);
	int len=strlen(s+1),i,q,t,f,re=0;
	for(i=1;i<=len;i++)d.push_back(s[i]);
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d",&t);
		if(t==1)re++;
		else
		{
			scanf("%d%s",&f,c);
			if(f==1)
			{
				if(re&1)d.push_back(c[0]);
				else d.push_front(c[0]);
			}
			else
			{
				if(re&1)d.push_front(c[0]);
				else d.push_back(c[0]);
			}
		}
	}
	if(re&1)
	{
		while(!d.empty())
		{
			printf("%c",d.back());d.pop_back();
		}
	}
	else
	{
		while(!d.empty())
		{
			printf("%c",d.front());d.pop_front();
		}
	}
	puts("");
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

vector<ll> D;
Graph G;


void dfs(int p, int parent = -1){

    for (int next_p : G[p]){
        if (parent == next_p) continue;
        D[next_p] += D[p];
        dfs(next_p, p);
    }
}

int main(){
    int N, Q; cin >> N >> Q;
    D.assign(N,0);
    G.assign(N, vector<int>());
    rep(i,N-1){
        int a, b; cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,Q){
        int p,x; cin >> p >> x;
        D[--p] += x;
    }
    dfs(0);

    rep(i,N){
        if (i != 0) cout << " ";
        cout << D[i];
    }

    cout << endl;

}

Measured memory_bytes: 24320
import java.util.*;

class Main{
    Scanner sc = new Scanner(System.in);

    Main(){
	int a=sc.nextInt();
	int b=sc.nextInt();
	System.out.println( (a*b) + " " + (a*2+b*2) );
    }

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

Measured memory_bytes: 26236