akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  y = NULL; //xの親
  x = root; //Tの根
  while(x != NULL){
    y = x; //親を設定
    if(z->key < x->key) x = x->left; //左の子へ移動
    else x = x->right; //右の子へ移動
  }

  z->parent = y;

  if(y == NULL) root = z; //Tが空の場合
  else if(z->key < y->key) y->left = z; //zをyの左の子にする
  else y->right = z; //zをyの右の子にする

}

void inorder(Node x){
  if(x!= NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
}
}
void preorder(Node x){
  if(x!= NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

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

constexpr int MAX = 100;

bool visited[MAX];

int dfs(int v, const std::vector<std::vector<int>> &G)
{
    visited[v] = 1;
    int res = 0;
    for (int to : G[v]) {
        if (!visited[to]) {
            res = std::max(res, dfs(to, G) + 1);
        }
    }
    visited[v] = 0;
    return res;

}

int main()
{
    int N;
    while (1) {
        std::cin >> N;
        if (N == 0) {
            break;
        }
        std::vector<std::vector<int>> G(MAX);
        for (int i = 0; i < N; i++) {
            int a, b;
            std::cin >> a >> b;
            a--; b--;
            G[a].emplace_back(b);
            G[b].emplace_back(a);
        }

        int res = 0;
        for (int i = 0; i < MAX; i++) {
            std::fill(visited, visited + MAX, 0);
            res = std::max(res, dfs(i, G) + 1);
        }
    
        std::cout << res << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3096
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(10000)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))
    N = int(input())
    S = input()
    ret = ''
    for c in S:
        c_rep = chr(((ord(c)+N) - 65) % 26+65)

        ret = ret + c_rep
    print(ret)  # 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 5304
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=(t-1);i>=(s);--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define sf scanf
#define pf printf
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
const ll mod = 1e9 + 7;

map<pii,ll> cnt[2];

int main()
{
	int n;
	string str,l,r;
	ll Rl,Bl,Rr,Br;
	cin>>n>>str;
	l=str.substr(0,n);
	r=str.substr(n,2*n);
	reverse(all(r));
	rep(i,0,(1<<n))
	{
		Rl=Bl=Rr=Br=0;
		rep(j,0,n)
		{
			if(i&(1<<j))
			{
				Rl=(Rl*99997+l[j])%mod;
				Br=(Br*99997+r[j])%mod;
			}
			else
			{
				Bl=(Bl*99997+l[j])%mod;
				Rr=(Rr*99997+r[j])%mod;
			}
		}
		cnt[0][mp(Rl,Bl)]++;
		cnt[1][mp(Br,Rr)]++;
	}
	ll ans=0;
	for(auto e:cnt[0])
		ans+=e.se*cnt[1][e.fi];
	cout<<ans<<endl;
}

Measured memory_bytes: 49408
n = STDIN.gets.strip.to_i

def check(n)
  d = n % 10
  while n > 0
    if n % 10 != d
      return false
    end
    n = n / 10
  end
  true
end


while true
  if check(n)
    puts n
    exit
  end
  n = n + 1
end

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define Nmax 300000 

typedef long long ll;

const ll mod = 1e9+7;
const double pi = acos(-1);

int n,i,j,k,t,m;
int a[200002];

int main(){
	scanf("%d", &n);
	for(i=0;i<n;++i)
		scanf("%d", a+i);
	for(i=0;i<n;++i){
		if(a[i]>i){
			puts("-1");
			return 0;
		}
	}
	ll ans = 0;
	for(i=n-1;i>0;--i){
		if(a[i]>0){
			ans++;
			if(a[i]!=a[i-1]+1){
				if(a[i-1] < a[i] - 1){
					puts("-1");
					return 0;
				}
				ans+=(ll)a[i]-1;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#define rep(i,n) for(int i(0);i<n;i++)

using namespace std;
int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i,n) cin >> d[i];

	int ans(0);
    for(int i(0);i<n-1;i++){
    	for(int j(i+1);j<n;j++){
    		ans += d[i] * d[j];
    	}
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
using namespace std;
int N, K, Q;
int tmp;
vector<int> A;
vector<int> points;

int main() {
	cin >> N >> K >> Q;
	for (int i = 0;i < Q;i++) {
		cin >> tmp;
		A.push_back(tmp);
	}
	for (int i = 0;i < N;i++) {
		points.push_back(0);
	}
	for (int i = 0;i < Q;i++) {
		points[A[i] - 1] ++;
	}
	for (int i = 0;i < N;i++) { //解答
		if (Q - points[i] < K) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1528
from collections import deque 
import sys
input = sys.stdin.readline
def main():
    q = deque([])
    h,w=map(int,input().split())
    a=[list(input()) for i in range(h)]
    x=[[-1,0],[1,0],[0,-1],[0,1]]
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                for k in x:
                    if 0<=i+k[0]<h and 0<=j+k[1]<w and a[i+k[0]][j+k[1]]==".":
                        a[i+k[0]][j+k[1]]="0"
                        q.append([i+k[0],j+k[1],1])
    ans=0
    while q:
        v=q.popleft()
        for k in x:
            if 0<=v[0]+k[0]<h and 0<=v[1]+k[1]<w and a[v[0]+k[0]][v[1]+k[1]]==".":
                a[v[0]+k[0]][v[1]+k[1]]="0"
                q.append([v[0]+k[0],v[1]+k[1],v[2]+1])
                ans=v[2]+1
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 134748
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin>>k;
  string s;
  for(int i=1;i<=k;i++) {
    s+="ACL";
  }
  cout<<s<<endl;

  return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int long long 
const ll mod = 998244353;
int n,l[100000+5],r[100000+5];
multiset<pair<int,int> > ls,rs;

ll calc(int& curp,int l,int r){
	int temp=curp;
	if(curp>=r){curp=r;return -r+temp;}
	if(curp<=l){curp=l;return l-temp;}
	return 0;
}
main() {
	///freopen("input","r",stdin);
	
	cin>>n;
	int cnt1=0,cnt2=0;
	for(int  i=0;i<n;i++){cin>>l[i]>>r[i];}
	ll total =0;
	ll ans =0,curp = 0;
	for(int i=0;i<n;i++){ls.insert({-l[i],-r[i]});rs.insert({r[i],l[i]});}
	for(int i=0;!ls.empty()||!rs.empty();i++){
		if(i%2){
			pair<int,int>x=*ls.begin();
			ans+=calc(curp,-x.first,-x.second);
			ls.erase(ls.find(x));
			rs.erase(rs.find({-x.second,-x.first}));
		}
		else{
			pair<int,int>x=*rs.begin();
			ans+=calc(curp,x.second,x.first);
			rs.erase(rs.find(x));
			ls.erase(ls.find({-x.second,-x.first}));
		}
	}
	total=ans+abs(curp);
	//cout<<ans<<endl;
	ans =0,curp = 0;
	for(int i=0;i<n;i++){ ls.insert({-l[i],-r[i]});rs.insert({r[i],l[i]});}
	for(int i=0;!ls.empty()||!rs.empty();i++){
		if(i%2==0){
			pair<int,int>x=*ls.begin();
			//cout<<curp<<" "<<-x.first<<" "<<-x.second<<endl;
			ans+=calc(curp,-x.first,-x.second);
			ls.erase(ls.find(x));
			rs.erase(rs.find({-x.second,-x.first}));
		}
		else{
			pair<int,int>x=*rs.begin();
			//cout<<curp<<" "<<x.second<<" "<<x.first<<endl;
			ans+=calc(curp,x.second,x.first);
			rs.erase(rs.find(x));
			ls.erase(ls.find({-x.second,-x.first}));
		}
	}
	total=max(total,ans+abs(curp));

	cout<<total<<endl;



}
 
	


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

int main(){

    ll x;
    cin >> x ;

    for(ll i=1;;i++){
        if((ll)(i+1)*i/2>=x){
            cout << i <<endl;
            break;
        }
    }

    return 0;
}

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

using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds; 

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX

const int MAXN=2e6+1;
const int M=998244353;

int cntr[MAXN],cntc[MAXN];

bool comp(pair<int,int> p1,pair<int,int> p2){
	return p1.first>p2.first;
}

int main(){
	
	int n,m,w;
	sfi(n) sfi(m) sfi(w)
	set<pair<int,int>> s;
	f(i,0,w){
		int x,y;
		sfi(x) sfi(y)
		cntr[x]++;
		cntc[y]++;
		s.insert({x,y});
	}

	vector<pair<int,int>> v,v1;

	f(i,1,n+1){
		if(cntr[i]!=0){
			v1.push_back({cntr[i],i});
		}
	}

	f(i,1,m+1){
		if(cntc[i]!=0){
			v.push_back({cntc[i],i});
		}
	}

	sort(v.begin(),v.end(),comp);
	sort(v1.begin(),v1.end(),comp);

	int maxi1=v[0].first,maxi2=v1[0].first;

	int cnt=0,cnt1=0;

	for(int i=1;i<=m;i++){
		if(cntc[i]==maxi1){
			cnt++;
		}
	}

	for(int i=1;i<=n;i++){
		if(cntr[i]==maxi2){
			cnt1++;
		}
	}

	cnt*=cnt1;

	int ans=v[0].first+v1[0].first-1;

	for(auto it:s){
		int r1=it.first;
		int c1=it.second;
		if(cntr[r1]+cntc[c1]==(ans+1)){
			--cnt;
		}

	}

	if(cnt)
		ans++;

	pfin(ans)

	return 0;
}

Measured memory_bytes: 28000
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

template<typename T> T MV(T v) { return v; }
template<typename T, typename... R> auto MV(T v, int s, R... r) { return vector<decltype(MV(v, r...))>(s, MV(v, r...)); }

int main() {
	int h, n;
	cin >> h >> n;
	vector<pair<int, int>> p(n);
	inc(i, n) { cin >> p[i].FI >> p[i].SE; }
	
	int INF = 1e9, M = h + 10000;
	auto dp = MV(INF, M);
	dp[0] = 0;
	inc(j, h) {
	inc(i, n) {
		setmin(dp[j + p[i].FI], dp[j] + p[i].SE);
	}
	}
	
	int ans = INF;
	incID(j, h, M) { setmin(ans, dp[j]); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
///int ->(-2147483648<->2147483647)
///unsigned int(0<->4294967295)
///long long int (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
///unsigned long long int (0 to 18,446,744,073,709,551,615)
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<stack>
#include<cstring>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<iomanip> ///setprecision
#include<cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define OPEN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","r",stdin)
#define INF 1000000000
#define ll long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define pdd pair<double,double>
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vd vector<double>
#define sci(value) scanf("%d%*c",&value)
#define scl(value) scanf("%lld%*c",&value)
#define pi  (2*acos(0))
#define pb push_back
#define valid(value123,value234,limitrow,limitcol) value123>=0&&value123<limitrow&&value234>=0&&value234<limitcol
//int fx[]= {0,0,1,-1,-1,1,-1,1};//kings move
//int fy[]= {1,-1,0,0,-1,1,1,-1};//kings move
//int fx[]={-2,-2,-1,-1, 1,1, 2,2};  // Knights Move
//int fy[]={-1, 1,-2, 2,-2,2,-1,1}; // Knights Move
//ll powFunction(ll a,ll b){if(b==0)return 1;ll re=powFunction(a,b/2);re=(re*re);if(b&1)re=(re*a);return re;}
///ll digitSum(ll a){ll ans=0;while(a){ans+=(a%10);a/=10;}return ans;}

#define MX 3005
#define mod 1000000007
int LCS[MX][MX];
string s1,s2;
int n,m;
int findLCS (int i,int j)
{
    if(i == n || j == m)
        return 0;
    if(LCS[i][j]!=-1)
        return LCS[i][j];
    if(s1[i]==s2[j])
        LCS[i][j]=1+findLCS(i+1,j+1);
    else
        LCS[i][j]=max(findLCS(i+1,j),findLCS(i,j+1));
    return LCS[i][j];
}
void printlcs(int ans)
{
    int i=0,j=0;
    while(i!=n && j!=m)
    {
        if(s1[i]==s2[j])
        {
            cout<<s1[i];
            i++;
            j++;
        }
        else
        {
            if(LCS[i+1][j]>LCS[i][j+1])
            {
                i++;
            }
            else
            {
                j++;
            }
        }
    }
}
int main()
{
    cin>>s1>>s2;
    n = s1.size();
    m = s2.size();
    memset(LCS,-1,sizeof LCS);
    int ans = findLCS(0,0);
    if(ans==0)
        printf(" \n");
    printlcs(ans);
    printf("\n");
}



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

int dp[101010];

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

	fill_n(dp, 101010, 1e9+1);
	dp[0] = 0;
	for (int i=0; i<n; ++i) {
		if (i+1 < n) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
		if (i+2 < n) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i])); 
	}

	int ans = dp[n-1];
	cout << ans << endl;
	
  return 0;
}


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

long double dp[16][3][3]={};
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int bx,by;
int tx,ty;

long double rec(int rest,int x,int y){
     //cout<<"x:"<<x<<"y:"<<y<<endl;
     if(x<0||x>2||y<0||y>2)return 0;
     if(dp[rest][x][y]>0)return dp[rest][x][y];

     if(rest==0){
	  if(x==tx&&y==ty)return 1;
	  else return 0;
     }
     long double sum=0;
     for(int i=0;i<4;i++){
	  if(((x+dx[i]==bx)&&(y+dy[i]==by))||x+dx[i]<0||x+dx[i]>2||y+dy[i]>2||y+dy[i]<0){
	       sum+=rec(rest-1,x,y);
	       }else{
	       sum+=rec(rest-1,x+dx[i],y+dy[i]);
	  }
     }
     sum=sum/4.0;
     dp[rest][x][y]=sum;
     return sum;
}
void topoint(char a,int &x,int &y){
     int tmp=a-'A';
     x=tmp/3;
     y=tmp%3;
     return;
}
int main(){
     int N;
     cout.precision(8);
     cout.setf(ios::fixed);
     while(cin>>N,N){
	  char s,t,b;
	  cin>>s>>t>>b;
	  int sx,sy;
	  topoint(s,sx,sy);
	  topoint(t,tx,ty);
	  topoint(b,bx,by);
	  //cout<<sx<<":"<<sy<<" "<<tx<<":"<<ty<<endl;
	  cout<<rec(N,sx,sy)<<endl;
	  for(int i=0;i<16;i++){
	       for(int j=0;j<3;j++){
		    for(int k=0;k<3;k++){
			 dp[i][j][k]=0;
		    }
	       }
	  }
		   
     }
     return 0;
}

Measured memory_bytes: 676
#include "bits/stdc++.h"
using namespace std;
#define LL long long int

//const LL len = 100000009;
//LL p;
//LL Prime[len+5];
//bool mark[len+5];
//LL cum[len+5];
//
//void Siv()
//{
//    p = 1;
//    cum[0] = 0;
//    mark[2] = mark[3] = false;
//
//    for(LL i = 2; i * i <= len; i++)
//    {
//        if(!mark[i])
//        {
//            for(LL j = i+i; j <= len; j += i)
//            {
//                mark[j] = true;
//            }
//        }
//    }
//
//    for(LL i = 2; i <= len; i++)
//    {
//        if(!mark[i])
//        {
//            Prime[p] = i;
//            cum[p] = cum[p-1] + Prime[p];
//            p++;
//        }
//    }
//}

int main()
{
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-b) <= d && abs(b-c) <= d || abs(a-c) <= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    //Siv();
//    LL T;
//    scanf("%lld", &T);
//    while(T-- > 0)
//    {
//        LL x, y;
//        scanf("%lld %lld", &x, &y);
//        printf("%lld\n", cum[y]-cum[x-1]);
//    }
}

/*
2
1 2
3 5
*/


Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    int x; cin >> x;
    vector<int> dp(100000, 0);

    queue<int> que;
    que.push(0);

    vector<int> dx = {100, 101, 102, 103, 104, 105};

    while (!que.empty()) {
        int c = que.front(); que.pop();
        for (int dx_: dx) {
            if (c+dx_ > 100000) continue;
            if (dp[c+dx_]) continue;
            dp[c+dx_] = 1;
            que.push(c+dx_);
        }
    }

    cout << dp[x] << endl;
    return 0;
}



Measured memory_bytes: 640
def even(num):
    if num & 1:
        return('uneven')
    else:
        return('even')

N = int(input())
A = list(map(int, input().split()))

n = 0
for a in A:
    if even(a) == 'uneven':
        n += 1

if even(n) == 'even':
    print('YES')
else:
    print('NO')


Measured memory_bytes: 14364
#include<iostream>
using namespace std;
int sum(int x)
{
  int s=0;
  while(x)
  {
    s+=x%10;
    x/=10;
  }
  return s;
}
int main()
{
  int n;
  cin >> n;
  if(n%sum(n)==0)
    cout << "Yes\n";
  else
    cout << "No\n";
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

bool isPrime(long long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (long long i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(void){
    ll X; cin >> X;

    if(X == 2){
        cout << 2 << endl;
    }else{
        if(X%2 == 0) X++;
        while(1){
            if(isPrime(X)){
                cout << X << endl;
                break;
            }
            X += 2;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

vector<int> divisor(int a){
    vector<int> res;
    res.push_back(a);
    for(int i=1; i<=sqrt(a); i++){
        if(a%i==0){
            res.push_back(i);
            if(i!=a/i) res.push_back(a/i);
        }
    }
    // sort(all(a));
    return res;
}

int main(){
    int n; cin >> n;
    map<int,int> num;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
        num[p[i]]++;
    }

    int ans=0;

    rep(i,n){
        vector<int> primes;
        primes=divisor(p[i]);
        bool check=true;
        rep(j,primes.size()){
            if(primes[j]==p[i]){
                if(num[primes[j]]>1){
                check=false;
                break;
            }
            }
            else{
            if(num[primes[j]]!=0){
                check=false;
                break;
            } 
            }
        }
        if(check==true) ans++;
    }
    
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 33084
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
vector<int>v;
int n,m,k; 
int main()
{
	scanf("%d%d",&k,&n);
	if (k%2==0)
	{
		printf("%d ",k/2);
		fo(i,1,n-1)printf("%d ",k);
	}
	else
	{
		v.resize(n,(k+1)/2);
		fd(i,n/2,1)
		{
			if (--v.back()==0)
			{
				v.pop_back();
				continue;
			}
			while (v.size()<n)v.push_back(k);
		}for(int i:v)printf("%d ",i);
	}
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    double x[n];
    string u[n];
    rep(i, n) cin >> x[i] >> u[i];
    double ans = 0;
    rep(i, n){
        if (u[i] == "JPY"){
            ans += x[i];
        }else{
            ans += x[i] * 380000;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[]) {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int A, B;
    std::cin >> A >> B;
    int counter = 0;
    for (int i=A; i<=B; i++) {
        std::string s = std::to_string(i);
        if (s[0] == s[4] && s[1] == s[3]) {
            counter++;
        }
    }
    std::cout << counter << '\n';
    return 0;
}

Measured memory_bytes: 888
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int N, Q;
    scan(N, Q);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }
    auto add = new long[](N);
    foreach (j ; 0 .. Q) {
        int pj, xj;
        scan(pj, xj);
        pj--;
        add[pj] += xj;
    }

    void dfs(int v, int p, long a) {
        add[v] += a;
        foreach (u ; adj[v]) if (u != p) {
            dfs(u, v, add[v]);
        }
    }

    dfs(0, -1, 0);

    writefln("%(%s %)", add);
}




















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 34300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n, m;
  cin >> n >> m;

  map<int, vector<int>> l;
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;

    if (l.find(a) == l.end())
    {
      vector<int> tmp = {b};
      l[a] = tmp;
    }
    else
    {
      l[a].push_back(b);
    }
  }

  bool success = false;
  for (int island : l[1])
  {
    if (find(l[island].begin(), l[island].end(), n) != l[island].end())
    {
      success = true;
      break;
    }
  }

  if (success)
  {
    cout << "POSSIBLE" << endl;
  }
  else
  {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 19320
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }



signed main()
{
	string s;
	cin >> s;
	
	if (s[s.length() - 1] == 's')
	{
		s += "es";
	}
	else
	{
		s += "s";
	}
	cout << s << endl;
}



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

int main() {
    int n, r;
    while(cin >> n >> r) {
        if(n == 0 && r == 0) break;
        vector<int> array(51); for(int i=0; i<n; i++) array[i] = n-i;
        vector<int> temp(51);
        for(int i=0; i<r; i++) {
            int a, b;
            cin >> a >> b;
            a--;
            
            int x = 0, y = b;
            for(int j=0; j<n; j++) {
               if(j < a || a + b - 1 < j) {
                   temp[y] = array[j];
                   y++;
               }
               else {temp[x] = array[j]; x++;}
            }
            
            for(int j=0; j<n; j++) array[j] = temp[j];
            // for(int j=0; j<n; j++) cout << array[j] << " ";
            // cout << endl;
        }
        cout << array[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 18;
const int maxDim = 1 << maxN;
const int inf = 1000000000;

int n, i, j, limit;
pair<int, int> best[maxDim];
int ans[maxN];

pair<int, int> combine(pair<int, int> A, pair<int, int> B) {
    if (A.first < B.first) swap(A, B);
    return mp(A.first, max(A.second, B.first));
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d", &n);
    limit = 1 << n;

    for (i = 0; i < limit; i++) {
        scanf("%d", &best[i].first);
        best[i].second = -inf;
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < limit; j++) {
            if ((j >> i) & 1) 
                best[j] = combine(best[j], best[j ^ (1 << i)]);
        }
    }

    for (i = 1; i < limit; i++) {
        ans[i] = max(ans[i - 1], best[i].first + best[i].second);
        printf("%d\n", ans[i]);
    }


    return 0;
}


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

using namespace std;

const int MAX = 2e5 + 5 ;
int arr[MAX] ;
vector< vector<int> >st(MAX) ;
vector< vector<int> >en(MAX) ;
vector< pair<int , pair<int , int> > >vp ;
int n , m;

int main()
{
    scanf("%d %d" , &n , &m) ;
    for(int i = 0 ; i < n ; ++i)
    {
        int l , r , x ;
        scanf("%d %d %d" , &l , &r , &x) ;
        vp.push_back({x , {l , r}}) ;
    }
    sort(vp.begin() , vp.end()) ;
    for(int i = 0 ; i < m ; ++i)
        scanf("%d" , &arr[i]) ;
    for(int i = 0 ; i < n ; ++i)
    {
        int a = vp[i].second.first - vp[i].first ;
        int b = vp[i].second.second - vp[i].first ;
        int idx = lower_bound(arr , arr + m , a) - arr ;
        int idx2 = lower_bound(arr , arr + m , b) - arr ;
        st[idx].push_back(vp[i].first) ;
        en[idx2].push_back(vp[i].first) ;
    }
    multiset<int>s ;
    for(int i = 0 ; i < m ; ++i)
    {
        for(auto &j : st[i])
            s.insert(j) ;
        for(auto &j : en[i])
            s.erase(s.find(j)) ;
        if(s.size() == 0)
            printf("%d\n" , -1) ;
        else
            printf("%d\n" , *s.begin()) ;
    }
    return 0 ;
}


Measured memory_bytes: 30192
def factorize(n):
    from collections import defaultdict
    d = defaultdict(int)
    for i in range(2, int(n**0.5)+1):
        while n%i==0:
            d[i] += 1
            n //= i
        if not n:
            break
    if n>1:
        d[n] += 1
    return d


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

MOD = 10**9+7
n = N+30
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

v = 1
for i in d.values():
    v *= comb(i+N-1, i)
    v %= MOD
print(v)

Measured memory_bytes: 11316
object Main {
  def main(args: Array[String]): Unit = {
    val factors  = scala.io.StdIn.readLine.split(" ").map{_.toInt}
    var map: Array[String] = Array.empty

    ( 0 until factors( 0 ) ).foreach { i =>
      map ++= scala.io.StdIn.readLine.split( "" ).filter( s => s != "\n" )
    }

    ( 0 until map.length ).foreach{ i =>
      if( map( i ) == "." ) print( countBombsAround( i, map, factors( 0 ), factors( 1 ) ) )
      else print( map( i ) )

      if( i % factors( 1 ) == factors(1) - 1 ) println( "" )
    }
  }

  def countBombsAround( point: Int, map: Array[String], y_size: Int,  x_size: Int): Int = {
    var count = 0

    ( -1 to 1 ).foreach { i =>
      ( -1 to 1 ).foreach { j =>
        val check_y = point/x_size + i
        val check_x = point%x_size + j

        if( !( i == 0 && j == 0 ) && y_size > check_y && check_y >= 0 && x_size > check_x && check_x >= 0) {
          if( map( check_y*x_size + check_x ) == "#" ) count += 1
        }
      }
    }

    return count
  }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		int n = sc.nextInt();
		char[][] map = new char[2*n][2*n];
		char[][] S = new char[n][n];
		for(int i=0; i<n; i++) {
			String s = sc.next();
			for(int j=0; j<n; j++) {
				S[i][j] = s.charAt(j);
			}
		}
		if(n==1) {
			System.out.println(1);
			return;
		}
		{
			for(int l=0; l<2*n; l+=n) {
				for(int k=0; k<2*n; k+=n) {
					for(int i=0; i<n; i++) {
						for(int j=0; j<n; j++) {
							map[l+i][k+j] = S[i][j];
						}
					}		
				}	
			}
		}
		int ans = 0;
		for(int i=0; i<n; i++) {
			if(isSym(i, 0, n, map)) {
				ans += (n-i);
			}
		}
		for(int i=1; i<n; i++) {
			if(isSym(0, i, n, map)) {
				ans += (n-i);
			}
		}
		System.out.println(ans);
	}
	
	static boolean isSym(int i, int j, int n, char[][] map) {
		for(int ii=0; ii<n; ii++) {
			for(int jj=ii; jj<n; jj++) {
				if(map[i+ii][j+jj]!=map[i+jj][j+ii]) {
					return false;
				}
			}
		}
		return true;
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 26040
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10; 
const int mod = 1e9+7;
long long b[N],c[N],d[N],a[N];
int main(){
	int n;
	cin>>n;
	a[1]=1;
	b[1]=1;
	c[1]=0;
	d[1]=8;
	for(int i=2;i<=n;i++){
		a[i]=(a[i-1]*9+d[i-1])%mod;
		b[i]=(b[i-1]*9+d[i-1])%mod;
		c[i]=(a[i-1]+b[i-1]+c[i-1]*10)%mod;
		d[i]=(d[i-1]*8)%mod; 
	//	printf("%lld %lld %lld %lld\n",a[i],b[i],c[i],d[i]);
	}
	printf("%lld\n",c[n]);

} 

Measured memory_bytes: 34868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;
        public string S, T;
        public void Run()
        {
            S = Console.ReadLine();
            T = Console.ReadLine();
            int SL = S.Length;
            int TL = T.Length;
            int[,] DP = new int[SL + 1, TL + 1];

            for (int s = 1; s <= SL ; s++)
            {
                for (int t = 1; t <= TL; t++)
                {
                    DP[s, t] = Math.Max(DP[s, t], DP[s - 1, t - 1] + (S[s - 1] == T[t - 1] ? 1 : 0));
                    DP[s, t] = Math.Max(DP[s, t], DP[s - 1, t] + 0);
                    DP[s, t] = Math.Max(DP[s, t], DP[s, t - 1] + 0);
                }
            }

            // 復元
            {
                int s = SL;
                int t = TL;
                int v = DP[s, t];
                List<char> chs = new List<char>();
                while (s > 0 && t > 0 && v > 0)
                {
                    if (v == DP[s - 1, t])
                    {
                        s -= 1;
                        continue;
                    }

                    if (v == DP[s, t - 1])
                    {
                        t -= 1;
                        continue;
                    }

                    if (v == DP[s - 1, t - 1] + 1)
                    {
                        chs.Add(S[s-1]);
                        s -= 1;
                        t -= 1;
                        v -= 1;
                        continue;
                    }
                }

                chs.Reverse();

                Console.WriteLine(string.Join("", chs));
            }

        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 46176
#include<stdio.h>
int main()
{
    int d;
    scanf("%d",&d);
    if(d==22)
    {
        printf("Christmas Eve Eve Eve\n");
    }
    else if(d==23)
    {
        printf("Christmas Eve Eve\n");
    }
    else if(d==24)
    {
        printf("Christmas Eve\n");
    }
    else
    {
        printf("Christmas\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main (void)
{
    int cnt=0,h,w,i,j;
    scanf("%d %d",&h,&w);
    char s[10][10];
    for(i=0;i<h;i++)
    {
        scanf("%s",s[i]);
    }
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            if(s[i][j]=='#')
            {
                cnt++;
            }
        }
    }
    if(cnt<h+w)
    {
        puts("Possible");
    }else{
        puts("Impossible");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main(){
    int N, K; cin >> N >> K;
    vector<int> a;
    for (int i = 0; i < N; i++){
        int h; cin >> h;
        a.push_back(h);
    }
    sort(a.begin(), a.end());
    int ans = 1000000000;
    for (int i = 0; i+K-1 < N; i++){
        ans = min(ans, a[i+K-1] - a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  sort(rall(a));
  a.pb(0);
  //cout<<a;
  int d;
  rep(i,n){
    if(a[i]==i+1){
      //cout<<"yoko"<<endl;
      for(d=0;a[i]==a[i+1];++i) ++d;
      break;
    }else if(a[i]!=a[i+1]){
      if(a[i+1]==i+1){
	int f1=0,f2=0;
	if((a[i]-a[i+1])%2){
	  //cout<<"bokoA"<<endl;
	  d=1;
	}else{
	  //cout<<"bokoB"<<i<<endl;
	  for(++i;a[i]==a[i+1];++i) ++f2;
	  d=1-f2%2;
	}
	break;
      }else if(a[i+1]<i+1){
	//cout<<"tate"<<endl;
	d=a[i]-(i+1);
	break;
      }
    }
  }
  //cout<<d<<endl;
  cout<<(d%2?"First":"Second")<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

namespace IO {
    template <typename _T>
    inline bool read (_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return false;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input () {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};
using namespace IO;

#define reg register
#define MAX_N 200007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
typedef long long ll;

int N;
double x, y, d;

int main () {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(x), read(d);
    y = (N * 2.0 - 1.0) * d + x;
    double res = 0.0;
    for (int i = (N << 1); i; i -= 2) {
        res += (x + y) / 2.0;
        x += (x * 2.0 + 5.0 * d) / (1.0 * i);
        y += (y * 2.0 - 5.0 * d) / (1.0 * i);
        if (i > 2) d = (y - x) / (i * 1.0 - 2.0);
    }
    printf("%.12lf\n", res);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int[] input;
    public static void main(String[] args) {
        while(read()){
            solve();
        }
    }
    static boolean read(){
        n = sc.nextInt();
        if(n == 0)return false;

        input = new int[n];
        for(int i = 0; i < n; i++)input[i] = sc.nextInt();
        return true;
    }
    static void solve(){
        int max = Integer.MIN_VALUE;
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum = input[i];
            max = Math.max(sum, max);
            for(int j = i+1; j < n; j++){
                sum +=  input[j];
                max = Math.max(sum, max);
            }
            sum = 0;
        }
        if(n == 1){
            System.out.println(input[0]);
        }else{
            System.out.println(max);
        }
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int N, M, A, X[100];
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        scanf("%d", &X[i]);
    }
    scanf("%d", &M);
    for(int i = 0; i < M; i++){
        scanf("%d", &A);
        if(X[A-1] != X[A]-1 && X[A-1] != 2019) X[A-1] += 1;
    }
    
    for(int i = 0; i < N; i++){
        printf("%d\n", X[i]);
    }
    return 0;
}


Measured memory_bytes: 3224
n = gets.strip.to_i

MOD = 10**9+7

dp = {'' => 1}

n.times do
  next_hash = Hash.new(0)

  dp.each do |k, v|
    'AGCT'.chars.each do |c|
      # s = (k+c)[1..-1]
      s = (k+c)
      s = s[1..-1] if s.length == 5
      next if s.match(/AGC|GAC|ACG|AG.C|A.GC/)
      next_hash[s] += v
      next_hash[s] %= MOD
    end
  end
  # p dp
  # p '-'

  dp = next_hash
end

# p dp
p dp.values.inject(:+) % MOD


Measured memory_bytes: 2172