akhauriyash/Code-Regression huggingface dataset:
import numpy as np
from collections import Counter

# 最頻値
def mode(list):
    c = Counter(list)
    freq_scores = c.most_common()
    max_count = freq_scores[0][1]
    modes = []
    for num in freq_scores:
        if num[1] == max_count:
            modes.append(num[0])
    return(modes)

n, k = map(int, input().split())
h_list = list(map(int, input().split()))
h_list.sort()
h_list.reverse()
del h_list[0:k]
print(sum(h_list))

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

    const int mn=1e5+7;
    int n,q,a,cnt[mn],b,c;
    long long sum;

    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;++i) {scanf("%d",&a);cnt[a]++;sum+=a;}
        scanf("%d",&q);
        while(q--) {
            scanf("%d%d",&b,&c);
            sum=sum+1ll*cnt[b]*(c-b);
            cnt[c]+=cnt[b];
            cnt[b]=0;
            printf("%lld\n",sum);
        }
    }

Measured memory_bytes: 4176
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  s[3]='8';
  P(s);
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
n=int(input())
s=input()

w_num=0
b_num=0
w_l=[0]
b_l=[0]

for i in s:
 if i=='.':
  w_num+=1
 else:
  b_num+=1
 w_l.append(w_num)
 b_l.append(b_num)

ans=10**5
for i in range(n+1):
 ans=min(ans,b_l[i]+(w_num-w_l[i]))
print(ans)

Measured memory_bytes: 12768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

const int N = 5e4;
int main(){
	int a, b, d;
	while (cin >> a >> b >> d, a){
		tuple<ll, ll, pair<ll, ll>> ans = MT(1e6, 0, MP(0, 0));
		for (ll y = -N; y <= N; ++y){
			ll x = d - b*y;
			if (x%a) continue;
			x /= a;
			ll ax = abs(x), ay = abs(y);
			ans = min(ans, MT(ax + ay, a*ax + b*ay, MP(ax, ay)));
		}
		auto p = get<2>(ans);
		cout << p.first << ' ' << p.second << endl;
	}

	return 0;
}

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

int main()
{
	int k;
	cin>>k;
	int r=7%k;
	int i=1;
	while(r>0&&i<=k)
	{
		r=((r*10)%k+7)%k;
		i++;
	}
	if(r!=0)
		i=-1;
	cout<<i;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	string w;
	cin>>w;
	int yh=0;
	for(int i=0;i<w.length();i++)
	{
		int temp=w[i];
		yh=yh^temp;
	}
	if(yh==0){
		cout<<"Yes";
	}
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = Integer.parseInt(sc.nextLine());
			if(n == 0) break;
			HashMap<String, Integer> log = new HashMap<String, Integer>();
			HashMap<String, Integer> record = new HashMap<String, Integer>();
			for(int i = 0 ; i < n; i++){
				String s = sc.nextLine();
				String [] ss = s.split(" ");
				String [] time = ss[1].split(":");
				int h = Integer.parseInt(time[0]);
				int m = Integer.parseInt(time[1]);
				int value = h * 60 + m;
				if(ss[2].equals("I")){
					record.put(ss[3], value);
				}
				else{
					if(ss[3].equals("000")){
						for(String key: record.keySet()){
							if(key.equals("000")) continue;
							int diff = value - Math.max(record.get(key), record.get("000"));
							//System.out.println("diff = " + diff);
							if(log.containsKey(key)){
								log.put(key, log.get(key) + diff);
							}
							else{
								log.put(key, diff);
							}
						}
						record.remove(ss[3]);
					}
					else{
						if(record.containsKey("000")){
							int diff = value - Math.max(record.get(ss[3]), record.get("000"));
							record.remove(ss[3]);
							if(log.containsKey(ss[3])){
								log.put(ss[3], log.get(ss[3]) + diff);
							}
							else{
								log.put(ss[3], diff);
							}
						}
						else{
							record.remove(ss[3]);
						}
					}
				}
//				System.out.println("i = " + i);
//				for(String key: record.keySet()){
//					System.out.println("key = " + key + " value = " + record.get(key));
//				}
//				System.out.println();
//				for(String key : log.keySet()){
//					System.out.println("ley = " + key + "value = " + log.get(key));
//				}
//				System.out.println("---");
			}
			int max = 0;
			for(String key: log.keySet()){
				//System.out.println("key = " + key + " value = " + log.get(key));
				if(key.equals("000")) continue;
				max = Math.max(max, log.get(key));
			}
			System.out.println(max);
		}
	}

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

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

using namespace std;

int main(){

  int K,A,B,c;
  double N;
  const double PI=3.14159265358979323846;
  //cin>>S>>T;
  
  cin>>K;
  cin>>A>>B;
  //cin>>U;

  c=A/K;
  
  if((c+1)*K<=B or c*K==A){
  cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
    return 0;
}


Measured memory_bytes: 3104
using System;

namespace QuestionA
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split();
            var kyori = double.Parse(inputs[0]);
            var time = double.Parse(inputs[1]);
            var speed = double.Parse(inputs[2]);

            if(kyori / speed <= time)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}

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

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

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

#include <cmath>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    auto V = make_v(n, d, 0);
    REP(i, 0, n) {
        REP(j, 0, d) {
            cin >> V[i][j];
        }
    }
    int ans = 0;
    REP(i, 0, n) {
        REP(j, i + 1, n) {
            double dis = 0.0;
            REP(k, 0, d) {
                dis += (V[i][k] - V[j][k]) * (V[i][k] - V[j][k]);
            }
            dis = sqrt(dis);
            dis -= int(dis);
            if (abs(dis) < 1e-6) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;
ll dp[52][3][3]={};
int main()
{
    int n;
    cin >>n;
    string s[2];
    rep(i,2) cin >>s[i];

    int p = 0;
    if(s[0][0]==s[1][0])
    {
        rep(i,3) dp[0][i][i]=1;
        ++p;
    }
    else
    {
        rep(i,3)rep(j,3)if(i!=j)
        {
            dp[0][i][j]=1;
            dp[1][i][j]=1;
        }
        p+=2;
    }

    while(p<n)
    {
        bool yoko = true;
        if(p==n-1) yoko=false;
        else
        {
            if(s[0][p]!=s[0][p+1]) yoko=false;
        }

        if(yoko)
        {
            rep(i,3)rep(j,3)if(i!=j)
            {
                rep(k,3)if(k!=i && k!=j) (dp[p][i][j]+=dp[p-1][k][k])%=mod;

                rep(k,3)rep(l,3)if(k!=l && k!=i && l!=j) (dp[p][i][j]+=dp[p-1][k][l])%=mod;

                dp[p+1][i][j] = dp[p][i][j];
            }
            p+=2;
        }
        else
        {
            rep(i,3)
            {
                rep(k,3)if(k!=i) (dp[p][i][i]+=dp[p-1][k][k])%=mod;

                rep(k,3)rep(l,3)if(k!=l && k!=i && l!=i) (dp[p][i][i]+=dp[p-1][k][l]%=mod);
            }
            ++p;
        }
    }

    ll ans = 0;
    rep(i,3)rep(j,3) (ans+=dp[n-1][i][j])%=mod;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<vector<int>> v(n);
	int first;
	cin >> first;
	v[0].push_back(first);
	int last = first, index = 0;
	for (int i = 1; i < n; i++) {
		int k;
		cin >> k;
		if (k != last) {
			index++;
			last = k;
		}
		v[index].push_back(k);
	}
	int sum = 0;
	for (auto numbers : v) {
		sum += numbers.size() / 2;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define OPERAND 100
#define OPERATER 99

int stack[OPERAND], top = -1;
void push( int ); 
int pop( void ); 


int main (){
    char data[100];
    int fx, lx;// fx means former x, and fy means latter x


    //inputing data, and storing or calculating the data
    while ( scanf("%s", data) != EOF ){
	if (data[0] == '+'){//addition procedure
	    lx = pop();
	    fx = pop();
	    fx = fx + lx;
	    push(fx);
	}
	else if (data[0] == '-'){//subtraction procedure
	    lx = pop();
	    fx = pop();
	    fx = fx - lx;
	    push(fx);
	}
	else if (data[0] == '*'){//multiplication procedure
	    lx = pop();
	    fx = pop();
	    fx = fx * lx;
	    push(fx);
	}
	else {//store the input data
	    push(atoi(data));
	}
    }
    //display the calculation result
    printf("%d\n", pop());

    return 0;
}


void push( int data ){

    //store the data,and update the top number
    top++; //this first number is '-1'
    stack[top] = data;
    

    return ;
}


int pop( void ){
    int retval;

    retval = stack[top];
    top--;

    return retval;
}



Measured memory_bytes: 2052
#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>;

const int MX = 100005;

vector<P> g[MX];
int x[MX];
bool used[MX];

vector<int> ans;
int dfs(int v) {
  used[v] = true;
  int res = x[v];
  for (P e : g[v]) {
    if (used[e.first]) continue;
    int r = dfs(e.first);
    if (r) ans.push_back(e.second);
    res ^= r;
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  x[0] = a[0].second;
  rep(i,n-1) x[i+1] = a[i].second^a[i+1].second;
  x[n] = a[n-1].second;

  rep(i,m) {
    int l, r;
    cin >> l >> r;
    l = lower_bound(a.begin(),a.end(),P(l,0))-a.begin();
    r = upper_bound(a.begin(),a.end(),P(r,1))-a.begin();
    g[l].emplace_back(r,i+1);
    g[r].emplace_back(l,i+1);
  }

  rep(i,n+1) {
    if (used[i]) continue;
    if (dfs(i)) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  rep(i,ans.size()) printf("%d ", ans[i]);
  cout << endl;
  return 0;
}


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, layer[202];
int adj[202][202];
char eat[202];

int ans = -1;

int que[202], l, r;

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf(" %s", eat + 1);
		for(int j = 1; j <= n; j++){
			adj[i][j] = eat[j] - '0';
		}
	}
	for(int i = 1; i <= n; i++){
		memset(layer, -1, sizeof(layer));
		l = 0, r = 1, que[1] = i;
		layer[i] = 0;
		
		int max_layer = 0;
		
		while(l < r){
			int cur = que[++l];
			for(int j = 1; j <= n; j++){
				if(adj[cur][j] == 1 && layer[j] == -1){
					layer[j] = layer[cur] + 1;
					que[++r] = j;
					max_layer = layer[j];
				}
			}
		}
		
		bool ok = true;
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(adj[i][j] && abs(layer[i] - layer[j]) != 1){
					ok = false;
					break;
				}
			}
		}
		
		if(ok){
			ans = max(ans, max_layer + 1);
		}
	}
	printf("%d\n", ans);
}

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

d = []
for _ in range(N):
    a, b = map(int, input().split())
    d.append((a, b))

d.sort(key=lambda x: x[0])

c = 0
for p in d:
    c += p[1]
    if c >= K:
        print(p[0])
        break


Measured memory_bytes: 18192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String alpha = sc.next();

        Character a = alpha.charAt(0);

        if (Character.isUpperCase(alpha.charAt(0))) {
            System.out.println("A");
        }else {
            System.out.println("a");
        }

    }
}


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

int main()
{
  int64_t N, t = 0;
  cin >> N;
  vector<pair<int64_t, int64_t>> vp(N);
  for (int i = 0; i < N; i++)
  {
    cin >> vp[i].second >> vp[i].first;
  }
  sort(vp.begin(), vp.end());
  for (int i = 0; i < N; i++)
  {
    t += vp[i].second;
    if (t > vp[i].first)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

vector<int> v[202020];

signed main() {
  int H, W, N;
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    v[y].push_back(x);
  }

  int ans = H, cnt = 0;
  for (int i = 1; i <= W; i++) {
    sort(v[i].begin(), v[i].end());
    for (auto h : v[i]) {
      if (h - cnt == i) cnt++;
      if (h - cnt > i) ans = min(ans, h - 1);
    }
  }

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


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


vector<pair<int,string> > sort(vector<pair<int,string> > data){
	int len = data.size();
	for(int i=1;i<len;i++){
		for(int j=len-1;j>=i;j--){
			if( data[j-1].first < data[j].first ){
				swap(data[j-1],data[j]);
			}
		}
	}
	return data;
}





int main(){
    int n;
    bool f = false;
    while(cin>>n){
        if(n==0)break;
        if(f)cout<<endl;
        else f=true;
        
        vector< pair<int,string> > data;
        rep(i,n){
            string s;int w,l,d;
            cin>>s>>w>>l>>d;
            int p = w*3+d*1;
            data.pb(make_pair(p,s));
        }
		
		data = sort(data);        
        rep(i,data.size()){
            cout<<data[i].second<<","<<data[i].first<<endl;
        }
    }
}

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

using namespace std;

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

    int f = (3 * n);
    int a[f];
    for(int i = 0; i < f; i++) cin >> a[i];
    sort(a, a + f);

    // for(int i = 0; i < f; i++) cout << a[i] << " ";
    // cout << endl;



    int x = 0;
    long long sum = 0;
    for(int i = f - 2; i >= 0; i -= 2)
    {
        x++;
        if(x > n) break;
        sum += 1ll*a[i];
    }
    cout << sum << "\n";
}


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

int main(){
    int n; ll k; cin >> n >> k;
    vector<int> A(n),F(n);
    ll ans = 0;
    rep(i,n) cin >> A[i];
    rep(i,n) cin >> F[i];
    sort(ALL(A));
    sort(F.rbegin(),F.rend());
    ll ng = -1,ok = 1e18;
    while(ok-ng > 1){
        ll c = (ng+ok)/2;
        bool check = [&]{
            ll s = 0;
            rep(i,n){
                s += max(0ll,A[i]-c/F[i]);
            }
            return s <= k;
        }();
        if(check) ok = c; else ng = c;
    }
    cout << ok << endl;
}

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

int main(){
  int n,a;

  for(;;){
    cin >> n;
    if(!n)break;

    vector<int> color;
    vector<int> num;
    for(int i=1;i<=n;i++){
      cin >> a;
      if(color.empty()){
	color.push_back(a);
	num.push_back(1);
      }else{
	if(!(i&1) && color.back()!=a){
	  color[(int)color.size()-1] = a;
	  num[(int)num.size()-1]++;
	  if(color.size()>1){
	    num[(int)num.size()-2] += num[(int)num.size()-1];
	    color.erase(color.begin()+(int)color.size()-1);
	    num.erase(num.begin()+(int)num.size()-1);
	  }
	}else{
	  if(color.back()==a)num[(int)num.size()-1]++;
	  else{
	    color.push_back(a);
	    num.push_back(1);
	  }
	}
      }
    }
    int ans = 0;
    for(int i=0;i<(int)color.size();i++)
      if(!color[i])ans += num[i];
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x: a) cin >> x;

  unordered_map<int, ll> left_count, right_count;
  for (int i = 0; i < n; i++) {
    left_count[i-a[i]]++;
    right_count[i+a[i]]++;
  }

  ll ans = 0;
  for (auto &x: left_count) {
    ans += x.second * right_count[x.first];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 27120
#include<stdio.h>
int main()
{
    int n,m,s,b,i,j;
    int a[100];
    scanf("%d",&n);
    scanf("%d%d",&m,&b); 
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    s=0;
    for(i=0;i<n;i++)
    {
        if(a[i]<m)
        {
            for(j=1;;j++)
            {
                if(j*a[i]+1>m)
                {
                    s+=j-1;
                    break;
                }                
            }
        }
    }
    printf("%d\n",s+b+n);
    return 0;
}

Measured memory_bytes: 128
from collections import Counter
N,K = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
ctr = Counter()
for a,b in src:
    ctr[a] += b

tmp = 0
for k,v in sorted(ctr.items()):
    tmp += v
    if tmp >= K:
        print(k)
        exit()

Measured memory_bytes: 26420
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int n, w;
int c[105], v[105];
ll dp[100005];

int main(){
    fio;
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> c[i] >> v[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = w - c[i]; j >= 0; j--){
            dp[j + c[i]] = max(dp[j + c[i]], dp[j] + v[i]);
        }
    }
    cout << *max_element(dp,dp+w+1) << '\n';
}

Measured memory_bytes: 1024
from collections import deque
INF = 10**10
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
mat = []
for _ in range(h):
    s = input()
    mat.append(s)

costs = [[INF for _ in range(w)] for _ in range(h)]
costs[ch-1][cw-1] = 0
queue = deque()
queue.append((ch-1, cw-1))
while len(queue) > 0:
    x, y = queue.popleft()
    for i in range(4):
        dx = [-1, 0, 1, 0][i]
        dy = [0, -1, 0, 1][i]
        nx = x+dx
        ny = y+dy
        if nx < 0 or h <= nx or ny < 0 or w <= ny:
            continue
        if mat[nx][ny] == "#":
            continue
        if costs[nx][ny] > costs[x][y]:
            costs[nx][ny] = costs[x][y]
            queue.appendleft((nx, ny))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nx = x+i
            ny = y+j
            if nx < 0 or h <= nx or ny < 0 or w <= ny:
                continue
            if mat[nx][ny] == "#":
                continue
            if costs[nx][ny] > costs[x][y] + 1:
                costs[nx][ny] = costs[x][y] + 1
                queue.append((nx, ny))
if costs[dh-1][dw-1] == INF:
    print(-1)
else:
    print(costs[dh-1][dw-1])



Measured memory_bytes: 94676
import bisect
n = int(input())
S = list(input())
R, G, B = [], [], []
for i in range(n):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)
r = len(R)
g = len(G)
b = len(B)
cnt = 0
Rset, Gset, Bset = set(R), set(G), set(B)
# RGB
for i in range(r):
    g0 = bisect.bisect_right(G, R[i])
    for j in range(g0, g):
        b0 = bisect.bisect_right(B, G[j])
        cnt += b - b0
        x = 2*G[j]-R[i]
        if x in Bset:
            cnt -= 1
# RBG
for i in range(r):
    b0 = bisect.bisect_right(B, R[i])
    for j in range(b0, b):
        g0 = bisect.bisect_right(G, B[j])
        cnt += g - g0
        x = 2*B[j]-R[i]
        if x in Gset:
            cnt -= 1
# GBR
for i in range(g):
    b0 = bisect.bisect_right(B, G[i])
    for j in range(b0, b):
        r0 = bisect.bisect_right(R, B[j])
        cnt += r - r0
        x = 2*B[j]-G[i]
        if x in Rset:
            cnt -= 1
# GRB
for i in range(g):
    r0 = bisect.bisect_right(R, G[i])
    for j in range(r0, r):
        b0 = bisect.bisect_right(B, R[j])
        cnt += b - b0
        x = 2*R[j]-G[i]
        if x in Bset:
            cnt -= 1
# BRG
for i in range(b):
    r0 = bisect.bisect_right(R, B[i])
    for j in range(r0, r):
        g0 = bisect.bisect_right(G, R[j])
        cnt += g - g0
        x = 2*R[j]-B[i]
        if x in Gset:
            cnt -= 1
# BGR
for i in range(b):
    g0 = bisect.bisect_right(G, B[i])
    for j in range(g0, g):
        r0 = bisect.bisect_right(R, G[j])
        cnt += r - r0
        x = 2*G[j]-B[i]
        if x in Rset:
            cnt -= 1
print(cnt)


Measured memory_bytes: 71696
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,k;
    cin >> n >> k;
    vector<pii > p;
    rep(i,n){
        intl a,b;
        cin >> a >> b;
        p.pb(mp(a,b));
    }
    sort(all(p));
    intl cnt = 0;
    rep(i,n){
        cnt += p[i].second;
        if(cnt >= k){
            cout << p[i].first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 2548
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pipii;

map<int, int> dp;
void takeOne(int x) {
  if(--dp[x] == 0) dp.erase(x);
}

void solve() {
  int n;
  cin >> n;
  vector<pii> ret;
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    dp[t]++;
  }
  int amt = n;
  while(amt-- > 1) {
    int biggest = dp.rbegin()->first;
    if(biggest <= 0) {
      int other = dp.begin()->first;
      takeOne(other);
      takeOne(biggest);
      ret.push_back({biggest, other});
      dp[biggest-other]++;
    }
    else {
      takeOne(biggest);
      int newBiggest = dp.rbegin()->first;
      if(newBiggest > 0) {
        // we can still merge into something positive, so subtract away!
        int other = dp.begin()->first;
        takeOne(other);
        ret.push_back({other, biggest});
        dp[other-biggest]++;
      }
      else {
        // build into this one
        int other = dp.begin()->first;
        takeOne(other);
        ret.push_back({biggest, other});
        dp[biggest-other]++;
      }
    }
  }
  cout << dp.begin()->first << "\n";
  for(pii out: ret) {
    cout << out.first << " " << out.second << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 3700
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int N,t,i;
set<int> d;
inline void solve(){
  IN(N);
  REP(i,N){
    IN(t);
    d.insert(t);
  }
  OUT(d.size());
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			while(true){	//nextlineがeofならエラーを吐いて自動的に止まる
			int n = Integer.parseInt(br.readLine());
			System.out.println(NumComCalcurate(n));
			}
		} catch (Exception e){}
	}
	static int NumComCalcurate(int n){
		int count = 0;
		for(int a=0; a<=9; a++){
			for(int b = 0; b<=9; b++){
				for(int c = 0; c<=9; c++){
					for(int d= 0; d<=9; d++){
						if(a+b+c+d==n){count+=1;
						}
					}
				}
			}
		}
		return count;
	}
}

Measured memory_bytes: 18800
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    r = 0
    if False:
        for i in range(K+1):
            r += (A[-i-1] - A[i]) * cmb(N-i-1, K-1, mod)
    else:
        for i in range(N-K+1):
            r += (A[-i-1] - A[i]) * cmb(N-i-1, K-1, mod)
 
    print(r % mod)
def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, 10 ** 6 + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


main()



Measured memory_bytes: 132956
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
#define int long long
vector<ll> f(ll n) {
    vector<ll> v;
    int k = n;
    int count=1;
    for(int i = 2;i<=k;i++) {
        if(n%i==0) {
            while(n%i==0) {
                v.pb(i);
                n/=i;
                count++;
            }
        }
    }
    return v;
}
signed main() {
    vi prime;
    for(int i = 2;i<=1000;i++) {
        bool ok = false;
        for(int j = 2;j<=sqrt(i);j++) {
            if(i%j==0) {
                ok = true;
                break;
            }  
        }
        if(ok)continue;
        prime.pb(i);
    }
    // for(auto p:prime) cout << p << ' ';
    // cout << prime.size() << endl;
    int n;cin >> n;
    int count = 1;
    rep(i, 168) {
        int cnt = 0;
        int N = n;
        while(N/prime[i]!=0) {
            cnt+=N/prime[i];
            N/=prime[i];
            // cnt++;
        }
        // cout << cnt << endl;
        // cout << prime[i] << ":" << cnt << endl;
        count*=cnt+1;
        count%=mod;
        // cout << count << endl;
    }
    cout << count << endl;
    // cout << fact(6) << endl;
    // for(auto p:f(720)) cout << p << ' ';
    return 0;
}

Measured memory_bytes: 3708
#include "bits/stdc++.h"
#define ll long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define se second
#define fi first
using namespace std;
typedef pair<ll,ll> pll;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n; cin>>n;
    map<ll,ll> cnt;
    for(ll i=0;i<n;i++){
        ll num; cin>>num;
        if(cnt[num]) cnt[num]=0;
        else cnt[num]=1;
    }
    ll ans =0;
    for(auto m:cnt){
        if(m.se==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> dp(n+2);
    vector<int> p(n+2);
    for(int i = 1; i <= n; i++)
    {
        cin >> p[i];
    }
    p[0] = 0;
    p[n+1] = n+1;

    for(int i = 1; i <= n+1; i++)
    {
        dp[i] = 1e14;
        ll bigger = 0;
        for(int j = i-1; j >= 0; j--)
        {
            if(p[i] > p[j])
            {
                dp[i] = min(dp[i], dp[j] + bigger * a + (i-j-1-bigger) * b);
            }
            else
            {
                bigger++;
            }
        }
    }
    cout << dp[n+1] << endl;
}


Measured memory_bytes: 256
def linearSearch(A, n, key):
	i = 0
	A.append(key)
	while (A[i] != key):
		i += 1
	del A[n]

	return i != n


if __name__ == '__main__':
	
	n = int(input())
	L = list(map(int, input().split()))

	q = int(input())
	Key = list(map(int, input().split()))

	cnt = 0
	for i in range(q):
		if (linearSearch(L, n, Key[i])):
			cnt += 1

	print(cnt)

Measured memory_bytes: 8452
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

long reflection(double xp1, double yp1, double xp2, double yp2, double x, double y, double* px, double* py)
{
    if ( xp1 == xp2 && yp1 == yp2 ) {
        return 1;
    } else {
        double dDist = sqrt(pow((xp2 - xp1), 2) + pow((yp2 - yp1), 2));
        double dCos = (xp2 - xp1) / dDist;
        double dSin = (yp2 - yp1) / dDist;
        double dXrot = dCos * (x - xp1) + dSin * (y - yp1);
        double dYrot = -dSin * (x - xp1) + dCos * (y - yp1);
        dYrot = -dYrot;
        *px = dCos * dXrot - dSin * dYrot + xp1;
        *py = dSin * dXrot + dCos * dYrot + yp1;
        return 0;
    }
}


long CGL_1_B()
{
    long iRcF = 0;
	double xp1 = 0, yp1 = 0, xp2 = 0, yp2 = 0;
    long q = 0;
    double x = 0, y = 0;
    double* px = &x;
    double* py = &y;
	cin >> xp1 >> yp1 >> xp2 >> yp2;
	cin >> q;
    long i = 0;
    cout << fixed << setprecision(10);
    for ( i = 0; i < q; i++ ){
        cin >> x >> y;
        double reflected_x = 0, reflected_y = 0;
        iRcF = reflection(xp1, yp1, xp2, yp2, x, y, &reflected_x, &reflected_y);
        if ( iRcF ) {
            throw "ERROR: cannot calculate reflected points!";
        }
        cout << reflected_x << " " << reflected_y << endl;
    }
	return 0;
}

// #define AOJ_CGL_1_A
#define AOJ_CGL_1_B

int main() {
#ifdef AOJ_CGL_1_A
    CGL_1_A();
#endif
#ifdef AOJ_CGL_1_B
    CGL_1_B();
#endif
    return 0;
}


Measured memory_bytes: 3292
#include<stdio.h>

int main() {
	int A, B, C, D = 0;

	scanf("%d %d %d %d",&A,&B,&C,&D);

	if (A*B>C*D) {
		printf("%d",A*B);
	}
	else {
		printf("%d",C*D);
	}


	return 0;
}

Measured memory_bytes: 128
def main():
    N = int(input())
    d = [0] * N
    r= 100
    for i in range(1, r):
        ii = i * i
        for j in range(1, i + 1):
            iji = ii + j * j + i * j
            l =6
            if iji + 1 + i + j > N:
                break
            for k in range(1, j + 1):
                c = iji + k * k + (i + j) * k
                if c <= N:
                    if i == j or j == k:
                        l = 3
                        if i == k:
                            l = 1
                    d[c - 1] += l
                else:
                    break
    print(*d, sep="\n")


if __name__ == "__main__":
    main()


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


//AOJ How many islands?
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp

int dx[8] = {1,-1,0,0,1,1,-1,-1};
int dy[8] = {0,0,1,-1,1,-1,1,-1};
int h,w;
using Graph = vector<vector<int>>;
vector<vector<bool>> seen;
vector<vector<int>> maze;

void dfs(P p){
    seen[p.first][p.second] = true;

    for(int i = 0;i < 8;i++){
        int nx = p.second + dx[i];
        int ny = p.first + dy[i];
        if(nx < 0 || ny < 0 || h <= ny || w <= nx) continue;
        if(seen[ny][nx]) continue;
        if(maze[ny][nx] == 0) continue;

        dfs(make_pair(ny,nx));
    }
}

void recur(int w,int h) {
    int count = 0;
    maze.assign(h,vector<int>(w,0));
    seen.assign(h,vector<bool>(w,false));
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> maze[i][j];
        }
    }

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(maze[i][j]==0) continue;
            if(seen[i][j]) continue;
            dfs(make_pair(i,j));
            count++;
        }
    }
    
    cout << count << endl;
    w = 0;
    h = 0;
}

int main(){
    while(true){
        cin >> w >> h;
        if(w*w + h*h == 0) break;
        recur(w,h);
    }
    return 0;
}



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


// //AOJ How many islands?
// //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp

// int dx[8] = {1,-1,0,0,1,1,-1,-1};
// int dy[8] = {0,0,1,-1,1,-1,1,-1};
// int h,w;
// using Graph = vector<vector<int>>;
// vector<vector<bool>> seen;
// vector<vector<int>> maze;

// void dfs(P p){
//     seen[p.first][p.second] = true;

//     for(int i = 0;i < 8;i++){
//         int nx = p.second + dx[i];
//         int ny = p.first + dy[i];
//         if(nx < 0 || ny < 0 || h <= ny || w <= nx) continue;
//         if(seen[ny][nx]) continue;
//         if(maze[ny][nx] == 0) continue;

//         dfs(make_pair(ny,nx));
//     }
// }

// int main() {
//     cin >> w >> h;
//     int count = 0;
//     maze.assign(h,vector<int>(w,0));
//     seen.assign(h,vector<bool>(w,false));
//     for(int i = 0;i < h;i++){
//         for(int j = 0;j < w;j++){
//             cin >> maze[i][j];
//         }
//     }

//     for(int i = 0;i < h;i++){
//         for(int j = 0;j < w;j++){
//             if(maze[i][j]==0) continue;
//             if(seen[i][j]) continue;
//             dfs(make_pair(i,j));
//             count++;
//         }
//     }
    
//     cout << count << endl;
// }


Measured memory_bytes: 3100
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 x = 0;
		int y = 0;

		int[] balls = new int[n];
		for (int i = 0; i < n; i++) {
			balls[i] = 1;
		}

		boolean[] red = new boolean[n];
		red[0] = true;

		for (int i = 0; i < m; i++) {
			x = Integer.parseInt(sc.next()) - 1;
			y = Integer.parseInt(sc.next()) - 1;

			if (red[x]) {
				red[y] = true;
			}
			balls[x]--;
			balls[y]++;

			if (balls[x] == 0) {
				red[x] = false;
			}
		}
		int ans = 0;

		for (int i = 0; i < n; i++) {
			if (red[i])
				ans++;
		}

		System.out.println(ans);
	}

}


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

int main(){
  int64_t A,B,C;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    if (A % 2 == 0) cout << -1 << endl;
    else cout << 0 << endl;
  }
  else {
    int ans = 0;
    int64_t AB = A + B,BC = B + C,CA = C + A;
    while(AB % 2 == 0 && BC % 2 == 0 && CA % 2 == 0){
      ans++;
      AB /= 2;
      BC /= 2;
      CA /= 2;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
	int D;
	scanf("%d ", &D);
	if(D == 25)printf("Christmas\n");
	if(D == 24) printf("Christmas Eve\n");
	if(D == 23) printf("Christmas Eve Eve\n");
	if(D == 22) printf("Christmas Eve Eve Eve\n");

	
}

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

typedef struct element{
  long key;
  struct element *next;
  struct element *before;
}Element;

Element *insert(Element *begin, long key, Element **last) {
  Element *p;
  p = (Element*)malloc(sizeof(Element));
  p->key = key;
  p->next = begin;
  p->before = NULL;
  if(begin != NULL) {
    begin->before = p;
  }else{
    *last = p;
  }
  return p;
}

Element *delete(Element *begin, long key, Element **last) {
  Element *p = begin,*temp;
  while(p->key != key && p->next != NULL) p = p->next;
  if(p->next == NULL) {
    if(p->key != key) return begin;
    *last = p->before;
  }
  if(p->before != NULL) p->before->next = p->next;
  if(p->next != NULL) p->next->before = p->before;
  temp = begin;
  if(p == begin) temp = begin->next;
  free(p);

  return temp;
}

Element *deleteFirst(Element *begin, Element **last) {
  Element *p = begin->next;
  if(p != NULL) p->before = NULL;
  free(begin);
  if(p == NULL) *last = NULL;
  return p;
}

Element *deleteLast(Element *begin, Element **last) {
  Element *p = begin,*temp;
  p = (*last)->before;
  if(*last == begin) {
    temp = NULL;
  }else{
    temp = begin;
    (*last)->before->next = NULL;
  }
  free(*last);
  *last = p;

  return temp;
}

int main() {
  long i,n;
  scanf("%ld", &n);
  char command[12];
  long key;
  Element *begin;
  Element *last;
  for(i = 0; i < n; i++) {
    scanf(" %s", command);
    if(strcmp(command,"insert") == 0) {
      scanf("%ld", &key);
      begin = insert(begin, key, &last);
    }
    if(strcmp(command,"delete") == 0) {
      scanf("%ld", &key);
      begin = delete(begin, key, &last);
    }
    if(strcmp(command,"deleteFirst") == 0) begin = deleteFirst(begin, &last);
    if(strcmp(command,"deleteLast") == 0) begin = deleteLast(begin, &last);
  }

  Element *p = begin;
  while(p->next != NULL) {
    printf("%ld ", p->key);
    p = p->next;
  }
  printf("%ld\n", p->key);

  return 0;
}

Measured memory_bytes: 31788
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

S = gs
tomorrow_weather = {
  'Sunny' => 'Cloudy',
  'Cloudy' => 'Rainy',
  'Rainy' => 'Sunny'
}
puts tomorrow_weather[S]


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

using namespace std;


const int INF = 10000000;

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



void solve() {
    int H, W; cin >> H >> W;
    vector<string> maze(H);
    for (int i = 0; i < H; i++) cin >> maze[i];

    int ans = 0;

    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {

            if (maze[h][w] == '#') continue;

            vector<vector<int>> d(H, vector<int>(W, INF));
            queue<pair<int, int>> q;

            int ma = 0;

            q.push(make_pair(h, w));
            d[h][w] = 0;

            while(!q.empty()) {
                pair<int, int> p = q.front();
                q.pop();
                for (int i = 0; i < 4; i++) {
                    int nx = p.first + dx[i];
                    int ny = p.second + dy[i];

                    if (0 <= nx && nx < H && 0 <= ny && ny < W) {
                        if (maze[nx][ny] == '.' && d[nx][ny] == INF) {
                            d[nx][ny] = d[p.first][p.second] + 1;
                            ma = max(ma, d[nx][ny]);
                            q.push(make_pair(nx, ny));
                        }
                    }
                }
            }

            ans = max(ans, ma);
        }
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 3588
#include<iostream>

int countDivisors(int a, int b, int c);
int main()
{
	int a, b, c,count;

	std::cin >> a >> b >> c;

	count = countDivisors(a, b, c);

	std::cout << count << std::endl;

	return 0;
}

int countDivisors(int a, int b, int c)
{
	int count = 0;

	for (int i = a;i <= b;i++)
	{
		if (c % i == 0)
		{
			count++;
		}
	}
	return count;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int card[] = new int[n];
            for(int i=0; i<n; i++) card[i] = i+1;
            int r = sc.nextInt();
            if(n==0 && r==0) break;
            for(int i=0; i<r; i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                int strage[] = new int[c];
                for(int j=0; j<c; j++) strage[j] = card[n-p+1-c+j];
                for(int j=0; j<p-1; j++) card[n-p+1-c+j] = card[n-p+1+j];
                for(int j=0; j<c; j++) card[n-c+j] = strage[j]; 
            }
            System.out.println(card[n-1]);
        }
    }
}


Measured memory_bytes: 36948
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  int n, k;
	cin >> n >> k;
  bool sunuke[n];
  FOR(i, 0, n-1){
    sunuke[i] = false;
  }
  int num=n;
  FOR(i, 1, k){
    int dt;
    cin >> dt;
    FOR(j, 1, dt){
      int sunt;
      cin >> sunt;
      if (sunuke[sunt-1] == false) {
        sunuke[sunt-1] = true;
        num--;
      }
    }
  }
	cout << num << "\n";
}


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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a[10];
    for(int i=0;i<10;i++)   cin>>a[i];
    sort(a,a+10);
    cout<<a[9]<<endl;
    cout<<a[8]<<endl;
    cout<<a[7]<<endl;
    return 0;
}




Measured memory_bytes: 3212
import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    heapq.heappush(B2,(i,a))
dmax = 0
for i in range(N):
    dmax += B1[i][0]-B2[i][1]
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C and B2[0][0]<=i:
        _,b = heapq.heappop(B2)
        d += b
        a,j = heapq.heappop(C)
        heapq.heappush(B2,(j,a))
        d -= a
    dmax = max(dmax,d)
print(dmax)        

Measured memory_bytes: 133676