akhauriyash/Code-Regression huggingface dataset:
h,w=gets.split.map(&:to_i)
s=[]
h.times do
  s << gets.chomp.chars
end
a=0
h.times do |i|
  w.times do |j|
    if s[i][j]==nil
      next
    elsif s[i][j]=="."
      f="#"
      ha=Hash.new(0)
      ha["."]=1
    else
      f="."
      ha=Hash.new(0)
      ha["#"]=1
    end
    s[i][j]=nil
    q=[[i,j]]
    while q!=[]
      z=[]
      q.each do |qi,qj|
        if qi>0&&s[qi-1][qj]==f
          s[qi-1][qj]=nil
          z << [qi-1,qj]
          ha[f]+=1
        end
        if qj>0&&s[qi][qj-1]==f
          s[qi][qj-1]=nil
          z << [qi,qj-1]
          ha[f]+=1
        end
        if qi<h-1&&s[qi+1][qj]==f
          s[qi+1][qj]=nil
          z << [qi+1,qj]
          ha[f]+=1
        end
        if qj<w-1&&s[qi][qj+1]==f
          s[qi][qj+1]=nil
          z << [qi,qj+1]
          ha[f]+=1
        end
      end
      if f=="."
        f="#"
      else
        f="."
      end
      q=z.dup
    end
    a+=ha["."]*ha["#"]
  end
end
puts a


Measured memory_bytes: 24992
# -*- coding: utf-8 -*-
N, M = map(int, input().split())

N_list = [[] for _ in range(N + 1)]
for i in range(M):
    A, B = map(int, input().split())
    N_list[A].append(B)
    N_list[B].append(A)

ans_list = [-1 for _ in range(N + 1)]

def make_shirube(n):
    target_list = N_list[n]
    next_list = []
    for room in target_list:
        if ans_list[room] == -1:
            ans_list[room] = n
            next_list.append(room)
    return next_list

next_loop_list = make_shirube(1)
while len(next_loop_list) > 0:
    temp_list = []
    for room in next_loop_list:
        temp_list.append(make_shirube(room))
    next_loop_list = [flatten for inner in temp_list for flatten in inner]
if ans_list[1:].count(-1) == 0:
    print("Yes")
    print("\n".join(map(str, ans_list[2:])))
else:
    print("No")

Measured memory_bytes: 42168
#include <iostream>

#define ll long long
#define LINF 1e18
#define INF 1e9 + 7

using namespace std;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;

  if (A % C == 0) {
    if (B % C == 0) {
      cout << (B / C) - (A / C) + 1 << endl;
    } else {
      cout << (B / C) - (A / C) + 1 << endl;
    }
  } else {
    if (B % C == 0) {
      cout << (B / C) - (A / C) << endl;
    } else {
      cout << (B / C) - (A / C) << endl;
    }
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()

if N % 1000 == 0:
    print(0)
else:
    print(1000 - N % 1000)


Measured memory_bytes: 61712
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aizu
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(ReadLine());
			var matrices = new List<int[]>();
			for (var i = 0; i < n; i ++)
			{
				matrices.Add(ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray());
			}

			var mins = new long[n, n];
			for(var i = 0; i < n; i++)
			{
				for(var j = 0; j < n; j++)
				{
					if (i != j)
					{
						mins[i, j] = int.MaxValue;
					}
					else
					{
						mins[i, j] = 0;
					}
				}
			}

			WriteLine(Dp(mins, matrices, 0, n - 1));
		}

		private static long Dp(long[,] mins, List<int[]> matrices, int left, int right)
		{
			if(mins[left, right] != int.MaxValue)
			{
				return mins[left, right];
			}

			long min = int.MaxValue;
			if(Abs(left - right) == 1)
			{
				min = matrices[left][0] * matrices[left][1] * matrices[right][1];
			}
			else
			{
				for (var i = left; i < right; i++)
				{
					min = Min(min, (Dp(mins, matrices, left, i) + Dp(mins, matrices, i + 1, right) + matrices[left][0] * matrices[i][1] * matrices[right][1]));
				}
			}

			mins[left, right] = min;
			return min;
		}
	}
}



Measured memory_bytes: 18332
S = list(str(input()))
S_rev = S[::-1]

if len(S)%2 == 0:
  s1 = S[:len(S)//2]
  s2 = S_rev[:len(S)//2]
else:
  s1 = S[:len(S)//2 +1]
  s2 = S_rev[:len(S)//2 +1]
count = 0
for i in range(len(s1)):
  if not s1[i] == s2[i]:
    count += 1
print(count)
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;

main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll s = 0;
  for (int &v : a) cin >> v, s ^= v;
  for (int v : a) cout << (s ^ v) << ' ';
}


Measured memory_bytes: 3920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <stack>

#define rep(i, n) for(int i=0;i<n;i++)
#define IOS() ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define INT_MINI -987654321
#define INT_MAXI 987654321


using namespace std;

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 n, m;
int a[34] = {0, 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};

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    cin >> n;

    cout << a[n];

    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**5)

run=deque()

def rec(n,cnt):
    if cnt>10:return
    run.append(int(n))
    if n[-1]!="0":
        rec(n+str(int(n[-1])-1),cnt+1)
    if n[-1]!="9":
        rec(n+str(int(n[-1])+1),cnt+1)
    rec(n+n[-1],cnt+1)
k=int(input())
for i in range(1,10):
    rec(str(i),1)
a=sorted(run)
print(a[k-1])

Measured memory_bytes: 13248
#include <bits/stdc++.h>
using namespace std;
typedef long long               ll;
const int mod = 1e9+7;
#ifndef M_PI
const double M_PI = acos(-1.0);
#endif

int main(){
  cin.sync_with_stdio(false);
  int n, m;
  string s, t;
  cin>>n>>m;
  cin>>s>>t;
  int g = __gcd(n, m);
  for(int i=0; i<g; ++i){
    if(s[(ll)i*n/g] != t[(ll)i*m/g]){
      cout<<"-1\n";
      return 0;
    }
  }
  cout<<(ll)n*m/g<<'\n';
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(){
  int n,l;
  scanf("%d%d",&n,&l);
  char s[n][l+1];
  char temp[l+1];
  for(int i=0;i<n;i++)scanf("%s",&s[i]);
  for(int i=0;i<n-1;i++)for(int j=0;j<n-1;j++){
    if(0<strcmp(s[j],s[j+1])){
      strcpy(temp,s[j]);
      strcpy(s[j],s[j+1]);
      strcpy(s[j+1],temp);
    }
  }
  for(int i=0;i<n;i++)printf("%s",s[i]);
  return 0;
}

Measured memory_bytes: 128
K,N = map(int,input().split())
A = list(map(int,input().split()))

max_range = 0

for i in range(N):
    if i == N-1:
        if max_range < K-A[i]+A[0]:
            max_range = K-A[i]+A[0]
    else:
        if max_range < A[i+1]-A[i]:
            max_range = A[i+1]-A[i]
            

ans = K - max_range
print(ans)

Measured memory_bytes: 32216
#include <cstdio>
#include <cstring>
#include <algorithm>
#define SIZE 100100
using namespace std;

long long rec[SIZE];

int main()
{
    int n,t,i;
    int tmp,pos;
    long long ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%lld",rec+i);
    sort(rec,rec+n);
    if(rec[0]<0)
    {
        ans=rec[n-1];
        for(i=n-2;rec[i]>0;i--)
            ans+=rec[i];
        for(pos=i;i>=0;i--)
            ans-=rec[i];
        printf("%lld\n",ans);
        for(i=pos+1;i<n-1;i++)
        {
            printf("%lld %lld\n",rec[0],rec[i]);
            rec[0]-=rec[i];
        }
        for(i=0;i<=pos;i++)
        {
            printf("%lld %lld\n",rec[n-1],rec[i]);
            rec[n-1]-=rec[i];
        }
    }
    else
    {
        if(n==1)
            ans=rec[0];
        else
            ans=-rec[0];
        for(i=1;i<n;i++)
            ans+=rec[i];
        printf("%lld\n",ans);
        for(i=1;i<n-1;i++)
        {
            printf("%lld %lld\n",rec[0],rec[i]);
            rec[0]-=rec[i];
        }
        if(n>1)
        printf("%lld %lld\n",rec[n-1],rec[0]);
    }

    return 0;
}


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

using namespace std;

const int MOD = 998244353;

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

vector<int> grundy(int N){
    int M; cin >> M;
    vector<vector<int>> g(N);
    for(int i=0;i<M;i++){
        int a, b; cin >> a >> b;
        --a; --b;
        if(a > b) swap(a, b);
        g[a].push_back(b);
    }
    vector<int> res(N);
    vector<int> gr(N, 0);
    for(int i=N-1;i>=0;i--){
        for(int j=0;j<=g[i].size();j++) gr[j] = 0;
        for(auto& t : g[i]) gr[res[t]] = 1;
        for(int j=0;;j++){
            if(!gr[j]){ res[i] = j; break; }
        }
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<long long> res(1024, 0);
        res[0] = 1;
        for(int i=0;i<3;i++){
            auto gr = grundy(N);
            vector<long long> dst(1024, 0);
            vector<long long> next(1024, 0);
            for(int j=0;j<N;j++){
                dst[gr[j]] += modPow(10, 18*(j+1));
                dst[gr[j]] %= MOD;
            }
            for(int j=0;j<1024;j++){
                for(int k=0;k<1024;k++){
                    next[k^j] += res[k] * dst[j];
                    next[k^j] %= MOD;
                }
            }
            res = next;
        }
        cout << res[0] << endl;
    }
}

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

long long gcd(long long a, long long b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = gcd(a[0], a[1]);
	for (int i = 2; i < n; i++) {
		ans = gcd(ans, a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>


#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX_V = 100001;
const long long INF = 1e12;

int n,m,r;

struct edge{
	int to, dist;
	edge(int t_to,int t_dist){
		to=t_to;dist=t_dist;
	}
};

typedef pair<int,int> P;//cost??¨v

vector< vector<edge> > G(MAX_V);
long long d[MAX_V];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	fill_n((long long *)d, sizeof(d)/sizeof(long long),INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		if(d[v]<p.first) continue;
		rep(i,G[v].size()){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.dist){//??????????????´???
				d[e.to] = d[v] + e.dist;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}


int main(){

	cin >> n >> m >> r;

//	G.clear();
//	G.resize(n);

	rep(i,m){
		int a,b,d;
		cin >> a >> b >> d;
		edge tmp1(b,d);
		G[a].push_back(tmp1);
	}

	dijkstra(r);
	rep(i,n){
		//if(i==r) continue;
		if(d[i]==INF) cout << "INF" <<endl;
		else cout << d[i] << endl;
	}

}

Measured memory_bytes: 11672
N = gets.chomp.to_i
as = gets.chomp.split.map(&:to_i)
gcd_l = Array.new(N)
gcd_l[0] = as[0]
gcd_r = Array.new(N)
gcd_r[-1] = as[-1]

for i in 1..(N-1) do
    gcd_l[i] = gcd_l[i-1].gcd(as[i])
    gcd_r[N-1-i] = gcd_r[N-i].gcd(as[N-1-i])
end

max = 0
for i in 0..(N-1) do
    if i == 0
        max = [max, gcd_r[i+1]].max
    elsif i == N-1
        max = [max, gcd_l[i-1]].max
    else
        cmp = gcd_l[i-1].gcd(gcd_r[i+1])
        max = [max, cmp].max
    end
end
puts max


Measured memory_bytes: 13836
/*
AizuOnline A0125
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int day_of_month_table[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//
int isLeap(int y)
{
  if((y % 400)==0)
    return(1);
  if((y % 100)==0)
    return(0);
  if((y % 4)==0)
    return(1);
  return(0);
}
int day_of_year(int y)
{
  return(365+isLeap(y));
}
int day_of_month(int y,int m)
{
  return(day_of_month_table[m-1]+((isLeap(y)&&(m==2))?1:0));
}
int datediff(int y1,int m1,int d1,int y2,int m2,int d2)
{
  int i,s;

  if(y1==y2)
   
      if(m1==m2)
	return(d2-d1);
      else
	{
	  s = day_of_month(y1,m1)-d1;
	  if(m2 > m1+1)
	    for(i=m1+1;i<=m2-1;i++)
	      s += day_of_month(y1,i);
	  return(s+d2);
	}
    
  else
    {
      s = datediff(y2,1,1,y2,m2,d2)+1;
      if(y2 > y1+1)
	for(i=y1+1;i<=y2-1;i++)
	  s += day_of_year(i);
      s += datediff(y1,m1,d1,y1,12,31);
      return(s);
    }
}
main()
{
  int y1,m1,d1,y2,m2,d2,ret;
  //printf("2001=%d\n",isLeap(2001));
  while(scanf("%d %d %d %d %d %d",&y1,&m1,&d1,&y2,&m2,&d2) 
	&& (y1!=-1 || m1!=-1 || d1!=-1 ||y2!=-1 || m2!=-1 || d2!=-1 ))
    {
      ret=datediff(y1,m1,d1,y2,m2,d2);
      printf("%d\n",ret);
    }

return(0);
}

Measured memory_bytes: 596
//16D8104007J Kanehiro Maho
#include<stdio.h>

int main(void){
  int n,m;

  scanf("%d",&n);
  scanf("%d",&m);


  int a[50000];
  int ans[50000]={0};
  int i,j;
  int max;
  // int ma1,ma2;
  int cnt1=0;
  int cnt2=0;
  int x;
  

  while(n!=0&&m!=0){
    max=-1;
    // ma1=-1;
    // ma2=-1;
    for(i=0;i<n;i++){
      scanf("%d",&a[cnt1+i]);
    }

    for(i=0;i<n;i++){
      for(j=i+1;j<n;j++){
	x=a[cnt1+i]+a[cnt1+j];
	//	printf("%d ",x);
	if(x>max&&x<=m){
	  // ma1=i;
	  // ma2=j;
	  max=x;
	}
      }
    }
    ans[cnt2]=max;
    cnt2++;
    cnt1+=n;
    scanf("%d",&n);
    scanf("%d",&m);
  }
  
  for(i=0;i<cnt2;i++){
    if(ans[i]==-1){
      printf("NONE\n");
    }else{
      printf("%d\n",ans[i]);
    }
  }
  return 0;
}
    

    
  



Measured memory_bytes: 2032
STR=''
try:
    while True:
        str=input()
        str=str.lower()
        if str=='':
            break
        STR+=str
except EOFError:
    pass
for i in range(26):
    sum=0
    sum=STR.count(chr(ord('a')+i))
    print('%s : %d' % (chr(ord('a')+i),(sum)))



Measured memory_bytes: 5564
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int n,m;

    cin >> n >> m;

    vector<int> h(n);

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

    vector<vector<int>> pathlist(n,vector<int> {});

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

        pathlist[a-1].push_back(b-1);
        pathlist[b-1].push_back(a-1);
    }

    int sum = 0;

    for(int i=0; i<n; i++){
        bool flg = true;

        for(auto j:pathlist[i]){
            if(h[i]<=h[j]){
                flg = false;
                break;
            }
        }
        
        if(flg){
            sum++;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 8716
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
void solve() {
    int x;
    R(x);
    W(x>=30?"Yes":"No");
}
int main(){
#define MULTITEST 0
#if MULTITEST    
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3752
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(len(A)-1):
    if i > 0 and i < N:
        if (A[i] >A[i-1] and A[i]< A[i+1]):
            cnt+=1
        else:
            if (A[i] < A[i-1] and A[i] >A[i+1]):
                cnt+=1
            else:
                i+=1
print(cnt)


Measured memory_bytes: 3060
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let h: usize = s.next().unwrap().parse().unwrap();
	let w: usize = s.next().unwrap().parse().unwrap();
	let mut a = (0..h).map(|_| s.by_ref().take(w).map(|a| a.parse::<i16>().unwrap()).collect::<Vec<_>>()).collect::<Vec<_>>();
	for i in 0..h {
		for (j, b) in s.by_ref().take(w).map(|a| a.parse::<i16>().unwrap()).enumerate() {
			a[i][j] -= b;
		}
	}
	let n = std::cmp::min((w + h) * 80, 6401) as i16;
	let mut dp = vec![vec![vec![0u8; n as usize]; w]; h];
	dp[0][0][a[0][0].abs() as usize] = 1;
	for y in 0..h {
		for x in 0..w {
			if y >= 1 {
				for i in 0..n {
					if dp[y - 1][x][i as usize] == 0 { continue; }
					if (i + a[y][x]).abs() < n { dp[y][x][(i + a[y][x]).abs() as usize] = 1; }
					if (i - a[y][x]).abs() < n { dp[y][x][(i - a[y][x]).abs() as usize] = 1; }
				}
			}
			if x >= 1 {
				for i in 0..n {
					if dp[y][x - 1][i as usize] ==  0 { continue; }
					if (i + a[y][x]).abs() < n { dp[y][x][(i + a[y][x]).abs() as usize] = 1; }
					if (i - a[y][x]).abs() < n { dp[y][x][(i - a[y][x]).abs() as usize] = 1; }
				}
			}
		}
	}
	for i in 0..n as usize {
		if dp[h - 1][w - 1][i] != 0 {
			println!("{}", i);
			return;
		}
	}
}


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

int main()
{
    int n;
      cin >> n;
      map<string, int> mp;
      for(int i = 0; i < n; i++)
    {
          string s;
      cin >> s;
      mp[s]++;
    }
     set<pair<int , string> > st ; 
  auto it = mp.begin() ; 
  for( ; it != mp.end() ; it++ ) 
  {
    st.insert( { -it -> second , it -> first } ) ; 
  }
  auto it1 = st.begin() ; 
  for( ; it1!= st.end() ; it1++ ) 
    if(it1 -> first == st.begin() -> first)
    cout << it1 -> second << "\n" ; 
  
}


Measured memory_bytes: 37760
import java.util.Scanner;

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

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int countNeg = 0;
      int absMin = Integer.MAX_VALUE;
      long absSum = 0;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();
        absSum += Math.abs(A[i]);
        absMin = Math.min(absMin, Math.abs(A[i]));

        if (A[i] < 0) {
          ++countNeg;
        }
      }
      
      if (countNeg % 2 == 0) {
        System.out.println(absSum);
      } else {
        System.out.println(absSum - absMin * 2);
      }
    }
  }
}

Measured memory_bytes: 50280
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
ll c[5];
int main()
{
    int n;
    cin >>n;
    string s;
    for(int i=0;i<n;i++){
        cin >>s;
        if(s[0]=='M'){c[0]++;}
        else if(s[0]=='A'){c[1]++;}
        else if(s[0]=='R'){c[2]++;}
        else if(s[0]=='C'){c[3]++;}
        else if(s[0]=='H'){c[4]++;}
    }
    ll ans=0;

    //for(int i=0;i<5;i++)cout <<c[i]<<" ";
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ll v=c[i]*c[j]*c[k];
                ans+=v;
            }
        }
    }
    cout <<ans;
    return 0;
}


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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

long long ans(int c, int n, int W, vector<int> &w, vector<int> &v, vector<vector<long long> > &dp) {
    // debug
    // cout << c << " " << W << " called" << endl;
    if (W == 0)
        return 0;
    else if (c >= n)
        return 0;
    else if (dp[c][W] != -1)
        return dp[c][W];
    // don't take the c-th item
    long long a = ans(c + 1, n, W, w, v, dp);
    // take the c-th item if you can
    if (W >= w[c]) {
        a = max(a, (ll)v[c] + ans(c + 1, n, W - w[c], w, v, dp));
    }
    dp[c][W] = a;
    // cout << c << " " << W << " returned " << dp[c][W] << endl;
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n);
    vector<vector<ll> > dp(n, vector<ll>(W + 1, -1));
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];

    cout << ans(0, n, W, w, v, dp);

    return 0;
}

Measured memory_bytes: 79488
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int K,A,B;
  cin>>K>>A>>B;
  REP(i,1000){
    if(A<=K*i and K*i<=B){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
 
int main() {
ll n;
cin>>n;
ll ca=10000000000;
ll counter=0;
ll a[n]={};
ll cb=10000000000;
ll cc;
ll f=0;
ll counter1;
ll cd;
ll ce;
for(ll i=0;i<n;i++){
cin>>a[i];}
sort(a,a+n);
cout<<a[n-1]<<" ";
if(a[n-1]%2==0){
counter=a[n-1]/2;
for(ll i=0; i<n; i++){
if(counter<a[i]){
ca=i;
break;
}}

if(abs(counter-a[ca-1])>abs(counter-a[ca])){
cout<<a[ca]<<endl;}
else
cout<<a[ca-1]<<endl;}

else{
counter=a[n-1]/2;
for(ll i=0; i<n; i++){
if(counter<a[i]){
ca=i;
break;
}}

counter1=a[n-1]/2+1;
for(ll i=0; i<n; i++){
if(counter1<a[i]){
cb=i;
break;
}}

if(abs(counter-a[ca-1])>abs(counter-a[ca])){
cc=abs(counter-a[ca]);}
else{
cc=abs(counter-a[ca-1]);}

if(abs(counter1-a[cb-1])>abs(counter1-a[cb])){
cd=abs(counter1-a[cb]);}
else{
cd=abs(counter1-a[cb-1]);}

if(cc>cd){
if(abs(counter1-a[cb-1])>abs(counter1-a[cb])){
cout<<a[cb]<<endl;}
else
cout<<a[cb-1]<<endl;}
 
else{
if(abs(counter-a[ca-1])>abs(counter-a[ca])){
cout<<a[ca]<<endl;}
else
cout<<a[ca-1]<<endl;}}}


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

int main() {
	int N;
	cin >> N;
	int sum = 0;
	int B[N-1];
	for(int i = 1; i <= N - 1; i++)
	cin >> B[i];
	sum = B[1] + B[N-1];
	for(int i = 1; i <= N - 2;i++)
	sum += min(B[i], B[i+1]);
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.sql.*;

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();
		
		Arrays.sort(s);
		Arrays.sort(t);
		
		for (int i = 0; i < t.length / 2; i++) {
			char tmp = t[i];
			t[i] = t[t.length - i - 1];
			t[t.length - i - 1] = tmp; 
		}
		
		String ss = String.valueOf(s);
		String st = String.valueOf(t);
		
		if (ss.compareTo(st) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=3010;
int a[M],ans=0;
string s;
int main()
{
    cin>>s;
    a[0]=1;
    for(int i=s.size()-1,j=1,k=0;i>=0;i--,j=j*10%2019)
    {
        k=(k+(s[i]-'0')*j%2019)%2019;
        ans+=a[k];
        a[k]++;
    }
    cout<<ans;
    return 0;
}


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

int main(){
	int N, M, P, x;
	
	while(1){
		int temp = 0, sum = 0;
		cin>>N>>M>>P;
		
		if(N == 0 && M == 0 && P == 0) break;
		
		for(int i = 1; i <= N; i++){
			cin>>x;
			sum += x;
			if(M == i) temp = x;
		}
		
		sum *= 100;
		sum = sum - sum * (P/100.0);
		
		if(temp)cout<<sum/temp<<endl;
		else cout<<0<<endl;
		
		
		
	}
	return 0;
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a,b,c,d;
  cin >> N;
  a=N/1000;
  b=N/100%10;
  c=N/10%10;
  d=N%10;
  if(a==b&&b==c||b==c&&c==d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
bool cmp(long long a, long long b){
    return a > b;
}
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = b;
        b = a % b;
        a = t;
    }
    return a;
}
long long levels[100500];
void dfs(long long current, long long prev, set<long long>* sets){
    for (auto it:sets[current]){
        if (prev != it){
            levels[it] = levels[current] + 1;
            dfs(it, current, sets);
        }
    }
}

long long st[10], fin[10];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max, s1;
    long long da, db;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    if (n < 2)
        cout << 0;
    else {
        ch = 1;
        for (i = 0; i < n; i++) {
            ch = ch * 8;
            ch = ch % ((long long) (1e9) + 7);
        }
        ch1 = 1;
        for (i = 0; i < n; i++) {
            ch1 = ch1 * 9;
            ch1 = ch1 % ((long long) (1e9) + 7);
        }
        long long ch2 = 1;
        for (i = 0; i < n; i++) {
            ch2 = ch2 * 10;
            ch2 = ch2 % ((long long) (1e9) + 7);
        }
        ans = ch2 - ch1 * 2 + ch;
        if (ans < 0)
            ans = ans + 12 * (1e9 + 7);
        ans = ans % ((long long) (1e9) + 7);
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;
using Graph = vector<vector<int>>;

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 myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

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

vector<bool> seen;
void dfs(const Graph& G, int v, int count) {
    seen[v] = true;
    count = 0;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        if (count > 2) continue;
        count++;
        cout << count << ":" << next_v << endl;
        dfs(G, next_v, count);
    }
}

const long long INF = 1LL << 60;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> A(Q),B(Q);
    for (int i = 0; i < Q; i++) {
        cin >> A.at(i) >> B.at(i);
    }
    for (int i = 0; i < N - 1; i++) {
        if (S.at(i) == 'A' && S.at(i + 1) == 'C') S.at(i+1) = 'c';
    }
    vector<int> count(N);
    int c = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'c') c++;
        count.at(i) = c;
        //cout << count.at(i);
    }
    for (int i = 0; i < Q; i++) {
        cout << count.at(B.at(i) - 1) - count.at(A.at(i) - 1) << endl;
    }
}

Measured memory_bytes: 2176
#include <cstdio>
#include <algorithm>
#include <tr1/unordered_set>
using namespace std;

int n , v[20] , ans = 0;

tr1::unordered_set<int> memo[20];

int X[421] , Y[421] , top;
 
int main(){
	while(scanf("%d\n",&n)&& n){
		for(int i = 0 ; i < n ; i++) scanf("%d",&v[i]) , memo[i].clear() ;
		ans = 99999999;
		top = 0;
		X[top] = 0;
		Y[top] = 0;
		while(~top){
			int pos = X[top] , sum = Y[top]; top--;
			if(pos==n) ans = min(ans,sum);
			else{
				X[++top] = pos+1;
				Y[top]   = sum+v[pos];
				X[++top] = pos+1;
				Y[top]   = abs(sum-v[pos]);
			}
		}
		printf("%d\n",ans);
	}
}

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }
    vector<vector<int>> P(N, vector<int>(11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    int res = INT32_MIN;
    for (int i = 1; i < (1 << 10); i++) {
        int profit = 0;
        for (int j = 0; j < N; j++) {
            int count = 0;
            for (int k = 0; k < 10; k++) {
                if (F[j][k] && i & (1 << k)) count++;
            }
            profit += P[j][count];
        }
        res = max(res, profit);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char s1[1000],s2[1000];
int l1,l2,i;
int main()
{
  scanf("%s%s",s1,s2);
  l1=strlen(s1);l2=strlen(s2);
  if (l1<l2) {printf("<\n");return 0;}
  if (l1>l2) {printf(">\n");return 0;}
  for (i=0;i<l1;i++)
  {
    if (s1[i]>s2[i]) {printf(">\n");return 0;}
    if (s1[i]<s2[i]) {printf("<\n");return 0;}
  }
  printf("=\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'

 main() {
	int n, k;
	cin>>n>>k;
	int c[n];
	int p[n];
	for(int i=0; i<n; i++){
		cin>>p[i];
		p[i]--;
	}
	int maxi=-1e18;
	for(int i=0; i<n; i++){
		cin>>c[i];
		maxi=max(maxi, c[i]);
	}
	for(int i=0; i<n; i++){
		vector<int>path;
		path.pb(i);
		int tot=0;
		
		int node=p[i];
		while(node!=i){
			path.pb(node);
			node=p[node];
		}
		for(auto u:path){
			tot+=c[u];
		}
		int times=(k/path.size());
		int rem=(k%path.size());
		if(times==0){
			int sum=0;
			for(int j=0; j<k; j++){
				sum+=c[path[j]];
				maxi=max(maxi, sum);
			}
			continue;
		}
		if(tot<=0){
			int sum=0;
			for(int j=0; j<path.size(); j++){
				sum+=c[path[j]];
				maxi=max(maxi, sum);
			}
			continue;
		}
		int sum=0;
		int m2=-1e18;
		for(int j=0; j<rem; j++){
			sum+=c[path[j]];
			m2=max(m2, sum);
		}
		maxi=max(maxi, times*tot+m2);
		times--;
		sum=0;
		m2=-1e18;
		for(int j=0; j<path.size(); j++){
			sum+=c[path[j]];
			m2=max(m2, sum);
		}
		maxi=max(maxi, times*tot+m2);
	}
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 3800
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
    int N;
    cin >> N;

    int n4 = N/1000; N = N % 1000;
    int n3 = N/100; N = N % 100;
    int n2 = N/10; N = N % 10;
    int n1 = N;

    if( ((n4==n3)&&(n4==n2)) || ((n3==n2)&&(n3==n1)) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static final long mod = (long)1e9+7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); int ans = 0;
		long dp[][][][] = new long[n+1][4][4][4];
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					dp[1][j][k][l] = 1;
					dp[2][j][k][l] = 1;
					dp[3][j][k][l] = 1;
				}
			}
		}
		dp[3][0][1][2] = 0; dp[3][1][0][2] = 0; dp[3][0][2][1] = 0;
		for (int i = 3; i < n; i++) {
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 4; k++) {
					for (int l = 0; l < 4; l++) {
						if(k!=0||l!=2) {
							dp[i+1][k][l][1] += dp[i][j][k][l];
						}
						if((k!=0||l!=1)&&(k!=1||l!=0)&&(j!=0||l!=1)&&(j!=0||k!=1)){
							dp[i+1][k][l][2] += dp[i][j][k][l];
						}
						dp[i+1][k][l][0] += dp[i][j][k][l];
						dp[i+1][k][l][3] += dp[i][j][k][l];
						for (int m = 0; m < 4; m++) dp[i+1][k][l][m] %= mod;
					}
				}
			}
		}
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					ans += dp[n][j][k][l];
					ans %= mod;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23252
n=int(input())
d={i+1:j for (i,j) in enumerate(map(int,input().split()))}
m=int(input())
for _ in range(m):
  a,b=map(int,input().split())
  s=sum([j if i!=a else b  for (i,j) in d.items()])
  print(s)

Measured memory_bytes: 3064
def resolve():
    A, B, K = list(map(int, input().split()))
    cnt = 0
    i = max(A, B)
    while True:
        if A%i==0 and B%i==0:
            cnt += 1
            if cnt == K:
                break
        i -= 1
    print(i)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 61852
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		DisjointSet dj = new DisjointSet(n);

		for(int i = 0; i < m; i++){
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;

			dj.union(a, b);
		}

		int maxNum = 0;
		for(int i = 0; i < n; i++){
			maxNum = Math.max(maxNum, dj.amountOfOwnGroup(i));
		}

		System.out.println(maxNum);
	}
}

class DisjointSet {
	private int n;
	private int[] p;
	private int[] rank;
	//各グループの要素数を管理する
	private int[] num;
	//グループ数を管理する
	private int numOfGroup;

	public DisjointSet(int n){
		this.n = n;

		p = new int[n + 1];
		rank = new int[n + 1];

		num = new int[n + 1];

		Arrays.fill(num, 1);

		for(int i = 1; i <= n; i++){
			makeSet(i);
		}

		numOfGroup = n;
	}

	private void makeSet(int x){
		p[x] = x;
		rank[x] = 0;
	}

	public void union(int x, int y){
		int p1 = findSet(x), p2 = findSet(y);
		int num1 = num[p1];
		int num2 = num[p2];
		link (findSet(x), findSet(y));

		if(p1 != p2) {
			num[p1] = num[p2] = num1 + num2;
			numOfGroup--;
		}
	}

	public int amountOfOwnGroup(int x) {
		return num[findSet(x)];
	}

	public int numOfGroup() {
		return numOfGroup;
	}
	private int findSet(int x){
		if(x != p[x]){
			p[x] = findSet( p[x]);
		}
		return p[x];
	}

	public boolean isSameSet(int x, int y){
		return findSet(x) == findSet(y);
	}

	private void link(int x, int y){
		if(rank[x] > rank[y]){
			p[y] = x;
		}
		else {
			p[x] = y;
			if(rank[x] == rank[y]){
				rank[y]++;
			}
		}
	}

	//for debug
	public void printPArray() {
		for(int i = 1; i <= n; i++) {
			System.out.print(p[i]+" ");
		}
		System.out.println();
	}
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 143

typedef long long ll;
typedef pair<int, int> pa;
typedef pair<pa, int> ppa;
int N, M, L, Q;

struct edge{
    int to, cost;
    edge(int t, int c) : to(t) , cost(c) {}
};

vector<edge> G[310];
pa dist[310][310];

int main(){

    cin >> N >> M >> L;
    rep(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        if(c > L)continue;
        a--; b--;
        G[a].push_back(edge(b, c));
        G[b].push_back(edge(a, c));
    }

    rep(start, N){
        priority_queue<ppa, vector<ppa>, greater<ppa>> que;
        rep(i, N)dist[start][i] = make_pair(2000000000, 2000000000);
        dist[start][start] = make_pair(0, 0);
        que.push(ppa(dist[start][start], start));
        while(!que.empty()){
            ppa now = que.top();
            que.pop();
            pa d = now.first;
            int v = now.second;
            if(d > dist[start][v])continue;
            for(edge e : G[v]){
                pa tmp;
                if(d.second + e.cost > L)tmp = pa(d.first + 1, e.cost);
                else tmp = pa(d.first, d.second + e.cost);
                if(chmin(dist[start][e.to], tmp)){
                    que.push(ppa(dist[start][e.to], e.to));
                }
            }
        }
    }

    cin >> Q;
    rep(i, Q){
        int s, t;
        cin >> s >> t;
        s--; t--;
        pa p = dist[s][t];
        if(p.first >= 2000000000)cout << -1 << endl;
        else cout << p.first << endl;
    }

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int n,a,b;
vector<int> h;
bool isenough(int t){
	long long int x=0;
	for(int i=0;i<n;i++){
		x+=(max(h[i]-b*t,0)/(a-b))+(max(h[i]-b*t,0)%(a-b)!=0);
		if(x>t)return false;
	}
	if(x>t)return false;
	else{
		return true;
	}
}
int main(){
	
	cin>>n>>a>>b;
	h.assign(n,0);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int mx=INT_MIN;
	for(int i=0;i<n;i++){
		mx=max(mx,h[i]);
	}
	int n=mx/b;
	int st=0;
	int end=n+1;
	while(st<end){
		int mid=st+(end-st)/2;
		if(isenough(mid)){
			end=mid;
		}
		else{
			st=mid+1;
		}

	}
	cout<<st<<endl;
}

Measured memory_bytes: 768
#include<stdio.h>
int main()
{
		int i,j,n,m,t,p,max=-1000000001,day[101][10],money[101][11],bit[10];
		scanf("%d",&n);
		for(i=0;i<n;i++)
			for(j=0;j<10;j++)
			scanf("%d",&day[i][j]);
		for(i=0;i<n;i++)	
			for(j=0;j<11;j++)
			scanf("%d",&money[i][j]);
	for(int i=1;i<1024;i++)
	{
		int t = i;
		int len = 0;
		for(int j=0;j<10;j++)
		{
			bit[len++] = t%2;
			t= t/2;
		}
		int m = 0;
		int sum = 0;
		for(t=0;t<n;t++)
		{
			m=0;
		for(p=0;p<10;p++)
		if(bit[p]==1&&day[t][p]==1)
		{
			m++;
		}
		sum+= money[t][m];
		}
		if(sum>max)
		max=sum;
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
import sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
  A,B,C=map(int, input().split() )
  a+=[A]
  b+=[B]
  c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
 
for n in range(N-1):
  for m in range(M):
    u=a[m]
    v=b[m]
    if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
      V[b[m]-1]=V[a[m]-1]+c[m]
 
moji2=[0]*N
for n in range(N):
  for m in range(M):
    u=a[m]
    v=b[m]
    if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
      V[b[m]-1]=V[a[m]-1]+c[m]
      moji2[b[m]-1]=1
      if moji2[N-1]:
        print("inf")
        sys.exit()
print(V[N-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int R,G;
    cin >>R>>G;
    cout << 2*G-R << endl;



}

Measured memory_bytes: 256
N = int(input())
prev = ''
dic = set()
for i in range(N):
    word = input()
    if word in dic:
        print("No")
        exit()
    else:
        dic.add(word)
        if i == 0:
            prev = word[-1]
            continue
        if prev != word[0]:
            print("No")
            exit()
        prev = word[-1]
print("Yes")

Measured memory_bytes: 38384
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)
    for _ in range(M):
        x, y, z = map(int, input().split())
        uf.union(x-1, y-1)

    for i in range(N):
        uf.find(i)
    # print(uf.par)
    s = set(uf.par)
    print(len(s))


if __name__ == '__main__':
    main()

Measured memory_bytes: 14784
#include <stdio.h>

using namespace std;

int main(){
    int C[10001];
    for(int i = 0; i < 10001; i++) C[i] = 0;
    int n;
    scanf("%d",&n);
    int* A = new int[n];
    int* B = new int[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
        C[A[i]]++;
    }

    for(int i = 0,j=0; i < 10001; i++){
        if(C[i] != 0){
            for(int k = 0; k < C[i]; k++){
                B[j++] = i;
            }
        }
    }

    for(int i = 0; i < n-1; i++) printf("%d ",B[i]);
    printf("%d\n",B[n-1]);
    delete[] A;
    delete[] B;
    return 0;
}

  

 





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

#define NMAX 51

long long dp[NMAX][NMAX][NMAX * NMAX];  // how many ways to take a subset of j items from the first i with sum k;
int v[NMAX];

int main()
{
    ios_base::sync_with_stdio(false);

    int n, A, all_sum = 0;
    // ifstream cin("code.in");
    cin >> n >> A;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        all_sum += v[i];
    }
    for (int i = 0; i <= n; i++)
        dp[i][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            for (int k = 1; k <= all_sum; k++) {
                dp[i][j][k] = dp[i - 1][j][k];
                if (k - v[i] >= 0) {
                    dp[i][j][k] += dp[i - 1][j - 1][k - v[i]];
                }
            }
        }
    }
    long long sol = 0;
    for (int j = 1; j <= n; j++) {
        if (A * j > all_sum)
            break;
        sol += dp[n][j][A * j];
    }
    cout << sol << '\n';
    return 0;
}


Measured memory_bytes: 51072
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int> A(N+1), S(N+1), X(N+1);
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
	}
	for (int i = 1; i <= N; ++i) {
		if (i == 1) {
			S[i] = A[i];
			X[i] = A[i];
		}
		else {
			S[i] = S[i - 1] + A[i];
			X[i] = X[i - 1] ^ A[i];
		}
	}
	int L = 1;
	int R = 1;
	int ter = A[1];
	LL ans = 1;
	while (R<N) {
		while (R < N && ter + A[R+1] == (ter ^ A[R+1]) ) {
			ter += A[R+1];
			++R;
			ans += R-L+1;//減っていく分
		}
		
		if (R == N) {
			break;
		}
		while (L <= R && ter+A[R+1] != (ter^A[R+1]) ) {
			ter -= A[L];
			++L;
		}
		if (L > R) {
			R = L;
			ter = A[L];
			++ans;
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 2560