akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        if(n < k){
            long ans = n;
            if(ans > k-n)ans = k-n;
            System.out.println(ans);
            return;
        }
        long ans = n%k;
        if(ans==0){
            System.out.println(ans);
            return;
        }
        if(ans > k%ans)ans = k%ans;
        System.out.println(ans);


    }    
    
}







Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
int a[3030];
int mem[3030][3030];

int dp(int l, int r) {
    if(l==r) return a[l];
    if(~mem[l][r]) return mem[l][r];
    return mem[l][r] = max(a[l] - dp(l+1, r), a[r] - dp(l, r-1));
}

signed main() {

    cin >> n;
    for(int i = 0; i < n; i++) 
        cin >> a[i];
    
    memset(mem, -1, sizeof(mem));

    cout << dp(0, n-1) << endl;
  
    return 0;
}



Measured memory_bytes: 72192
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string p = Console.ReadLine();

            for (int i = 0; i < p.Length - 1; i++)
            {
                s += s[i];
            }

            if (s.Contains(p)) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 19780
n, m = map(int, input().split())
a = [(1, int(i)) for i in input().split()]
for _ in range(m):
    b, c = map(int, input().split())
    a.append((b, c))
a = sorted(a, key=lambda x: x[1])
ans = 0
t = 0
while t < n:
    b, c = a.pop()
    p = min(b, n-t)
    ans += p * c
    t += p
print(ans)


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

int A[100][100];//隣接行列
int n;
int D[100];  //訪問状態を保持　距離で

void bfs(int s) {
	queue<int> Q;
	Q.push(s);
	D[s] = 0; 
	while (! Q.empty()) {
		int cur = Q.front();
		Q.pop();
		for (int d=0; d<n; ++d) {
			if (A[cur][d] == 1 && D[d] == -1) {
				D[d] = D[cur]+1;
				Q.push(d);
			}
		}
	}
}

int main() {
	cin >> n;
	int p,q,r;
	for (int i=0; i<n; ++i) {
		cin >> p >> q;
		D[i] = -1; //到達不可能の時-1
		for (int i=0; i<q; ++i) {
			cin >> r;
			A[p-1][r-1] = 1;
		}
	}
	bfs(0);
	for (int i=0; i<n; ++i) {
		cout << i+1 << " " << D[i] << endl;
	}
    return 0;
}



Measured memory_bytes: 3128
import math
n, a = map(int, input().split())

vc = []

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

for i in range(n):
    v = list(map(int, input().split()))
    vc.append(v)

cc = 0
for k, i in enumerate(vc):
    if len(vc) < 2:
        break
    for v in vc[k+1:]:
        summ = 0
        for (x, y) in zip(i, v):
            summ += abs(x - y) ** 2


        if isqrt(summ) == math.sqrt(summ):
            cc += 1


print(cc)

Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define mod2 998244353
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
} 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
} 
ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin>>n>>m;
	n <= m ? cout<<"unsafe" : cout<<"safe";
}

Measured memory_bytes: 3652
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int cnt = 0;
    rep(i, h){
        rep(j, w){
            if(s[i][j] == '#') cnt++;
        }
    }

    queue<pair<pair<int,int>, int>> q;
    q.push({{0, 0}, 1});
    vector<vector<int>> visited(h, vector<int>(w, 0));
    visited[0][0] = true;
    while(!q.empty()){
        pair<int,int> now = q.front().first;
        int nowdist = q.front().second;
        q.pop();
        rep(i, 4){
            pair<int,int> next = {now.first + dx4[i], now.second + dy4[i]};
            int nextdist = nowdist + 1;
            if(next.first < 0 || next.first >= h || next.second < 0 || next.second >= w){
                continue;
            }
            if(visited[next.first][next.second]) continue;
            visited[next.first][next.second] = 1;
            if(s[next.first][next.second] == '#') continue;
            if(next == make_pair(h - 1, w - 1)){
                cout << h * w - nextdist - cnt << endl;
                return 0;
            }
            q.push({next, nextdist});
        }
    }
    cout << -1 << endl;

} 

Measured memory_bytes: 256
program main
    character (20) :: cx, ca, cb
    integer :: x, a, b
    read *, cx, ca, cb
    read (cx, *) x
    read (ca, *) a
    read (cb, *) b
    if (abs(x-a) < abs(x-b)) then
        print *, "A"
    else
        print *, "B"
    end if
end program main

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner sn = new Scanner(System.in)) {
			int a = sn.nextInt();
			int b = sn.nextInt();
			int c = sn.nextInt();
			int d = sn.nextInt();

			if ((Math.abs(b - a) <= d && Math.abs(c - b) <= d) || Math.abs(c - a) <= d) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 22228
#include<cstdio>

char S[101010];

int main(){
  scanf("%s",S);

  bool app[26];
  for (int i=0; i < 26; ++i){
    app[i] = false;
  }
  //C言語において文字っていうのは整数である．例) 'A' + 1 = 'B', 'A' + 2 = 'C'
  //出てきた文字それぞれについて，配列上でその文字に対応する位置をtrueに更新
  for(int i=0; S[i] != '\0'; ++i) {
    app[S[i] - 'a'] =true;
  }

  for(int i=0; i<26; ++i){
    if(!app[i]){
      printf("%c\n",(char)(i+'a'));
      return 0;
    }
  }
  puts("None");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2e5 + 20;
vector<int> edge[MAXN];
int siz[MAXN];
int sz[MAXN], dis[MAXN];
int res[MAXN], preMax[MAXN];
inline void dfs_2(int u, int p, int w) {
	siz[u] = 1;
	for (auto v : edge[u]) {
		if (v != p && v < w) {
			dfs_2(v, u, w);
			siz[u] += siz[v];
		}
	}
}
inline void dfs_1(int u, int p) {
	sz[u] = 1;
	preMax[u] = max(preMax[p], u);
	for (auto v : edge[u]) {
		if (v != p) {
			dfs_1(v, u);
			sz[u] += sz[v];
			dis[u] += dis[v]; 
		}
	}
	if (preMax[u] == u) {
		dis[u] = - sz[u];
		dfs_2(u, p, preMax[p]);
	}
	if (preMax[p] == p) dis[u] += sz[u];
}
inline void dfs_3(int u, int p) {
	if (p) {
		if (preMax[u] == u) {
			res[u] += siz[u];
		} else if (preMax[p] == p) {
			res[u] += dis[u] - siz[u];
		}
		res[u] += res[p];
	}
	for (auto v : edge[u]) {
		if (v != p) dfs_3(v, u);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	cin >> n;
	rep (i, 2, n) {
		int u, v;
		cin >> u >> v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	dfs_1(1, 0);
	dfs_3(1, 0);
	rep (i, 2, n) {
		cout << res[i] << ' ';
	}	cout << endl;
	return 0;
}

Measured memory_bytes: 38784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

class Prime
{
	ll i, iLimit;
public:
	bool isPrime(ll a);
};

bool Prime::isPrime(ll a)
{
	if (a == 1) return false;
	iLimit = (int)sqrt(a);
	for (i = 2; i <= iLimit; i++) if (a % i == 0) break;
	return (i == iLimit + 1 ? true : false);
}

vector<int> mp;
int n;
int ans = 0;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	Prime p;
	for (int i = 2; i <= n; ++i) {
		bool elf = p.isPrime(i);
		if (!elf) continue;
		int res = 0;
		for (int j = i; j <= n; ++j) {
			int tmp = j;
			while (tmp % i == 0) {
				tmp /= i;
				res++;
			}
		}
		mp.emplace_back(res);
	}
	int ans = 0;
	for (auto& c : mp) {
		if (c >= 74) ans++;
	}
	int m = mp.size();
	rep(i, m - 1) {
		for (int j = i + 1; j < m; ++j) {
			if (mp[i] >= 4 && mp[j] >= 14) ans++;
			if (mp[j] >= 4 && mp[i] >= 14) ans++;
			if (mp[i] >= 2 && mp[j] >= 24) ans++;
			if (mp[i] >= 24 && mp[j] >= 2) ans++;
		}
	}
	rep(i, m - 2) {
		for (int j = i + 1; j < m - 1; ++j) {
			for (int k = j + 1; k < m; ++k) {
				if (mp[i] >= 4 && mp[j] >= 4 && mp[k] >= 2) ans++;
				if (mp[i] >= 4 && mp[j] >= 2 && mp[k] >= 4) ans++;
				if (mp[i] >= 2 && mp[j] >= 4 && mp[k] >= 4) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	int a[9]={};
	for(int i=0;i<9;i++){
		scanf("%d",&a[i]);
	}
	int p=a[0]+a[4]+a[8];
	int q=a[0]+a[5]+a[7];
	int r=a[1]+a[3]+a[8];
	int s=a[1]+a[5]+a[6];
	int t=a[2]+a[4]+a[6];
	int u=a[2]+a[3]+a[7];
	if(p==q && q==r && r==s && s==t && t==u)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        rep(i,N)par[i]=i;
    }   

    int root(int x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }

    void unite(int x, int y){
        if(root(x)==root(y))return;
        par[root(x)]=root(y);
    }

    bool same(int x, int y){
        return root(x)==root(y);
    }
};

int main(){
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>> G(M);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        G[i].first=a-1;
        G[i].second=b-1;
    }
    int ans=0;
    rep(i,M){
        UnionFind tree(N);
        rep(j,M){
            if(j!=i)tree.unite(G[j].first,G[j].second);
        }
        if(!(tree.same(G[i].first,G[i].second)))ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
  for(int n;scanf("%d",&n),n;){
    set<int> all,w[10];
    for(int j=0;j<n;j++){
      vector<int> v(3);
      scanf("%d%d%d",v.data(),v.data()+1,v.data()+2);
      sort(begin(v),end(v));
      do{
	for(int i=0;i<60;i++){
	  int h=(v[0]+i)%60;
	  int m=(v[1]+i)%60;
	  int s=(v[2]+i)%60;
	  if(h%5==m/12){
	    int t=h/5*3600+m*60+s;
	    all.insert(t);
	    w[j].insert(t);
	  }
	}
      }while(next_permutation(begin(v),end(v)));
    }
    pair<int,int> c(0,1<<29);
    for(auto e:all){
      int l=-1;
      for(int i=0;i<n;i++){
	auto it=w[i].lower_bound(e);
	if(it==end(w[i]))goto next;
	l=max(l,*it);
      }
      if(c.second-c.first>l-e){
	c=make_pair(e,l);
      }
    next:
      ;
    }
    printf("%02d:%02d:%02d %02d:%02d:%02d\n",c.first/3600,c.first/60%60,c.first%60,c.second/3600,c.second/60%60,c.second%60);
  }
}

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


int main (void)
{
	char a[1200];
	int out;
	fgets(a, 1200, stdin);
		/*for ( int q = 1; q < 1200; q++)
		{
			scanf("%c" , &a[q]);
			if ( a[q] == '\n') break;
			out = q;
		}*/
		
		for ( int z = 0; a[z] != '\0'; z++)
		{
			if ( a[z] >= 'A' && a[z] <= 'Z')
			{
				printf("%c", a[z] + 32);
				//cout << a[z] - 32;
			}
			else if ( a[z] >= 'a' && a[z] <= 'z')
			{
				printf("%c", a[z] - 32);
				//cout << a[z] + 32;
			}
			else
			{
				printf("%c",a[z]);
			}
		}
	return 0;
}


Measured memory_bytes: 3096
n, res, a, m = int(input()), 0, [], {}
for i in range(n):
  a.append(int(input()))
  m[a[-1]] = i
a.sort()
for i in range(n):
  if i % 2 != m[a[i]] % 2:
    res += 1
print(res // 2)


Measured memory_bytes: 64216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String s = sc.next();
		if(a < 3200){
			System.out.println("red");
		}else{
			System.out.println(s);
		}
	}
}


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

MOD = 1_000_000_007
a, b, c, d = 8, 1, 1, 0
for i in range(N - 1):
    a, b, c, d = 8 * a, a + 9 * b, a + 9 * c, b + c + 10 * d
    a %= MOD
    b %= MOD
    c %= MOD
    d %= MOD
print(d)


Measured memory_bytes: 9064
#!/usr/bin/env python3


def yoko(A):
    f = False
    for i in range(3):
        if len(set(A[i]))==1:f = True
    return f

def tate(A):
    f = False
    for i in range(3):
        B = [A[0][i],A[1][i],A[2][i]]
        if len(set(B))==1: f = True
    return f


def naname(A):
    f = False
    B = [A[0][0],A[1][1],A[2][2]]
    if len(set(B))==1: f = True
    B = [A[0][2], A[1][1], A[2][0]]
    if len(set(B))==1: f = True

    return f


A = []

A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))

N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k]=-1

F1 = tate(A)
F2 = yoko(A)
F3 = naname(A)


if F1 or F2 or F3: print('Yes')
else: print('No')




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A;
  cin >> N >> A;
  
  int L = A; //リンゴ１の味
  int R = A + N -1;//最も大きい値の味＝R
  
  //最もおいしさの絶対値の小さいリンゴを見つけるために、RとLの値で場合分け
  
  int eat;
  
  if(R<=0) eat = R; /*最も大きい値の味Rが0以下、つまりすべてのリンゴの味が0以下⇒
  Rの絶対値が最小*/
  else if(L>=0) eat = L;
  else eat = 0;
  
  int answer = (R + L)*N /2 - eat;
  
  cout << answer << endl;
}


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

int main() {
    ll K;
    cin >> K;
    ll now = 0;
    for (int i = 1; i < K*2; i++) {
        now = (now*10+7)%K;
        if (now == 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
    
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

void fail() {
    cout << 0 << endl;
    exit(0);
}

int main() {
    int num;
    cin >> num;
    int mountains[100020];
    bool definite[100020];
    int temp[100020];
    fill(mountains, mountains+num, 0);
    fill(definite, definite+num, 0);
    fill(temp, temp+num, 0);
    cin >> mountains[0];
    definite[0] = true;
    for (int i=1; i<num; i++) {
        cin >> mountains[i];
        if (mountains[i] > mountains[i-1]) definite[i] = true;
    }
    for (int i=0; i<num; i++) {
        cin >> temp[i];
    }
    if (mountains[0] > temp[0]) fail();
    if (mountains[num-1] < temp[num-1]) fail();
    if (definite[num-1]) {
        if (mountains[num-1] != temp[num-1]) fail();
    }
    long long ans = 1;
    for (int i=num-2; i>=0; i--) {
        if (temp[i] > temp[i+1]) {
            if (definite[i] && mountains[i] != temp[i]) fail();
            if (mountains[i] < temp[i]) fail();
        } else if (!definite[i]) {
            long long ab = min(temp[i], mountains[i]);
            ans = (ans * ab) % (1000000007);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n,m,k=0,h=0;
    string u[256];
    string t[256];

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>u[i];
    }   

    cin>>m;

    for(int i=0;i<m;i++){
        cin>>t[i];
    }   
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(t[i]==u[j]){
                if(k==0){
                    cout<<"Opened by "<<t[i]<<endl;
                    k=1;
                    h++;
                }
                else if(k==1){
                    cout<<"Closed by "<<t[i]<<endl;
                    k=0;
                    h++;
                }       
            }       
        }
        if(h==0){
            cout<<"Unknown "<<t[i]<<endl;
        }
        h=0;
    }
}



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

using namespace std;

struct sushi_t {
  int d;
  int t;
};

static int n, k;
static std::array<sushi_t, 100000> sushis{};
static std::array<int, 100000> worstSushis{0};
static std::array<int, 100000> replaceables{};
static std::array<int, 100000> replacements{};

int64_t solve() {
  int64_t ret0 = 0;
  int64_t nn = 0;
  int replaceableIdx = 0;
  int i = 0;
  for (; i < k; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    ret0 += int64_t(s.d);
    if (!prev) {
      nn++;
    } else {
      replaceables[replaceableIdx++] = i;
    }
  }
  int64_t ret = ret0 + nn * nn;
  int replacementIdx = 0;
  for (; i < n; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    if (!prev) {
      replacements[replacementIdx++] = i;
    }
  }

  int const replacementSize = replacementIdx;
  replaceableIdx--;
  replacementIdx = 0;
  for (++nn; nn <= k && replaceableIdx >= 0 && replacementIdx < replacementSize;
       ++nn, --replaceableIdx, ++replacementIdx) {
    ret0 -= int64_t(sushis[replaceables[replaceableIdx]].d);
    ret0 += int64_t(sushis[replacements[replacementIdx]].d);
    if (ret0 + int64_t(k) * int64_t(k) <= ret) {
      break;
    }
    ret = std::max(ret0 + nn * nn, ret);
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    auto& s = sushis[i];
    std::cin >> s.t >> s.d;
    s.t--;
  }
  std::sort(sushis.begin(), sushis.begin() + n,
            [](const auto& lhs, const auto& rhs) { return lhs.d > rhs.d; });
  std::cout << solve() << std::endl;
  return 0;
}


Measured memory_bytes: 1664
#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>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define sz(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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;
}
int ch(string s){
    int a=sz(s);
    
    if(a%2){
        return 0;
    }else{
        string b,c;
        b="";c="";
        rep(i,a/2){
            b+=s[i];
        }
        FOR(i,a/2,a-1){
            c+=s[i];
        }
        if(b==c){
            return a;
        }else{
            return 0;
        }
    }
}
int main() {
    int t,y;cin>>t>>y;
    vector<vector<char>> ma(t+2,vector<char>(y+2,'.'));
    vector<vector<int>> na(t+2,vector<int>(y+2,-1));
    rep(i,t){
        rep(j,y){
            cin>>ma[i+1][j+1];
            
        }
    }
    
    rep(i,t){
        rep(j,y){
            if(ma[i+1][j+1]=='.'){
                int an=0;
                FOR(q,-1,1){
                    FOR(w,-1,1){
                        if(ma[i+1+q][j+1+w]=='#')an++;
                    }
                }
                na[i+1][j+1]=an;
            }
            
        }
    }
    
    rep(i,t){
        rep(j,y){
            if(na[i+1][j+1]==-1){
                cout<<"#";
            }else{
                cout<<na[i+1][j+1];
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
	"strconv"
)

func main() {
	var input string
	fmt.Scan(&input)
	s := strings.Split(input, "")
	N := make([]int, 4)
	for i := range s {
		n, _ := strconv.Atoi(s[i])
		N[i] = n
	}

	var calc func([]string, int, int) (bool, []string)
	calc = func(o []string, index, calcurated int) (bool, []string) {
		if index == 3 {
			if calcurated == 7 {
				return true, o
			} else {
				return false, o
			}
		} else {
			okPlus, p := calc(append(o, "+"), index+1, calcurated+N[index+1])
			okMinus, m := calc(append(o, "-"), index+1, calcurated-N[index+1])
			if okPlus {
				return okPlus, p
			} else {
				return okMinus, m
			}
		}
	}

	_, exp := calc(make([]string, 0), 0, N[0])
	for i := 0; i <= 2; i++ {
		fmt.Printf("%d%s", N[i], exp[i])
	}
	fmt.Printf("%d=7\n", N[3])
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define f(a,n) for(ll i=a;i<n;i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(v) v.begin(),v.end()
using namespace std;
const ll mod=(1e+9)+7;
const ll size = 2e5+9;
ll gcd(ll a,ll b) {if(b==0)return a;return gcd(b,a%b);}
ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;}

void solve()
{
    ll n;
    cin>>n;
    ll a[n+1];
    f(1,n+1)
    cin>>a[i];
    ll p[n+2],s[n+2];
    p[1] = a[1];
    for(ll i=2;i<=n;i++)
        p[i] = gcd(p[i-1],a[i]);
    s[n] = a[n];
    for(ll i=n-1;i>0;i--)
        s[i] = gcd(s[i+1],a[i]);

    p[0] = s[n+1] = 0;
    ll ans = LLONG_MIN;

    for(ll i=1;i<=n;i++)
        ans = max(ans,gcd(p[i-1],s[i+1]));

    cout<<ans<<endl;



}

int main()
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 Skyscraper. \n", double(end - beg) / CLOCKS_PER_SEC , 184);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

int a,b;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>a>>b;
    printf("%d\n",a*b);
    
    

    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

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

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

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

ll getScore(vector<bool> givingList) {
    ll ans = 0;
    for (bool b : givingList) {
        if (b) {
            ans++;
        }
    }
    return ans;
}

ll calcPath(vector<ll> holdingTrashes, ll X) {
    ll score = 0;
    ll cost = 1;
    score += holdingTrashes[0];
    holdingTrashes.push_back(0);
    FOR(i, 1, holdingTrashes.size()) {
        cost++;
        score += (holdingTrashes[i - 1] - holdingTrashes[i]) * cost * cost;
    }
    score += X * holdingTrashes.size();
    return score;
}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll maxNum = max(max(a, b), c);
    cout << a + b + c + maxNum * 9;
}

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

int main(){
  int a,b;
  int kekka = 0;
  int tmpA,tmpB;
  cin >> a >> b;
  
  for(int i = 1; i <= 1009; i++){
    tmpA = i * 0.08;
    tmpB = i * 0.1;
    
    if(tmpA == 0 || tmpB == 0) continue;
    
    if(tmpA == a && tmpB == b){
      kekka = i;
      break;
    }
  }
  
  if(kekka == 0) cout << -1;
  else cout << kekka;
}

Measured memory_bytes: 256
#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>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    ll cnt = 0;
    map<int, int> mp;
    rep(i,n) {
      int a;
      cin >> a;
      mp[a]++;
      cnt += a;
    }
    int q;
    cin >> q;
    rep(i,q) {
      int b, c;
      cin >> b >> c;
      cnt += (c-b)*mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
      printf("%lld\n", cnt);
    }
    return 0;
}

Measured memory_bytes: 8040
N, K = map(int, input().split())
S = str(input())

import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

s_list = list(nchars(S, 1))
s_list_num = [len(s) for s in s_list]
if '1' in s_list[0]:
    s_list_num.insert(0,0)
else:
    s_list_num.insert(0,0)
    s_list_num.insert(0,0)


s_list_sum = []
tmp_sum = 0
for x in s_list_num:
    tmp_sum += x
    s_list_sum.append(tmp_sum)

#print(s_list)
#print(s_list_num)
#print(s_list_sum)

ans = 0
for i in range(1, len(s_list_sum),2):

    l_sum = s_list_sum[i-1]
    r_sum = s_list_sum[min(len(s_list_sum)-1, i+K*2)]
    #print(l_sum, r_sum)
    ans = max(ans, r_sum - l_sum)

print(ans)

        
        

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

int main()
{
    int n;ll k;
    cin>>n>>k;
    ll a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int ans[n+1],cnt=1,vis[n+1]={0};
    for(int i=1;;i=a[i]){
        vis[i]++;
    if(vis[i]==3) break;
        ans[cnt++]=i;
}
//        for(int i=1;i<cnt;i++)
//            cout<<ans[i]<<" ";
//        puts("");
//        cout<<cnt<<endl;
//cout<<k%cnt;
   if(vis[ans[1]]==2) cout<<ans[(k+1)%(cnt-1)==0?cnt-1:(k+1)%(cnt-1)];
   else{
       int pos;
        for(int i=1;i<cnt;i++)
        if(vis[ans[i]]==3) {pos=i;break;}
        int t;
        for(int i=pos+1;i<cnt;i++)
        if(ans[i]==ans[pos]) {
            t=i-pos;break;
        }
        //cout<<pos<<" "<<t<<endl;
        if(k<=pos-1) cout<<ans[k+1];
        else cout<<ans[(k+1-pos+1)%t==0?t+pos-1:(k+1-pos+1)%t+pos-1];
   }
    return 0;
}


Measured memory_bytes: 6688
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    mx = 2
    mn = 2
    for a in reversed(A):
        mx = (mx // a + 1) * a - 1
        mn = (mn + a - 1) // a * a
        if mn > mx:
            print(-1)
            return
    print(mn, mx)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)


Measured memory_bytes: 83680
#include<bits/stdc++.h>
using namespace std;
#define  ll long long int
#define mx 1000007
ll dp[mx];
ll a[mx];

int main()
{
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];

    memset(dp,0,sizeof(dp));
    for(int i=1;i<=k;i++){
        for(int j=1;j<=n;j++){
            if(i-a[j]>=0){
                if(dp[i-a[j]]==0){
                    dp[i]=1;
                    break;
                }
            }
        }
    }
    if(dp[k]==1) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 11452
package main

import (
	"fmt"
)

func main() {
	var s string
	ok := false
	fmt.Scan(&s)
	for i := 0; i < len(s)-1; i++ {
		if s[i] == 'A' && s[i+1] == 'C' {
			ok = true
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int h,w,k;
	cin >> h >> w >> k;
	VVI a(h);
	VVI r(h);
	int first_h=LARGE_INT;
	REP(i,h){
		a[i].resize(w);
		r[i].resize(w);
		REP(j,w){
			char t;
			cin >> t;
			if(t == '.'){
				a[i][j] = 0;
			}
			else{
				a[i][j] = 1;
				first_h = min(first_h,i);
			}
		}
	}

	if(first_h == 0){
		int c = 1;
		bool f = true;
		REP(j,w){
			if(f){
				if(a[0][j] == 1){
					f = false;
				}
			}
			else{
				if(a[0][j] == 1){
					c++;
				}
			}
			r[0][j] = c;
		}
		c++;

		FOR(i,1,h){	
			bool nocake = true;
			REP(j,w){
				if(a[i][j] == 1){
					nocake = false;
				}
			}
			if(nocake){
				REP(j,w){
					r[i][j] = r[i-1][j];
				}
			}
			else{
				bool f = true;
				REP(j,w){
					if(f){
						if(a[i][j] == 1){
							f = false;
						}
					}
					else{
						if(a[i][j] == 1){
							c++;
						}
					}
					r[i][j] = c;
				}
				c++;
			}
		}
	}
	else{
		int c = 1;
		FOR(i,first_h,h){	
			bool nocake = true;
			REP(j,w){
				if(a[i][j] == 1){
					nocake = false;
				}
			}
			if(nocake){
				REP(j,w){
					r[i][j] = r[i-1][j];
				}
			}
			else{
				bool f = true;
				REP(j,w){
					if(f){
						if(a[i][j] == 1){
							f = false;
						}
					}
					else{
						if(a[i][j] == 1){
							c++;
						}
					}
					r[i][j] = c;
				}
				c++;
			}
		}
		for(int i=first_h-1;i>=0;i--){
			REP(j,w){
				r[i][j] = r[i+1][j];
			}
		}
	}

	REP(i,h){
		REP(j,w){
			if(j != 0){
				cout << " ";
			}
			cout << r[i][j];
		}
		cout << endl;
	}



	

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(a=="SAT")
	cout<<"1";
	if(a=="FRI")
	cout<<"2";
	if(a=="THU")
	cout<<"3";
	if(a=="WED")
	cout<<"4";
	if(a=="TUE")
	cout<<"5";
	if(a=="MON")
	cout<<"6";
	if(a=="SUN")
	cout<<"7";
	return 0;
}

Measured memory_bytes: 256
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_short(const void *a, const void *b){return *(short*)a - *(short*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
int n, i;
char c;
int r[26];
long long int ans;
int main(){
 n = nextInt();
 for(i=0; i<n; i++){
  r[getchar()-'a']++;
 }
 ans = 1;
 for(i=0; i<26; i++){
  ans = (ans*(r[i]+1))%1000000007;
 }
 printLong(ans-1);
 println();
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y;
std::cout << (x-1)*(y-1) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
#define MAX9 1000000000
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int a, b, k; CI a >> b >> k;
	set<int> ans;
	for (int i = a; i <= min(b, (a + k) - 1); i++) {
		ans.insert(i);
	}
	for (int i = max(a + k, b - k + 1); i <= b; i++) {
		ans.insert(i);
	}
	for (int x : ans) {
		CO x EN;
	}

	return 0;
}

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

bool a[100005] ;
int W[100005] ;
int main(){
	int N , M  , p ;
	cin >> N >> M ;
	string  s ;
	int c = 0 , w = 0 ;
	for( int i = 0 ; i < M  ; i++ ){
		cin >> p >> s ;
		if(s.compare("AC") == 0 ){
			a[p] = 1 ;
		}
		else{
			if(!a[p]) W[p]++ ;
		}
	}
	for( int i = 1 ; i <= N ; i++ ){
		if(a[i]) {
			w += W[i] ;
			c++ ;
		}
	}
	cout << c << " " << w << endl ;

	return 0 ;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  string W;
  cin >> W;
  for (int i = 0; i < W.size(); i++){
    W[i] = tolower(W[i]);
  }
  int ans = 0;
  while (1){
    string T;
    cin >> T;
    if (T == "END_OF_TEXT"){
      break;
    }
    for (int i = 0; i < T.size(); i++){
      T[i] = tolower(T[i]);
    }
    if (T == W){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

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

	ll ans = 0;
	for(ll i = 2 ; i*i <= n ; i ++){
		if (n % i == 0){
			ll counter = 0;

			while (n % i == 0){
				n /= i;
				counter++;
			}

			ll temp1 = 1;

			while(counter >= temp1){
				ans++;
				counter -= temp1;
				temp1++;
			}
		}
	}
	if(n > 1){
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
N,K=map(int,input().split())
XYC=[input().split() for i in range(N)]
d=[[[0]*K for i in range(K)] for i in range(2)]
for x,y,c in XYC:
    x,y=int(x),int(y)
    z=(x//K%2)^(y//K%2)^(c=='B')
    d[z][x%K][y%K]+=1
a=[[[0]*(K+1) for i in range(K+1)] for i in range(2)]
for k in range(2):
    for i in range(K):
        for j in range(K):
            a[k][i+1][j+1]=a[k][i+1][j]+a[k][i][j+1]-a[k][i][j]+d[k][i][j]
r=0
for k in range(2):
    for i in range(K):
        for j in range(K):
            r=max(r,a[k][-1][-1]-a[k][i][-1]-a[k][-1][j]+a[k][i][j]*2\
                +a[k^1][i][-1]+a[k^1][-1][j]-a[k^1][i][j]*2)
print(r)

Measured memory_bytes: 109656
m = [list(map(int,input().split())) for _ in range(3)]
n = int(input())

for i in range(n):
    x = int(input())
    for h in range(3):
        for w in range(3):

            if m[h][w] == x: m[h][w] = 0


for i in range(3):
    if sum(m[i]) == 0 :print('Yes'); exit()

for i in range(3):
    if m[0][i] + m[1][i] + m[2][i] == 0: print('Yes'); exit()

if m[0][0] + m[1][1] + m[2][2] == 0: print('Yes'); exit()
if m[0][2] + m[1][1] + m[2][0] == 0: print('Yes'); exit()

print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    string s; cin >> s;
    if(s[0]==s[2]) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
//package aoj0013;

import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Deque<Integer> stack = new ArrayDeque<Integer>();
		while (scan.hasNext()) {
			int tmp = scan.nextInt();
			if (tmp == 0) {
				System.out.println(stack.pop());
			} else {
				stack.push(tmp);
			}
		}
	}
}

Measured memory_bytes: 26184
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int64_t N, D;
    cin >> N >> D;
    D = D * D;
    int ret = 0;
    rep(i, N) {
        int64_t x, y;
        cin >> x >> y;
        if (x*x + y*y <= D) {
            ret++;
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3612
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m] = nexts(2);
  var h = nexts(n);
  var q = xArray(1,n);
  for(var i = 0; i < m; i++){
    var [a,b] = nexts(2);
    a--,b--;
    if(h[a] >= h[b])q[b] = 0;
    if(h[b] >= h[a])q[a] = 0;
  }
  return q.reduce((a,b)=>a+b);
}

Measured memory_bytes: 76076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).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;}

const int NM = 110;
const int WM = 1e5+10;
ll w[NM], v[NM];
ll dp[NM][WM]; // 価値の最大値

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,W;cin>>N>>W;
    rep(i,N){
        cin>>w[i];
        cin>>v[i];
    }
    rep(i,N){ // i番目の品物まで決定
        for(int sum_w=0; sum_w<=W; sum_w++){ // 各weightに対して計算
            if(sum_w - w[i] >= 0){
                chmax(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i]);
            }
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout<<dp[N][W]<<endl;

}
// dp_d

Measured memory_bytes: 79360
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;

struct edge {
    int to, cap, cost, rev;
};
int V;
vector<edge> G[802];
int dist[802];
int prevv[802], preve[802];

void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back((edge){to, cap, cost, int(G[to].size())});
    G[to].push_back((edge){from, 0, -cost, int(G[from].size()) - 1});
}

const int INF = 10000000;
int min_cost_flow(int s, int t, int f) {
    int res = 0;
    while (f > 0) {
        fill(dist, dist + V, INF);
        dist[s] = 0;
        bool update = true;
        while (update) {
            update = false;
            for (int v = 0; v < V; ++v) {
                if (dist[v] == INF) continue;
                for (int i = 0; i < G[v].size(); ++i) {
                    edge &e = G[v][i];
                    if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }

        if (dist[t] == INF)
            return -1;

        int d = f;
        for (int v = t; v != s; v = prevv[v])
            d = min(d, G[prevv[v]][preve[v]].cap);
        f -= d;
        res += d * dist[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int edist(string s1, string s2)
{
    int d[21][21];
    for (int i = 0; i < 21; ++i)
        d[i][0] = d[0][i] = i;

    for (int i = 1; i <= s1.size(); ++i) {
        for (int j = 1; j <= s2.size(); ++j) {
            int cost = s1[i - 1] != s2[j - 1];
            d[i][j] = min(min(
                    d[i - 1][j] + 1,
                    d[i][j - 1] + 1),
                    d[i - 1][j - 1] + cost);
        }
    }
    return d[s1.size()][s2.size()];
}

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

    map<string, int> t;
    for (int i = 0; i < n; ++i) {
        char buf[1002];
        gets(buf);

        istringstream s(buf);
        string w;
        while (getline(s, w, ' '))
            ++t[w];
    }
    vector<string> ts;
    vector<int> ti;
    for (auto it = t.begin(); it != t.end(); ++it) {
        ts.push_back(it->first);
        ti.push_back(it->second);
    }

    vector<string> w(m);
    for (int i = 0; i < m; ++i) {
        char buf[22];
        scanf("%s", buf);
        w[i] = buf;
    }

    for (int i = 0; i < ts.size(); ++i)
        add_edge(0, i + 2, 1, 0);
    for (int j = 0; j < w.size(); ++j)
        add_edge(j + 2 + ts.size(), 1, 1, 0);

    for (int i = 0; i < ts.size(); ++i) {
        for (int j = 0; j < w.size(); ++j) {
            add_edge(i + 2, j + 2 + ts.size(), 1, edist(ts[i], w[j]) * ti[i]);
        }
    }

    V = 2 + ts.size() + w.size();
    int ans = min_cost_flow(0, 1, ts.size());
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 7892
#include <stdio.h>
#include <math.h>

int main(int argc, char **argv)
{
	float x, h;
	
	while(1){
		scanf("%f", &x);
		scanf("%f", &h);
		if(x == 0){
			break;
		}
		printf("%.6f\n", (x*x+x*sqrt(x*x+4*h*h)));
	}
	
	return 0;
}

Measured memory_bytes: 0
#define M 50000
p[M+1];main(i,j,n){p[1]=1;for(;i<=M;i++)if(!p[i])for(j=i*2;j<=M;j+=i)p[j]=1;for(;scanf("%d",&n),n;printf("%d\n",j))for(i=2,j=0;i<=n/2;i++)if(!p[i]&&!p[n-i])j++;return 0;}

Measured memory_bytes: 600
import java.util.Scanner;
public class Main {

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

        int month = sc.nextInt(); // 材料の種類数
        int date = sc.nextInt(); // 材料の総量


        System.out.println(calc(month,date));
    }

    public static int calc(int month, int date) {

        if (month > date) {
            return month - 1;
        } else {
            return month;
        }

    }
}


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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << abs(a-b) + abs(b-c) + abs(c-a) - max(abs(a-b), max(abs(b-c), abs(c-a))) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int a,b,c,x;

scanf("%d", &a);

scanf("%d", &b);

scanf("%d", &c);

if(a > b)

{

x = a;

a = b;

b = x;

}

if(b > c)

{

x = b;

b = c;

c = x;

}

if(a > b)

{

x = a;

a = b;

b = x;

}

printf("%d %d %d\n",a, b, c);

return 0;

}

Measured memory_bytes: 596