akhauriyash/Code-Regression huggingface dataset:
import java.util.*;


public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine();
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
//        String s = sc.nextLine();
//        String t = sc.next();
//        String[] arr =  s.split("　");
//        sc.close();
//        System.out.println("input: "+ s);
//        System.out.println("k:" + k);
//        System.out.println("a:" + a);
//        System.out.println("b:" + b);
        String ans = "NG";
        for(int x = a; x<=b; x++){
            if(x%k == 0){
                ans = "OK";
            }
        }
        System.out.println(ans);
//        \
//        System.out.println("arr[1]:" + arr[1]);
//
//        if(s.equals("ABC")){
//            System.out.println("ARC");
//        }else{
//            System.out.println("ABC");
//        }
//        String[] arr1 =  s.split("");
//        String[] arr2 =  t.split("");
////        List<String> list1 = Arrays.asList(s.split(""));
//        List list1 = new LinkedList(Arrays.asList(s.split("")));
////        List<String> list2 = Arrays.asList(t.split(""));
//        List list2 = new LinkedList(Arrays.asList(t.split("")));
////        int num = Integer.parseInt(arr[arr.length - 1]);
//        list2.remove(arr2.length - 1);
////        System.out.println(list1);
////        System.out.println(list2);
//         if(list1.toString().contentEquals(list2.toString())){
//             System.out.println("Yes");
//         }else{
//             System.out.println("No");
//         }
//        switch(num){
//            case 3:
//                System.out.println("bon");
//                break;
//            case 0:
//            case 1:
//            case 6:
//            case 8:
//                System.out.println("pon");
//                break;
//            default:
//                System.out.println("hon");
//                break;
//        }
//        String[] array = str.split(" ");
//        int sum = 0;
//        for(int i=0; i<array.length; i++) {
//            int num = Integer.parseInt(array[i]);
//            sum += num;
//        }
//        System.out.println(15-sum);
    }
}

Measured memory_bytes: 35724
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for(int i = 0; i < n; i++){
            array[i] = sc.nextInt();
        }
        System.out.print(array[n-1]);
       for(int i = n-2; i >= 0; i--){
           System.out.print(" " + array[i]);
       }
       System.out.println("");
    }
}


Measured memory_bytes: 26320
N = int(input())
Lifes = list(map(int, input().split()))

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

# for i in range(N):
#   for j in range(i, N):
#     life = Lifes[i]%Lifes[j]
#     if life > 0:
#       ans = min(ans, life)
# print(ans)

update = True
while update:
    min_num = ans
    for i in range(N):
        life_mod = Lifes[i]%ans
        if life_mod > 0:
            Lifes[i] = life_mod
            if min_num > life_mod:
                min_num = life_mod
    if ans == min_num:
        update=False
    else:
        ans = min_num
print(ans)

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

int main(){
long long n;
cin>>n;
long long a[n];
for(long long i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
long long count=0;
long long ans=0;
count++;
long long temp=n-1;
ans+=a[temp];
temp--;
count++;
while(1){
    if(count==n){
        break;
    }
    ans+=a[temp];
    count++;

  if(count==n){
      break;
  }
ans+=a[temp];
count++;
temp--;
}
cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll sum=0;
  ll num=0;
  ll a[n];
  rep(i,0,n){
    cin>>a[i];
    sum+=a[i];
    if(i%2==1)num+=a[i];
  }

  ll x=sum-2*num;
  ll ans[n];ans[0]=x;
  rep(i,1,n){
    ans[i]=2*a[i-1]-ans[i-1];
  }

  rep(i,0,n){
    cout<<ans[i]<<" ";
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
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 eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=INF,n=0,w=0;
  string s,t;
  std::cin >> s>>t;
  rep(i,s.size()){
    Rep(j,s.size()){
      if(t[j]!=s[(i+j)%s.size()]){
        x++;
        break;
      }
    }
    if(x==0){
      std::cout << "Yes" << '\n';
      return 0;
    }else{
      x=0;
    }
  }
  std::cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int n,m,cnt; 
int ans;
/*int h[200010],dis[200010],v[200010];
int dp[1005][1005];
struct edge
{
	int v,w,next;
}e[200010*2];
il void add(int u,int v)
{
	e[++cnt].v=v;
//	e[cnt].w=w;
	e[cnt].next=h[u];
	h[u]=cnt;
}*/ 
int main()
{
	double r;
	cin>>r;
	printf("%lf",3.14159265358979323*2.0*r);
	return 0;
}

Measured memory_bytes: 3784
#include<stdio.h>
int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);
  if(a<b)
    printf("a < b\n");
  if(a>b)
    printf("a > b\n");
  if(a==b)
    printf("a == b\n");
 return 0;
}


Measured memory_bytes: 2040
#include <iostream>
using namespace std;
int main() {
	int w, h, c, n = 0;
	cin >> w >> h >> c;
	int rw = w, rh = h;
	if (w < h) swap(w, h);
 	while (1) {
		w = w%h;
		swap(w, h);
		if (h == 0) {
			n = w;
			break;
		}
	}
	cout << rw*rh / n / n*c << endl;
	return 0;
}

Measured memory_bytes: 3116
let a, b, x = Scanf.scanf " %f %f %f" @@ fun a b c -> a, b, c
let f r = 180. *. r /. acos (-1.) |> Printf.printf "%.10f\n"
let _ = f @@ if x <= b *. a *. a /. 2. then let d = 2. *. x /. (a *. b) in let k = sqrt (b *. b +. d *. d) in acos @@ 2. *. x /. (a *. k) /. b
  else atan2 (2. *. (a *. b -. x /. a)) (a *. a)

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int&x : h){
        cin >> x;
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= i+k && j < n; j++){
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n-1] << endl;;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  int mi = mod;
  cin>>n;
  int ret = 0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    mi = min(mi, x);
    if(mi>=x)ret++;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string N;
cin >> N;
  if(N.at(0) == '7' || N.at(1) == '7' || N.at(2) == '7')
cout << "Yes" << endl;
 
else 
cout << "No" << endl;
 
 
 
}

Measured memory_bytes: 3624
N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)

posi = []
nega = []
zeros = 0
A.each do |ai|
  if ai < 0
    nega << ai
  elsif ai > 0
    posi << ai
  else
    zeros += 1
  end
end

posi.sort!
nega.sort_by!{|t| -t }

posi_size = posi.size
nega_size = nega.size

nega_pairs = posi_size * nega_size
zero_pairs = zeros * (zeros - 1) / 2 + zeros * (N - zeros)

ng = -(10**18 + 1)
ok = 10**18 + 1

ans = (ng..ok).bsearch do |mid|
  
  cnt = 0
  
  cnt += zero_pairs if mid >= 0

  if mid > 0
    cnt += nega_pairs
    [posi, nega].each do |a|
      l = 0
      r = a.size - 1
      while l < r
        r -= 1 while l < r && a[l] * a[r] > mid
        cnt += r - l
        l += 1
      end
    end
  else
    r = nega_size - 1
    posi.size.times do |l|
      r -= 1 while(r >= 0 && posi[l] * nega[r] <= mid)
      cnt += nega_size - r - 1
    end
  end

  cnt >= K
end

puts ans

Measured memory_bytes: 24452
/*input
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
*/
#include "bits/stdc++.h"
using namespace std;
const long long md = 1e9 + 7;
long long a[1000005], n;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	map<long long,int> mp;

	long long ans = 0;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		ans += mp[i - a[i]];
		++mp[a[i]+i];
	}

	cout << ans << '\n';
}

Measured memory_bytes: 27940
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int H, A;
    cin >> H >> A;
    // H <= k * A <==> H/A <= k
    cout << ceil(double(H)/A) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int x,y,d,z;
  scanf("%d %d",&x,&y);
  while(1){
    if(x >= y){
      if(y == 0){
	printf("%d\n",x);
	return 0;
      }
    d=x%y;
    x=y;
    y=d;
    }
    if(y == 0){
      printf("%d\n",x);
      break;
    }
    else {
      if(y == 0){
	printf("%d\n",y);
	return 0;
      }
      d=y%x;
      y=x;
      x=d;
      if(x == 0){
      printf("%d\n",y);
      break;
      }
    }
  }
  return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main() {

    ll N; cin >> N;
    vector<ll > A(N, 0);

    for(ll i = 0; i < N; i++){
        cin >> A[i];
    }

    //ll left = 0;
    ll right = 0;
    ll SUM = 0;
    ll XOR = 0;
    ll ans = 0;

    for(ll left = 0; left < N; left++){
        //rightがデータ数の最大を超えず，これまでのSUMとXORが同じ時
        while(right < N && (SUM + A[right]) == (XOR ^ A[right])){
            SUM += A[right];
            XOR ^= A[right];
            right++;
        }

        //leftからrightまでの条件を満たす個数
        ans += right - left;
        
        if(right == left){
            right++;
        }else{
            SUM -= A[left];
            //同じものをXORするともとに戻る
            XOR ^= A[left];
        }
    }

    cout << ans << endl;
}

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

int main(){
  int n,m=0,ma=0;
  std::cin >> n;
  for (int i = 1; i < n+1; i++) {
    /* code */
    int d;
    d=i;
    int j;
    for ( j = 0; d%2==0 ; j++) {
      /* code */
      d/=2;
    }
    
    if(m<j){m=j;ma=i;}
  }
  if(n==1)std::cout << 1 << std::endl;
  else std::cout << ma<< std::endl;
}

Measured memory_bytes: 256
//agc043_a.cpp
//Thu May 28 21:14:16 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int h,w;
	cin >> h >> w;

	int col[h][w];
	int visited[h][w];
	for (int i=0;i<h;i++){
		string s;
		cin >> s;
		for (int j=0;j<w;j++){
			if (s[j]=='.'){
				col[i][j]=0;
			}else {
				col[i][j]=1;
			}
			visited[i][j] = 0;
		}
	}

	queue<P> q;
	int flip = 0;
	q.push(P(0,0));
	int qcol[2];
	if (col[0][0]==0){
		qcol[0] = 1;
		qcol[1] = 0;
	}else {
		qcol[0] = 0;
		qcol[1] = 1;
	}

	while(!q.empty()){
		if (qcol[flip%2]==0){
			flip++;
		}
		P x = q.front();q.pop();
		if (visited[x.first][x.second]){
			qcol[col[x.first][x.second]]--;
		}else if (col[x.first][x.second]==flip%2){
			visited[x.first][x.second] = 1;
			qcol[col[x.first][x.second]]--;
			if (x.first==h-1 && x.second==w-1){
				break;
			}
			if (x.second!=w-1){
				q.push(P(x.first,x.second+1));
				qcol[col[x.first][x.second+1]]++;
			}
			if (x.first!=h-1){
				q.push(P(x.first+1,x.second));
				qcol[col[x.first+1][x.second]]++;
			}
		}else {
			q.push(x);
		}
		// cout << flip << " " << qcol[0] << " " << qcol[1] <<endl;
	}

	cout << (flip+1)/2 << endl;
//	printf("%.4f\n",ans);
}

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

using namespace std;

constexpr int N_MAX = 300000;

vector<int> is_prime(N_MAX+1, 0), primes;

void solve(int n) {
    cout << n << ":";
    for(int p: primes) {
        if(n % p) continue;
        int pp = n/p;
        if(pp % 7 == 1 || pp % 7 == 6) {
            cout << " " << p;
            while(n % p) {
                n /= p;
            }
        }
    }
    cout << endl;
}

int main() {
    int n;
    int i = 1;
    is_prime[6] = 1;
    while(7*i < N_MAX) {
        is_prime[7*i+1] = 1;
        is_prime[7*i+6] = 1;
        ++i;
    }
    for(int i=6;i<600;++i) {
        if(!is_prime[i]) continue;
        int m = i+i;
        while(m <= N_MAX) {
            is_prime[m] = 0;
            m += i;
        }
    }
    for(int i=6;i<=N_MAX;++i) if(is_prime[i]) primes.push_back(i);
    while(cin >> n && n != 1) {
        solve(n);
    }
}


Measured memory_bytes: 4312
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str1,str2;
    cin>>n;
    while(n>=2){
        n/=2;
        sum++;
    }
    a=1;
    rep(i,sum){
        a=a*2;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;



int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
		ll n,i,j,l,k;
		cin>>n;
		l=n%10;
		if(l==0 || l==1 || l==6 || l==8)
			cout<<"pon"<<"\n";
		else if(l==3)
			cout<<"bon"<<"\n";
		else 
			cout<<"hon\n";
		return 0;
}
	

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int H, W;
  cin >> H >> W;
  char mas[202][202];
  queue<Pi> que;
  rep(i, H) rep(j, W) {
    cin >> mas[i][j];
    if(mas[i][j] == '%') que.push(Pi(i, j));
  }
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  int d[202][202]; memset(d, -1, sizeof(d));
  d[que.front().F][que.front().S] = 0;
  int pri = -1; vector<int> sol;
  while(!que.empty()) {
    Pi p = que.front(); que.pop();
    if(mas[p.F][p.S] == '@') {
      pri = d[p.F][p.S];
    } else if(mas[p.F][p.S] == '$') {
      sol.push_back(d[p.F][p.S]);
    }
    rep(i, 4) {
      if(0 <= p.F+dy[i] && p.F+dy[i] < H &&
	 0 <= p.S+dx[i] && p.S+dx[i] < W &&
	 mas[p.F+dy[i]][p.S+dx[i]] != '#' &&
	 d[p.F+dy[i]][p.S+dx[i]] == -1) {
	que.push(Pi(p.F+dy[i], p.S+dx[i]));
	d[p.F+dy[i]][p.S+dx[i]] = d[p.F][p.S] + 1;
      }
    }
  }
  cout << (pri != -1 && (sol.empty() || *min_element(all(sol)) > pri) ? "Yes" : "No") << endl;
  return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  int a;
  for(int i=0; i<2*M; i++){
    cin >> a;
    for(int j=1; j<N+1; j++){
      if(a == j){
        vec.at(j-1) += 1;
        break;
      }
    }
  }
  for(int i=0; i<N; i++){
    cout << vec.at(i) << endl;
  }
  
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K; cin >> N >> K;

    vector<vector<pair<int,int>>> G(2*K,vector<pair<int,int>>(2*K,{0,0}));
    REP(i,N){
        int x,y;
        char c;
        cin >> x >> y >> c;
        if(c=='B') G[x%(2*K)][y%(2*K)].first ++;//first : B
        else if(c=='W') G[x%(2*K)][y%(2*K)].second ++;// second : W
    }

    vector<vector<pair<int,int>>> sum(2*K+1,vector<pair<int,int>>(2*K+1,{0,0}));

    REP(i,2*K){
        FOR(j,1,2*K+1){
            sum[i+1][j].first += sum[i][j].first + G[i][j-1].first;
            sum[i+1][j].second += sum[i][j].second + G[i][j-1].second;
        }
    }

    FOR(i,1,2*K+1){
        REP(j,2*K){
            sum[i][j+1].first += sum[i][j].first;
            sum[i][j+1].second += sum[i][j].second;
        }
    }

    // REPR(j,2*K){
    //     REP(i,2*K+1){       
    //         cout << sum[i][j].second << " ";
    //     }cout << endl;
    // }

    vector<int> XY{-K,0,K,2*K};

    int ans = 0;

    REP(i,K){
        REP(j,K){
            int ans1=0, ans2=0;
            REP(x,3){
                REP(y,3){
                    if((x+y)%2==0){
                        ans1 += sum[min(2*K, XY[x+1]+i)][min(2*K, XY[y+1]+j)].first
                        + sum[max(0,XY[x]+i)][max(0,XY[y]+j)].first
                        - sum[max(0,XY[x]+i)][min(2*K, XY[y+1]+j)].first
                        - sum[min(2*K, XY[x+1]+i)][max(0,XY[y]+j)].first;

                        ans2 += sum[min(2*K, XY[x+1]+i)][min(2*K, XY[y+1]+j)].second
                        + sum[max(0,XY[x]+i)][max(0,XY[y]+j)].second
                        - sum[max(0,XY[x]+i)][min(2*K, XY[y+1]+j)].second
                        - sum[min(2*K, XY[x+1]+i)][max(0,XY[y]+j)].second;
                    }else{
                        ans2 += sum[min(2*K, XY[x+1]+i)][min(2*K, XY[y+1]+j)].first
                        + sum[max(0,XY[x]+i)][max(0,XY[y]+j)].first
                        - sum[max(0,XY[x]+i)][min(2*K, XY[y+1]+j)].first
                        - sum[min(2*K, XY[x+1]+i)][max(0,XY[y]+j)].first;

                        ans1 += sum[min(2*K, XY[x+1]+i)][min(2*K, XY[y+1]+j)].second
                        + sum[max(0,XY[x]+i)][max(0,XY[y]+j)].second
                        - sum[max(0,XY[x]+i)][min(2*K, XY[y+1]+j)].second
                        - sum[min(2*K, XY[x+1]+i)][max(0,XY[y]+j)].second;
                    }
                }
            }
            ans = max(ans, ans1);
            ans = max(ans, ans2);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 66068
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        System.out.println(a[k-1]);
    }
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();

		int ans = t.length;

		for(int i = 0; i <= s.length - t.length; i++) {
			int diff = 0;
			for(int x = 0; x < t.length; x++) {
				if(t[x] != s[i+x]) {
					diff++;
				}
			}
			ans = ans <= diff ? ans : diff;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 35496
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var sum = 0.0
    for(i in 1..N){
        val list = readLine()!!.split(" ")
        val x = list[0].toDouble()
        val u = list[1]
        sum += if(u.equals("JPY")){
            x
        } else {
            x.toYen()
        }
    }
    println(sum)
}
fun Double.toYen(): Double{
    return this * 380000
}


Measured memory_bytes: 37680
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
s = b
for i in range(n-1):
    for j in range(i,n-1):
        s.append(b[j+1]-b[i])
s.sort(reverse=True)
l = len(bin(s[0]))-2
d = 1<<l-1
t = 0
while d>0:
    s1 = []
    if s[k-1] >= d:
        t += d
        for i in s:
            if i >= d:
                s1.append(i)
            else:
                s=s1
                break
    for i in range(len(s)):
        if s[i] >= d:
            s[i] -= d
        else:
            s.sort(reverse=True)
            break
    d //= 2
print(t)

Measured memory_bytes: 27544
# D問題
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# nCr
def nCr(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def main():
  n,k=LI()

  # 隙間
  a=n-k+1

  for i in range(1,k+1):
    if a<i or k-1<i-1:
      print(0)
    else:
      print(nCr(a,i)*nCr(k-1,i-1)%mod)

main()


Measured memory_bytes: 5840
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
long long sum,aa,bb;
long long mi=0x7fffffff;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld%lld",&aa,&bb);
		sum+=(long long)aa;
		if(aa>bb)mi=min(mi,bb);
	}
	if(mi==0x7fffffff)
		printf("0\n");
	else
	printf("%lld\n",sum-mi);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i;
  int n, m;
  int sum;

  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    sum = 0;
    for (i = 0; i < n/4; i++) {
      scanf("%d", &m);
      sum += m;
    }
    printf("%d\n", sum);
  }

  return 0;
}



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



int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    map<string,int> mp;
    for(int i = 0;i < n;i++){
    	string s;
    	cin>>s;
    	mp[s]++;
	}
	cout<<mp.size()<<endl;
    return 0;
}

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

ans_list=[]
sgn=1
for i in range(100):
  if N%2==1:
    ans_list.append("1")
    N-=sgn
  else:
    ans_list.append("0")
    
  N//=2
  sgn*=-1
  if N==0:
    break
  
print("".join(reversed(ans_list)))

Measured memory_bytes: 3060
# coding: utf-8
# Your code here!
import collections

N,M = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
tmp=[]
for i in lst:
    l = i[1:]
    for p in l:
        tmp.append(p)

ct = collections.Counter(tmp)
values, counts = zip(*ct.most_common())
ans = 0
for i in counts:
    if i == N:
        ans+=1
print(ans)

Measured memory_bytes: 3316
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int union_tree[200000];
int union_find(int a) {
    if (union_tree[a] == a) return a;
    return union_tree[a] = union_find(union_tree[a]);
}
int union_merge(int a, int b) {
    a = union_find(a);
    b = union_find(b);
    if (a == b) return 0;
    union_tree[a] = b;
    return 1;
}
void solve(){
    int n, m;
    cin >> n >> m;
    vector<complex<long double>> inputs;
    REP(i, n) {
        union_tree[i] = i;
        long double a, b;
        cin >> a >> b;
        inputs.push_back(complex<long double>{a, b});
    }
    vector<tuple<long double, int, int>> edges;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges.push_back(make_tuple(abs(inputs[a] - inputs[b]), a, b));
    }
    sort(ALL(edges));
    long double ans = 0;
    for (int i = m - 1; i >= 0; --i) {
        ans += (long double)(1 - union_merge(get<1>(edges[i]), get<2>(edges[i]))) * get<0>(edges[i]);
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 4420
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  bool flag = false;
  for (ll i = A; i <= B; i++) {
    if (i % K == 0) flag = true;
  }
  string ans = flag ? "OK" : "NG";

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



Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;
const int MODULO = 1000000007; // check!!!
const int INF = 100000000; //1e8

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

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())


int main(){
	string s; cin>>s;
	FOR(i,sz(s)){
		char x = s[i];
		x -= 3;
		if(x < 'A') x += 'Z' - 'A' + 1;
		s[i] = x;
	}

	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
int main() {
    string a; 
    int minn = 214748364; 
    cin >> a;
    for (int i = 1; i < a.size(); i++) 
        if (a[i] != a[i - 1]) 
            minn = min(max(int(a.size()) - i, i), minn);
    if (minn < a.size()) printf("%d\n", minn); else printf("%d\n", a.size());
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<sstream>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
#define pb push_back

using namespace std;
int letters[] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
vector<string> result;
map<string,string> dictionary;      

string make_intWord(string word)
{
  stringstream ss;
  rep(i,word.size())
    {
      ss << letters[word[i]-'a'];
    }
  return ss.str();
}

void rec(string sequence,string message)
{
 
  for(map<string,string>::iterator it = dictionary.begin();it != dictionary.end();it++)
    {
      if(sequence.size() < (*it).S.size())
	continue;

      if(sequence.substr(0,(*it).S.size()) == (*it).S)
	{
	  if(sequence.size() == (*it).S.size())
	    {
	      result.pb(message + " " + (*it).F);
	      continue;
	    }
	  //cout << "sequence.substr(*it.S.size(),sequence.size()-(*it).S.size()) = "<< sequence.substr((*it).S.size(),sequence.size()-(*it).S.size()) << " : " << message << " " << (*it).F << endl; 
	  rec(sequence.substr((*it).S.size(),sequence.size()-(*it).S.size() ),message+ " " +(*it).F );
	}
    }  
 

}

int main()
{

  int n;
  while(true)
    {
      cin >> n;
      if(!n)break;

      result.clear();
      dictionary.clear();
      
      rep(i,n)
	{
	  string word;
	  cin >> word;
	  dictionary[word] = make_intWord(word);
	  //cout << "word : " << word << " -> " << dictionary[word] << endl;
	}

      string sequence;
      cin >> sequence;

      rec(sequence,"");

      rep(i,result.size())
	{
	  cout << result[i].substr(1,result[i].size()-1) << "." <<  endl;
	}
      cout << "--" << endl;
    }
  return 0;
}

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

using namespace std;

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

  int *a = new int[n];
  for(int i = 0; i < n; i+=1){
    cin >> a[i];
  }

  sort(a, a+n);
  bool flag;
  for(int i = 1; i <= a[0]; i += 1){
    flag = true;
    for(int j = 0; j < n && flag; j += 1){
      flag &= (a[j]%i == 0);
    }

    if(flag){
      cout << i << endl;
    }
  }

  delete[] a;

  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a, b;
  while(cin >> a >> b, a || b) {
    int ans = INT_MAX;
    for(int i = 1; i*i <= a; i++) {
      if(a%i) continue;
      for(int j = 1; j*j <= b; j++) {
	if(b%j) continue;
	int x = a/i, y = b/j;
	vector<int> v;
	v.push_back(i);
	v.push_back(j);
	v.push_back(x);
	v.push_back(y);
	sort(v.begin(), v.end());
	ans = min(ans, (v[1]-v[0])*(v[1]-v[0])+(v[2]-v[1])*(v[2]-v[1]) + (v[3]-v[2])*(v[3]-v[2]));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n, k, q; cin >> n >> k >> q;
    V<int> C(n);
    loop (q, i) {
        int a; cin >> a;
        C[a - 1]++;
    }
    loop (n, i) {
        if (q - C[i] >= k) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 1024
// ConsoleApplication9.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[9] = {0, 0,0,1,1,1,-1,-1,-1 };
int dyy[9] = {0, 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

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

long long 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;
}

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

ll stoL(string s) {
	ll n = s.length();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pow2(10, n - i - 1)*(ll)(s[i] - '0');
	}
	return ans;
}
int alpha[26];
int main() {
	int N; cin>> N;
	int ans = 0;
	string A, B, C; cin >> A >> B >> C;
	REP(i, N) {
		if (A[i] == B[i] && B[i] == C[i])continue;
		else if (A[i] == B[i] || B[i] == C[i]||C[i]==A[i])ans++;
		else ans += 2;
	}
	print(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    double x1, y1, x2, y2;
     
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
     
    printf("%f\n", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
     
    return (0);
     
}

Measured memory_bytes: 652
# -*- coding: utf-8 -*-

import math

n = int(input())

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

def divisor(fac):
    temp = 1
    for i in range(len(fac)):
        temp *= (fac[i][1] + 1)
    return temp

print(divisor(factorize(math.factorial(n))) % 1000000007)

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


#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define maxx 1e6+7

int main() {
	off;
	/*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif*/
	
	int n,m;
	cin>>n>>m;
	if(n>m)
	{
		cout<<0;
		return 0;
	}
	int a[m];
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
	}
	sort(a,a+m);
	vector <int> v;
	for(int i=1;i<m;i++)
	{  
		v.push_back(a[i]-a[i-1]);
	}
	int ans=a[m-1]-a[0];
	
	sort(v.begin(),v.end(),greater <int> ());
	for(int i=0;i<n-1;i++)
	{
       ans-=(v[i]);
	}
	cout<<ans<<'\n';
  	return 0;
}

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

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

void main() {
    int h, w;
    scan(h, w);
    int a, b;
    scan(a, b);

    auto ans = h * w - ((h / a * a) * (w / b * b));

    writeln(ans);
}























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

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

    return adj;
}

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

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

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

    return adj;
}

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

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

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

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

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

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

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

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

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

    return isChanged;
}

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

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

    return isChanged;
}



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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

struct edge{
  int to;
  int dist;
  int cmp;
};

struct sta{
  int id;
  int dist;
};

int main(){
  while(1){
    int n,m,c,s,g;
    cin >> n >> m >> c >> s >> g;
    if(n==0) return 0;
    s--,g--;
    vector<vector<edge>> e(n);
    int x,y,d,cc;
    for(int i=0;i<m;i++){
      cin >> x >> y >> d >> cc;
      x--,y--;
      cc--;
      e[x].push_back({y,d,cc});
      e[y].push_back({x,d,cc});
    }
    vector<int> p(c);
    for(int i=0;i<c;i++) cin >> p[i];

    vector<vector<int>> un(c,vector<int>(20001));
    for(int i=0;i<c;i++){
      vector<int> q(p[i]-1),r(p[i]);
      for(int j=0;j<p[i]-1;j++) cin >> q[j];
      for(int j=0;j<p[i];j++) cin >> r[j];
      int now=0;
      for(int j=1;j<=20000;j++){
        if(now<p[i]-1) if(j>q[now]) now++;
        un[i][j]=un[i][j-1]+r[now];
      }
    }
    vector<int> ds(n,IINF);
    priority_queue<sta,vector<sta>,function<bool(sta,sta)>>
      heap([](const sta &a, const sta &b){return a.dist>b.dist;});
    heap.push({s,0});
    while(!heap.empty()){
      sta now = heap.top();
      heap.pop();
      if(ds[now.id]!=IINF) continue;
      // cout <<now.id+1 SP now.dist << endl;
      ds[now.id]=now.dist;
      for(int cmp=0;cmp<c;cmp++){
        priority_queue<sta,vector<sta>,function<bool(sta,sta)>>
          dijk([](const sta &a, const sta &b){return a.dist>b.dist;});
        vector<int> ddd(n,IINF);
        dijk.push({now.id,0});
        while(!dijk.empty()){
          auto nn=dijk.top();
          dijk.pop();
          if(ddd[nn.id]!=IINF) continue;
          ddd[nn.id] = nn.dist;
          for(auto nx:e[nn.id]){
            if(nx.cmp!=cmp) continue;
            if(ddd[nx.to]!=IINF) continue;
            dijk.push({nx.to,nn.dist+nx.dist});
          }
        }
        for(int i=0;i<n;i++){
          if(ddd[i]!=IINF&&ds[i]==IINF){
            heap.push({i,now.dist+un[cmp][ddd[i]]});
          }
        }
      }
    }
    if(ds[g]==IINF) cout << -1 << endl;
    else cout << ds[g] << endl;
  }
  return 0;
}



Measured memory_bytes: 6252
#include<iostream>
using namespace std;
int main(){

	int n,a,m,l=0,k=0;
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>a;
	if(a==1){
		k=k+1;
		if(l<k){
		l=k;
		}
	}
	else{k=0;}
	}



	cout<<l+1<<endl;

	return 0;
}


Measured memory_bytes: 3088
s = input()
t = input()
x = 0
for i in range(0,len(s)-len(t)+1):
    p = s[i:i+len(t)]

    y = 0
    for j in range(0,len(t)):
        if p[j] == t[j]:
            y = y + 1

    if y >= x:
        x = y

print(len(t) - x)

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

using namespace std;

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

    int c[501], s[501], f[501];
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i] >> s[i] >> f[i];
    }

    for (int i = 0; i < n; ++i) {
        int t = 0;
        for (int j = i; j < n - 1; ++j) {
            t = max(t, s[j]);
            if (t % f[j] != 0) t += f[j] - (t - s[j]) % f[j];
            t += c[j];
        }
        cout << t << endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

/*
全探索.
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func solve(k int, ms []int) bool {
	return solveK(k, 0, 0, ms)
}

func solveK(k, sum, idx int, ms []int) bool {
	if sum == k {
		return true
	}
	if idx >= len(ms) {
		return false
	}
	return solveK(k, sum+ms[idx], idx+1, ms) || solveK(k, sum, idx+1, ms)
}

func isAssembleK(k int, ms []int) bool {
	for i, m := range ms {
		if k == m {
			return true
		}
		if m < k {
			if isAssembleK(k-m, ms[i+1:len(ms)]) {
				return true
			}
		}
	}
	return false
}

// func solve(k int, ms []int) bool {
// 	for i := range ms {
// 		if isAssembleK(k, ms[i:len(ms)]) {
// 			return true
// 		}
// 	}
// 	return false
// }
//
// func isAssembleK(k int, ms []int) bool {
// 	for i, m := range ms {
// 		if k == m {
// 			return true
// 		}
// 		if m < k {
// 			if isAssembleK(k-m, ms[i+1:len(ms)]) {
// 				return true
// 			}
// 		}
// 	}
// 	return false
// }

func main() {
	scanner := makeScanner(8192)
	eGetInt(scanner)
	ms := eGetInts(scanner)
	eGetInt(scanner)
	qs := eGetInts(scanner)
	for _, q := range qs {
		if solve(q, ms) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(max int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), max)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = " "
	}
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}



Measured memory_bytes: 1144
import sys
input = sys.stdin.readline
INF = 10**9
MOD = 10**9 + 7

def main():
    n = int(input())
    
    ans = 0
    for _ in range(n):
        x,u = map(str,input().split())
        if u == 'JPY':
            ans += int(x)
        else:
            ans += float(x) * 380000.0
    print(ans)
  
if __name__=='__main__':
    main()

Measured memory_bytes: 3060
from copy import deepcopy
h, w, k = map(int, input().split())
c = []
for _ in range(h):
    c.append(list(input()))

def cnt(table):
    ret = 0
    for row in range(h):
        for col in range(w):
            ret += (table[row][col] == "#")
    return ret

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        c_copy = deepcopy(c)
        for row in range(h):
            if ((i >> row) & 1):
                for col in range(w):
                    c_copy[row][col] = ":"
        for col in range(w):
            if ((j >> col) & 1):
                for row in range(h):
                    c_copy[row][col] = ":"
        ans += (cnt(c_copy) == k)
print(ans)


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

int main() {
  ll x;
  cin >> x;
  ll cnt = (x/11) * 2;
  if (x % 11 > 6) cnt += 2;
  else if (x % 11 > 0) cnt++;
  cout << cnt << endl;
  return 0;
}


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

int main(){
  int N,v;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> v;
    A[i] = v;
  }
  int maxv = 0, sum = 0;
  for(int i = 0; i < N; i++){
    if(A[i] > A[maxv]){
      maxv = i;
    }
    sum += A[i];
  }

  if(A[maxv] < sum - A[maxv]){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  return 0;

}

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

int main(void) {
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    long long ans = 1000000000;
    for (int i = 0; i < 100; i++) {
        long long tmp = 0;
        for (int j = 0; j < N; j++) {
            tmp += (X[j] - i) * (X[j] - i);
        }
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int K,N;
  cin >> N >> K;
 
  vector<int>p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int sum = 0;
  sort(p.begin(), p.end());
  for (int i = 0; i < K; i++) {
    sum += p.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624