akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string S;
    cin >> S;
    int N = S.size();
    ll ans = 0;
    for (int bit = 0; bit < (1 << N - 1); bit++) {
        ll tmp = 0;
        REP(i, N - 1) {
            tmp = tmp * 10 + (S[i] - '0');
            if ((bit >> N - 2 - i) & 1) {//i個目の「間」に+が入ったなら
                ans += tmp;
                tmp = 0;
            }
        }
        tmp = tmp * 10 + (S[N - 1] - '0');
        ans += tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const int MAXN = 305;

int n,m,MOD;

ll f[MAXN][MAXN];
ll g[MAXN][MAXN];

int main()
{
	scanf("%d%d%d",&n,&m,&MOD);
	for (int i = 0;i <= n;i++)
	{
		memset(f,0,sizeof(f));
		for (int j = 0;j <= n;j++)
			f[0][j] = 1;
		for (int j = 1;j <= i;j++)
			for (int k = 0;k <= n;k++)
			{
				f[j][k] = f[j - 1][k];
				if (k)
					(f[j][k] += f[j][k - 1] * (j + 1)) %= MOD;
			}
		for (int j = 0;j <= n;j++)
			if (i + j <= n)
				g[i][i + j] = f[i][j];
	}
	memset(f,0,sizeof(f));
	f[0][0] = 1;
	for (int i = 1;i <= m;i++)
		for (int j = 0;j <= n;j++)
			for (int k = 0;k <= j;k++)
				(f[i][j] += f[i - 1][k] * g[k][j]) %= MOD;
	printf("%lld\n",f[m][n]);
    return 0;
}

Measured memory_bytes: 1664
h,w=map(int,input().split())
l=[]
for i in range(h):
  l.append(input())
al=[]
for i in range(h):
  s=''
  for j in range(w):
    if l[i][j]=='#':
      s+='#'
      continue
    c=0
    if i>0 and j>0 and l[i-1][j-1]=='#':
      c+=1
    if i>0 and l[i-1][j]=='#':
      c+=1
    if i>0 and j<w-1 and l[i-1][j+1]=='#':
      c+=1
    if j>0 and l[i][j-1]=='#':
      c+=1
    if j<w-1 and l[i][j+1]=='#':
      c+=1
    if i<h-1 and j>0 and l[i+1][j-1]=='#':
      c+=1
    if i<h-1 and l[i+1][j]=='#':
      c+=1
    if i<h-1 and j<w-1 and l[i+1][j+1]=='#':
      c+=1
    s+=str(c)
  al.append(s)
for i in range(h):
  print(al[i])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,a[110],b[110],c[110],d[110],to[110],u[110],e[110][110],ans;
int dfs(int x)
{
    for(register int i=1;i<=n;i++)
        if(e[x][i] && !to[i])
        {
            to[i]=1;
            if(!u[i] || dfs(u[i]))
            {
                u[i]=x;
                return 1;
            }
        }
    return 0;
}
int main()
{
    scanf("%d",&n);
    for(register int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]);
    for(register int i=1;i<=n;i++)
        scanf("%d%d",&c[i],&d[i]);
    for(register int i=1;i<=n;i++)
        for(register int j=1;j<=n;j++)
            if(a[i]<c[j] && b[i]<d[j])
                e[i][j]=1;
    for(register int i=1;i<=n;i++)
    {
        memset(to,0,sizeof(to));
        ans+=dfs(i);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int answer,w,h;
char c[21][21];

void move(int x,int y){
    if(c[x][y]!='#'){
        answer++;
        c[x][y]='#';
        if(x-1>=0) move(x-1,y);
        if(x+1<h) move(x+1,y);
        if(y-1>=0) move(x,y-1);
        if(y+1<w) move(x,y+1);
    }
}

int main(){
    while(1){
        int x,y;
        answer=0;
        scanf("%d %d",&w,&h);
        if(w==0&&h==0) return 0;
        getchar();
        for(int i=0;i<h;i++){
            for(int j=0;j<=w;j++){
                scanf("%c",&c[i][j]);
                if(c[i][j]=='@'){
                    x=i;
                    y=j;
                }
            }
        }
        move(x,y);
        printf("%d\n",answer);
    }
}

Measured memory_bytes: 1040
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll dp[100010];
int main()
{
	int n,m;
	ll ans=0;
	cin>>n>>m;
	fill(dp,dp+100010,0);

	for(int i=0;i<m;i++)
	{
		int a;
		cin>>a;
		dp[a]=-999;
	}
	dp[0]=1;
	//ここからDP
	for(int i=0;i<n+1;i++)
	{
		if(dp[i]>0)
		{
			if(dp[i+1]>=0)
			{
				dp[i+1]+=dp[i]+MOD;
				dp[i+1]%=MOD;
			}
			if(dp[i+2]>=0)
			{
				dp[i+2]+=dp[i]+MOD;
				dp[i+2]%=MOD;
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int x;
  
  int b=1;
  int c=0;
  
  scanf("%d",&x);
  

  for(int i;i<=8;i++){
    c = c+ x/b%10;
    b=b*10;
  }
  if(x%c==0){
    printf("Yes\n");
    return 0;
  }

  printf("No\n");
  
  

  
  return 0;
}
  


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

int i;

int main()
{
    int n, ans, j = 0;
    cin >> n;
    vector<int> a(n);
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    while (j < n)
    {
        int cnst = a[j], count = 0;
        while (j < n && cnst == a[j])
        {
            j++, count++;
        }
        ans += count % 2;
    }

    cout << ans;
}

Measured memory_bytes: 640
n=int(raw_input())
a=[raw_input() for _ in xrange(n)]
cnt=0
for i in xrange(n):
    for j in xrange(n):
        if a[i][j]==".":
            cnt+=1
if cnt==n*n:
    print -1
    exit()

cnt=[0]*n
y=[False]*n
for i in xrange(n):
    for j in xrange(n):
        if a[i][j]==".":
            cnt[i]+=1
            y[i]=True
t=[False]*n
nokori=n
for j in xrange(n):
    tmp=0
    for i in xrange(n):
        if a[i][j]=="#":
            tmp+=1
    if tmp==n:
        nokori-=1
    if tmp!=0:
        t[j]=True

ans=9999999999
for i in xrange(n):
    if y[i]:
        if t[i]:
            ans=min(ans,cnt[i]+nokori)
        else:
            ans=min(ans,cnt[i]+nokori+1)
    else:
        ans=min(ans,nokori)
print ans

Measured memory_bytes: 2948
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pii pair<ll,ll>
#define sc(x) scanf("%lld",&x)

int main(){
	io;
	ll n,s=0,m;
	cin>>n>>m;
	ll val=4*m;
	vector<ll>v(n);
	for(ll i=0;i<n;i++){
		cin>>v[i];
		s+=v[i];
	}
	sort(v.rbegin(),v.rend());
	
	ll vote=ceil(((long double)s/(long double)val));
	ll i=0;
	while(i<n && v[i]>=vote){
		i++;
	}
	
	if(i>=m){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())

max_num = max(a,b,c)

if max_num*3 % 2 == (a+b+c) % 2:
    print((max_num*3-(a+b+c))//2)
else:
    print(((max_num+1)*3-(a+b+c))//2)


Measured memory_bytes: 61240
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define N 100010
#define LL long long
#define CK 1000000007
using namespace std;

int i,n;
LL Ans;
LL a[N],p[N],s[N],b[N];

inline void Ready(){
	int i=0;
	for (p[1]=1,i=2;i<=n;i++)	p[i]=((CK-CK/i)*p[CK%i])%CK;
}

inline void Work(){
	int i=0;
	for (i=1;i<=n;i++)	s[i]=(s[i-1]+p[i])%CK;
	for (i=1;i<=n;i++)	b[i]=(s[i]+s[n-i+1]-1)%CK;
	for (i=1;i<=n;i++)	Ans+=(a[i]*b[i])%CK;
	for (i=1;i<=n;i++)	Ans=(Ans*i)%CK;
	cout<<Ans<<endl;
}

int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++)	cin>>a[i];
	Ready();	Work();
	return 0;
}

Measured memory_bytes: 3328
#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() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int ans=0;
  for(int i=0; i<n-2; i++) {
    for(int j=i+1; j<n-1; j++) {
      for(int k=j+1; k<n; k++) {
        if(a[i]<a[j]+a[k]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math
def solve(numbers):
    s='#'
    for number in numbers:
        
        h=number[0]
        w=number[1]
        for i in range(h):
            string=s*w
            print(string)
        print()


def answer():
    numbers=[]

    while True:
        s = input().split()
        if s[0]=='0' and s[1]=='0':
            break
        numbers.append(list(map(int,s)))
       
    solve(numbers)


if __name__ =='__main__':
    answer()


Measured memory_bytes: 5688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define forn(i,n) for(ll i=0;i<ll(n);++i)
#define all(x) (x).begin(),(x).end()

class DisjointSets {
public:
    explicit DisjointSets(ll N) : id_(N) {
        forn(i, N) id_[i] = i;
    }

    void join(ll a, ll b) {
        if (a > b) swap(a, b);
        id_[id(b)] = id(a);
    }

    ll id(ll a) {
        if (id_[a] == a) return a;
        ll i = id(id_[a]);
        id_[a] = i;
        return i;
    }

private:
    vll id_;
};

int main() {
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vll p(N);
    forn(i, N) cin >> p[i], --p[i];
    DisjointSets uf(N);
    forn(i, M) {
        ll x, y;
        cin >> x >> y;
        --x, --y;
        uf.join(x, y);
    }
    ll ok = 0;
    forn(i, N) {
        ok += uf.id(p[i]) == uf.id(i);
    }
    cout << ok << '\n';
}

Measured memory_bytes: 1792
<?php
list($n, $m) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = strs();
$bb = '';
for ($i = 0; $i < $m; ++$i) {
    list($b[]) = strs();
    $bb .= $b[$i];
}
for ($i = 0; $i <= $n - $m; ++$i) {
    for ($j = 0; $j <= $n - $m; ++$j) {
        $aa = '';
        for ($k = 0; $k < $m; ++$k) $aa .= substr($a[$k + $i], $j, $m);
        if ($aa === $bb) exit('Yes');
    }
}
echo 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 4856
import collections
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 1

AA = collections.Counter(A)
cc = [0]*(max(A)+1)

for i in AA.keys():
    cc[i] = AA[i]

for i in range(len(cc)):
    ans =  max(ans, sum(cc[i:i+3]))

print(ans)

Measured memory_bytes: 14548
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
b = LI()

result = []
while True:
    #  print(b)
    for i in range(1, len(b)+1):
        #  print(i)
        if b[-i] == len(b)-i+1:
            #  print('break')
            result.append(b[-i])
            b.pop(-i)
            break
    else:
        if not b:
            break
        print(-1)
        exit()
for i in result[::-1]:
    print(i)



Measured memory_bytes: 66924
blue = []
red = []
ans = 0
n = int(input())
for i in range(n):
  blue.append(input())
m = int(input())
for j in range(m):
  red.append(input())
word = set(blue)
for k in word:
  c = blue.count(k) - red.count(k)
  ans = max(ans,c)
print(ans)

Measured memory_bytes: 9124
x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())),reverse = True)
q = sorted(list(map(int,input().split())),reverse = True)
r = sorted(list(map(int,input().split())),reverse = True)
pre = sorted(p[:x]+q[:y])
for i in range(min(x+y,c)):
  if pre[i] < r[i]:
    pre[i] = r[i]
  else:
    break
print(sum(pre))

Measured memory_bytes: 106980
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

vector<int>l[100010];

class UnionFind {
public:
	vector<int>par, rank, node;
	UnionFind(int n) :par(n), rank(n, 0),node(n,1) {
		for (int i = 0;i < n;i++) {
			par[i] = i;
			rank[i] = 0;
			node[i] = 1;
		}
	}

	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}

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

	void unite_tree(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	int root_size(int x){
		return rank[find(x)];
	}

	int size(int x) {
		return node[find(x)];
	}

	void unite_node(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (size(x) < size(y))swap(x, y);
		node[x] += node[y];
		par[y] = par[x];
	}
};

int main(void){
    int n,m,k,a;
    cin>>n>>m;
    UnionFind uf = UnionFind(n);
    for(int i=0;i<n;i++){
        cin>>k;
        for(int j=0;j<k;j++){
            cin>>a;
            l[a].push_back(i);
        }
    }
    for(int i=1;i<=m;i++){
        if((int)l[i].size()>1){
            for(int j=0;j<(int)l[i].size();j++){
                uf.unite_tree(l[i][0],l[i][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        if(!uf.same(0,i)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int f(int n) {
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

void solve() {
    int s;
    cin >> s;

    int idx = 1, ans;
    bool found = false;
    vector<int> a;
    a.push_back(s);
    while (true) {
        a.push_back(f(a[idx-1]));
    
        for (int i = 0; i < idx; i++) {
            if (a[i] == a[idx]) {
                ans = idx + 1;
                found = true;
            }
        }

        if (found) break;
        idx++;
    }

    cout << ans << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
_ = $stdin.gets
PX = $stdin.gets.chomp.split(" ").map(&:to_i).sort
PY = $stdin.gets.chomp.split(" ").map(&:to_i).sort
M = 1000000007

def msum(xs)
  i = 0
  r = 0
  while i < xs.size-1-i
    j = xs.size-1-i
    #$stderr.puts "(#{j} - #{i}) * #{(j-i)}"
    r = (r + (xs[j] - xs[i])*(j-i)) % M
    i += 1
  end
  r
end

puts ((msum(PX) % M) * (msum(PY) % M)) % M



Measured memory_bytes: 19304
#include <stdio.h>
#include <stdlib.h>

typedef struct vector2 {
  int x;
  int y;
}vector2;

int qcount;
vector2 *queue;
int qfirst = 0, qlast = 0;

void makeQueue(int count) {
  qcount = count;
  qfirst = qlast = count / 2;
  queue = malloc(count * sizeof(vector2));
}

void push_back(int x, int y) {
  vector2 v = { x, y };
  qlast %= qcount;
  queue[qlast++] = v;
}

void push_front(int x, int y) {
  vector2 v = { x, y };
  qfirst = (qfirst + qcount) % qcount;
  queue[--qfirst] = v;
}

vector2 dequeue(void) {
  qfirst %= qcount;
  vector2 v = queue[qfirst++];
  return v;
}

int main(void){
  int h, w;
  scanf("%d%d", &h, &w);
  int ch, cw;
  scanf("%d%d", &ch, &cw);
  ch++, cw++;
  int dh, dw;
  scanf("%d%d", &dh, &dw);
  dh++, dw++;
  makeQueue((h+4) * (w+4));
  char s[h+4][w+4];
  int d[h+4][w+4];
  
  // clear map
  for(int i = 0;i < h + 4;i++) {
    for(int j = 0;j < w + 4;j++) {
      d[i][j] = 0x7FFFFFFF;
      s[i][j] = 0;
    }
  }

  // read map
  for(int i = 2;i < h + 2;i++) {
    scanf("%s", &s[i][2]);
    for(int j = 2;j < w + 2;j++) {
      if(s[i][j] == '.') s[i][j] = 1;
      if(s[i][j] == '#') s[i][j] = 0;
    }
  }

  push_back(cw, ch);
  d[ch][cw] = 0;

  while(qfirst != qlast) {

    vector2 point = dequeue();
    int x = point.x, y = point.y;
    if(x == dw && y == dh) break;
    int data = d[y][x];

    // work
    int dx[] = { -1, 1, 0, 0 };
    int dy[] = { 0, 0, -1, 1 };
    for(int i = 0;i < 4;i++) {
      int sw = x + dx[i], sh = y + dy[i];
      int sd = d[sh][sw];
      // wall
      if(s[sh][sw] == 0) continue;

      if(sd > data) {
        d[sh][sw] = data;
        push_front(sw, sh);
      }
    }

    // warp
    for(int i = -2;i <= 2;i++) {
      for(int j = -2;j <= 2;j++) {
        int sw = x + j, sh = y + i;
        int sd = d[sh][sw];
        // wall
        if(s[sh][sw] == 0) { continue; }

        if(sd > data + 1) {
          d[sh][sw] = data + 1;
          push_back(sw, sh);
        }
      }
    }
    // printf("x: %d y: %d\n", x, y);
    // for(int i = 0;i < h + 4;i++) {
    //   for(int j = 0;j < w + 4;j++) {
    //     printf("%10d ", d[i][j]);
    //   }
    //   puts("");
    // }
  }
  if(d[dh][dw] == 0x7FFFFFFF) {
    puts("-1");
  } else {
    printf("%d\n", d[dh][dw]);
  }
  return 0;
}


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

using namespace std;

int main()
{
  string N;
  cin >> N;
  
  bool is_ok = false;

  do {
    for (auto it = N.begin(); it != N.end(); it++) {
      if (*it == '7') {
	is_ok = true;
	break;
      }
    }

  } while(0);

    
  if (is_ok == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void yes(){
  cout << "AC" << endl;
}

void no(){
  cout << "WA" << endl;
  exit(0);
}

int main() {
  string s; cin >> s;
  
  if(s[0] != 'A') no();

  ll c = -1;
  FOR(i,2,s.size()-1){
    if(s[i] == 'C') c = i;
  }
  if(c==-1) no();

  FOR(i, 1, s.size()){
    if(i!=c && (s[i] < 'a' || s[i] > 'z')) no(); 
  }
  yes();
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  double r = 0;
  int ret1 = 100*a, ret2 = 0;
  REP(i, 31) {
    if(i*a*100 > f) break;
    // cout << "a" << endl;
    REP(j, 31) {
      if(i*a*100 + j*b*100 > f) break;
      // cout << "b" << endl;
      REP(k, 3001) {
        if(i*a*100 + j*b*100 + k*c > f) break;
        // cout << "c" << endl;
        REP(l, 3001) {
          if(i*a*100 + j*b*100 + k*c + l*d > f) break;
          int water = i*a*100 + j*b*100, sugar = k*c+l*d;
          if(water + sugar <= f && water*e >= 100*sugar) {
            if(r <= (double)sugar/(sugar+water)) {
              // cout << water << " " << sugar << endl;
              ret1 = sugar;
              ret2 = sugar + water;
              r = (double)sugar/(sugar+water);
            }
          }
        }
      }
    }
  }
  cout << ret2 << " " << ret1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int a;cin>>a;
    rep(i,0,10001){
        int u=a-100*i;
        if(u<0)break;
        int e=5*i;
        if(e>=u){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
LL a[MAXN],n,m,b[MAXN];LL K;
LL p[MAXN],ans[MAXN],vis[MAXN];
LL ri[MAXN],tot;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=n;i>=1;i--)a[i]=a[i]-a[i-1];
	m=read();K=read();
	for(int i=1;i<=m;i++)b[i]=read();
	for(int i=1;i<=n;i++)p[i]=i;
	for(int i=1;i<=m;i++)swap(p[b[i]],p[b[i]+1]);
	for(int i=1;i<=n;i++)if(!vis[i])
	{
		tot=0;ri[++tot]=i;vis[i]=1;
		for(int j=p[i];j!=i;j=p[j])ri[++tot]=j,vis[j]=1;
		for(int j=1;j<=tot;j++)ans[ri[j]]=a[ri[(j+K%tot-1)%tot+1]];
	}
	for(int i=1;i<=n;i++)pr2(ans[i]+=ans[i-1]);
	return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] -= (i+1);
    }
    sort(a.begin(),a.end());
    long sum = 0;
    for(int i = 0; i < n; i++){
        sum += abs(a[i] - a[(n-1)/2]);
    }
    cout << sum;
}

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

int main(){
  int N,K,d;
  cin >> N >> K;
  int r = 0;
  vector<bool> A(K);
  for(int i = 0; i < K; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
      int a;
      cin >> a;
      if(!A[a]){
        A[a] = true;
        r += 1;
      }
    }
  }
  cout << N-r << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<vector<int> > graph;
vector<bool> seen;

void dfs(int v){
    if(seen[v]) return;
    seen[v] = true;
    for(auto sv : graph[v]){
        dfs(sv);
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    graph.resize(n);
    seen.resize(n);
    int z;
    rep(i,m){
        int a,b;
        cin >> a >> b >> z;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    ll cnt=0;
    for(int v=0;v<n;v++){
        if(seen[v]) continue;
        dfs(v);
        cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 8832
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    long long int x, y;
    cin>>x>>y;
    if(x>0&&y>0){
        long long int ans=abs(y-x);
        if(x>y) ans+=2;
        cout<<ans<<endl;
    }else if(x>0&&y<0){
        if(x!=abs(y)) cout<<abs(abs(y)-x)+1<<endl;
        if(x==abs(y)) cout<<1<<endl;
    }else if(x<0&&y>0){
        if(abs(x)!=y) cout<<abs(abs(x)-y)+1<<endl;
        if(abs(x)==y) cout<<1<<endl;
    }else if(x<0&&y<0){
        if(abs(x)>abs(y)){
            cout<<abs(x)-abs(y);
        }else if(abs(x)<abs(y)){
            cout<<2+abs(y)-abs(x);
        }else{
            cout<<0<<endl;
        }
    }else if(x==0&&y>0){
        cout<<y<<endl;
    }else if(x==0&&y<0){
        cout<<abs(y)+1<<endl;
    }else if(x>0&&y==0){
        cout<<x+1<<endl;
    }else if(x<0&&y==0){
        cout<<abs(x)<<endl;
    }else if(x==0&&y==0){
        cout<<0<<endl;
    }
}


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

int main() {
  ll ans=0,t1,t2,a1,a2,b1,b2,p,q,s,t;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  p=(a1-b1)*t1;
  q=(a2-b2)*t2;
  if(p>0) {
  	p*=-1; q*=-1;
  }
  if(p+q<0) puts("0");
  else if(p+q==0) puts("infinity");
  else{
  	s=-p/(p+q);
  	t=-p-(p+q)*s;
  	ans+=s*2;
  	if(t!=0) ans++;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
x = int(input())

if 400<=x and x<=599:
    print('8')
elif 600<=x and x<=799:
    print('7')
elif 800<=x and x<=999:
    print('6')
elif 1000<=x and x<=1199:
    print('5')
elif 1200<=x and x<=1399:
    print('4')
elif 1400<=x and x<=1599:
    print('3')
elif 1600<=x and x<=1799:
    print('2')
else:
    print('1')


Measured memory_bytes: 9180
h, w = map(int, input().split())
lis = []
num = [[0] * w for i in range(h)]
s = [str(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            lis.append([i,j])
            num[i][j] = 1
cnt = -1
while lis != []:
    cnt += 1
    tmp = []
    for x,y in lis:
        if x > 0:
            if num[x-1][y] == 0:
                num[x-1][y] = 1
                tmp.append([x-1,y])
        if x < h-1:
            if num[x+1][y] == 0:
                num[x+1][y] = 1
                tmp.append([x+1,y])
        if y > 0:
            if num[x][y-1] == 0:
                num[x][y-1] = 1
                tmp.append([x,y-1])
        if y < w-1:
            if num[x][y+1] == 0:
                num[x][y+1] = 1
                tmp.append([x,y+1])
    lis = tmp
print(cnt)

Measured memory_bytes: 146572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int N,M;
    cin>>N>>M;
    int dp[4096][1001];
    int INF = 1000000000;
    rep(i,1<<N)rep(j,M+1) dp[i][j] = INF;
    dp[0][0] = 0;
    int a,b,c;
    rep(j,M){
        cin>>a>>b;
        int hoge = 0;
        rep(k,b){
            cin>>c;
            c--;
            hoge = hoge | (1<<c);
        }
        rep(i,1<<N) dp[i][j+1] = dp[i][j];
        rep(i,1<<N) dp[(i|hoge)][j+1] = min(min(dp[(i|hoge)][j],dp[i][j]+a),dp[(i|hoge)][j+1]);
        
    }
    int ans = dp[(1<<N)-1][M];
    // rep(i,1<<N){
    //     rep(j,M+1) cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    if(ans == INF) ans = -1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		for(;;) {
			String line = br.readLine();
			if(line.equals("0")) {
				break;
			}
			int n = Integer.parseInt(line);
			String[] set = br.readLine().split(" ");
			int[] s = new int[n];
			double sum = 0;
			for(int i = 0; i < n; i++) {
				s[i] = Integer.parseInt(set[i]);
				sum += s[i];
			}
			double m = sum / n;
			double a = 0;
			for(int i = 0; i < n; i++) {
				 a += Math.pow(s[i] - m , 2);
			}

			double alpha = Math.sqrt(a / n);

			sb.append(alpha).append("\n");

		}
		System.out.print(sb);
	}
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  vector<bool> fg(N, false);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  sort( A.begin(), A.end() );
  
  deque<int> d;
  d.push_back(A.at(0));
  fg.at(0) = true;
  
  for( int i = 1; i < N; i+= 2 ){
    if( N-i > 0 && fg.at(N-i) == false ){
      fg.at(N-i) = true;
      d.push_front(A.at(N-i));
    }
    if( N-i-1 > 0 && fg.at(N-i-1) == false ){
      fg.at(N-i-1) = true;
      d.push_back(A.at(N-i-1));
    }
    if( fg.at(i) == false ){
      fg.at(i) = true;
      d.push_front(A.at(i));
    }
    if( i+1 < N && fg.at(i+1) == false ){
      fg.at(i+1) = true;
      d.push_back(A.at(i+1));
    }
  }
  
  reverse( A.begin(), A.end() );
  deque<int> d2;
  vector<bool> fg2(N, false);
  d2.push_back(A.at(0));
  fg2.at(0) = true;
  
  for( int i = 1; i < N; i+= 2 ){
    if( N-i > 0 && fg2.at(N-i) == false ){
      fg2.at(N-i) = true;
      d2.push_front(A.at(N-i));
    }
    if( N-i-1 > 0 && fg2.at(N-i-1) == false ){
      fg2.at(N-i-1) = true;
      d2.push_back(A.at(N-i-1));
    }
    if( fg2.at(i) == false ){
      fg2.at(i) = true;
      d2.push_front(A.at(i));
    }
    if( i+1 < N && fg2.at(i+1) == false ){
      fg2.at(i+1) = true;
      d2.push_back(A.at(i+1));
    }
  }

  
  
  
 
  int ans = 0;
  int ans2 = 0;
  for( int i = 1; i < N; i++ ){
    ans += abs( d.at(i) - d.at(i-1) );
    ans2 += abs( d2.at(i) - d2.at(i-1) );
  }
  cout << max(ans, ans2) << endl;
    
    
}

Measured memory_bytes: 2688
import itertools


S = list(input())
signs = [',+'] * 3 + [',-'] * 3
three_signs = list(itertools.permutations(signs, 3))
for i in three_signs:
    tmp = [_ for _ in S]
    for j in range(len(i)):
        tmp.insert(3-j, i[j])
    tmp = ''.join(tmp)
    tmp = tmp.split(',')
    temp = ''.join(tmp)
    tmp = map(int, tmp)
    ans = sum(tmp)
    if ans == 7:
        print(temp+'=7')
        exit()

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

int main(){

	int N;
	cin >> N;
	int V[N];
	int C[N];
	
	for(int i=0;i<N;i++)cin >> V[i];
	for(int i=0;i<N;i++)cin >> C[i];
	
	int ans=0;
	for(int i=0;i<N;i++){
		if(V[i]-C[i]>=0)ans+=V[i]-C[i];
	}
	
	cout << ans << endl;
	
}


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


int V, E, R, S[500010], T[500010], D[500010]; // 問題で与えられる入力
int C[100010]; // 各頂点までの最短距離の上限
// 無限を表す定数を全頂点をたどる最大超に設定
const int Inf = 10000*100000+100;

int main() {
  cin >> V >> E >> R;
  for (int i=0; i<E; i++){
    cin >> S[i] >> T[i] >> D[i]; // 各辺を入力
  }
  for (int i = 0; i < 100010; i++) C[i] = Inf;
  C[R] = 0;

    for (int t=0; t<V; t++) { // V回繰り返す
      bool update = false;
      for (int i=0; i<E; ++i) {
        int s = S[i], t = T[i], d = D[i]; // i番目の辺のs,t,dに対して
          if (C[s] < Inf && C[t] > C[s] + d) { // 辺s,tで緩和できるなら
          C[t] = C[s] + d;// C[t]を更新;
          update = true; // 更新が起こったことを記録
          }
        }
        if (!update) break;
    }

    for (int i = 0; i < V; i++){
      if (C[i] == Inf){
        cout << "INF" << endl;
      }else{
        cout << C[i] << endl;
      }
    }
    return 0;
  }



Measured memory_bytes: 9208
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 35000
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll pre[200000+10];
ll suf[200000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll a,b,c,d,e,f,x,y,k,t,A=0,mod,B=0,L,j,i,l,r,m,n,C=0,ans=0,sum=0,sum1=0;
    vector<ll>v,v1;
    queue<ll>qu;
    cin>>n;
    pre[0]=0;
    for(i=1;i<=n;i++)
    {
        cin>>aarray[i];
        pre[i]=pre[i-1]^aarray[i];
    }
    suf[n+1]=0;
    suf[n]=aarray[n];
    for(i=n-1;i>=1;i--)
    {
        suf[i]=suf[i+1]^aarray[i];
    }
    for(i=1;i<=n;i++)
    {
        cout<<(pre[i-1]^suf[i+1])<<" ";
    }

   cout<<endl;
    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>


using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> vt(N,-1);
    bool flag=true;
    for(int i=0; i<M; i++){
        int s,c;
        cin >> s >> c;
        if(vt[s-1]==-1) vt[s-1]=c;
        else if(vt[s-1]!=c){
            flag=false;
        }
    }

    if(vt[0]==0 && N!=1) flag=false;

    if(N==1 && flag==true && M!=0) cout << vt[0] << endl;
    else if(N==1 && flag==true) cout << 0 << endl;
    else if(flag){
        for(int i=0; i<N; i++){
            if(vt[i]==-1 && i==0) cout << 1;
            else if(vt[i]==-1) cout << 0;
            else{
                cout << vt[i];
            }
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }


    return 0;
}

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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> H(n);
  for (auto &h : H) cin >> h;
  sort(H.begin(), H.end());
  int res = 1e9;
  for (int i = 0; i+k-1<n ; ++i) {
    res = min(res, H[i+k-1]-H[i]);
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 640
S = list(input())
cnt = 0
flag = True
ans = "NO"
for i in range(len(S)-1):
    for j in range(i+1, len(S)):
        S_copy = S.copy()
        del S_copy[i+1:j]
        #print(S_copy)
        if "".join(S_copy)=="keyence":
            ans = "YES"
print(ans)

Measured memory_bytes: 3060
n, k = map(int, input().split())
s = str(input()).upper()
if 1 <= n <= 50 and 1 <= k <= n == len(s):
    chibi = s[k-1].lower()
    moji = list(s)
    moji[k-1] = chibi
    print("".join(moji))
else:
    print('Invalid value')

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

int main(){
	int i,j;
	int n,m; //??\?????°
	int tarou_num[100],hanako_num[100]; //??????????????°
	int tarou_sum,hanako_sum; //????????????????¨?
	int s,t;
	while(1){
		cin >> n >> m;
		tarou_sum=0; 
		hanako_sum=0;
		s=0;
		t=0;
		if(n==0 && m==0){
			break;
		}
		for(i = 0 ; i < n ; i++){
			cin >> tarou_num[i];
			tarou_sum+=tarou_num[i];
		}
		for(i = 0 ; i < m ; i++){
			cin >> hanako_num[i];
			hanako_sum+=hanako_num[i];
		}
		for(i = 0 ; i < n ; i++){
			for(j = 0 ; j < m ; j++){
				if(tarou_sum-tarou_num[i]+hanako_num[j]==hanako_sum+tarou_num[i]-hanako_num[j]){
					t=tarou_num[i];
					s=hanako_num[j];
					i=200;
					break;
				}
			}
		}
		if(t==0&&s==0){
			cout << -1 << endl;
		}else{
			cout << t << " " << s << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<long long>X(N);
    rep(i,N)cin >> X[i];
    long long ans = INF;
    rep(y,101){
        ll nx=0;
        rep(i,N){
            nx+=(X[i]-y)*(X[i]-y);
        }
        ans=min(ans,nx);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
lists=list(map(int,input().split()))
from collections import Counter
a=dict(Counter(lists))
if len(a)==1:
    if n>=lists[0]*2 or lists[0]==n-1:
        print("Yes")
    else:
        print("No")
    
elif len(a)==2:
    P=list(a.keys())
    Q=list(a.values())
    x,y=min(P),max(P) #x=k+l-1,y=k+l
    c,d=a[x],a[y]#c=k,d=?
    if 2*y-c<=n and c>0 and y>c and y-x==1:
        print("Yes")
    else:
        print("No")

    
else:
    print("No")

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

bool mm(string s){
  return("01" <= s && s <= "12");
}
int main(){
  string s; cin >> s;
  string s1 = s.substr(0, 2), s2 = s.substr(2, 2);
  if(mm(s1)){
    if(mm(s2)) cout << "AMBIGUOUS";
    else cout << "MMYY";
  }
  else{
    if(mm(s2)) cout << "YYMM";
    else cout << "NA";
  }
  cout << endl;


}


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

using namespace std;
typedef long long ll;


int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    ll ceil_a = (a + x - 1) / x;
    ll floor_b = b / x;
    cout << max(0LL, floor_b - ceil_a + 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int l[60];
  int n,k,ans=0;cin>>n>>k;
  for(int i=0;i<n;i++)cin>>l[i];
  sort(l,l+n,greater<int>());
  for(int j=0;j<k;j++){
    ans+=l[j];
  }
  cout<<ans;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int ans = 0;
  for(auto i=0;i<3;++i){
    if(s.at(i)==t.at(i))
      ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define _CRT_SECURE_NO_DEPRECATE
#define ii pair<int, int>
#define vii vector<ii>
#define vi vector<int>
const int N = 200005;
const int Q = 1 << 21;
const ll mod =  10e9+7;
using namespace std;
#define INF 1000000000
int n,m;
ll arr[N];
vector<ll> v[N];
struct UnionFind{
    int parent[N],rank[N];

    UnionFind(int n){
        int i;
        for(int i=0;i<n;i++) {parent[i] = i; rank[i] = 1;}
    }

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

    void connect(int x, int y){
        int rx=root(x),ry=root(y);
        if(rx == ry) return;
        if(rank[rx] > rank[ry]) {parent[ry] = rx; rank[rx] += rank[ry];}
        if(rank[rx] <= rank[ry]) {parent[rx] = ry; rank[ry] += rank[rx];}
    }
};


int main(){
 ios_base::sync_with_stdio(false);
	    cin.tie(NULL);


    cin >> n>>m;
    UnionFind uf(n);

    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<m;i++)
    {
    	int a,b;
    	cin>>a>>b;
    	uf.connect(a,b);
	}

	for(int i=0;i<n;i++)
	v[uf.root(i)].emplace_back(arr[i]);
	ll ans=0,cnt=0;
	vector<ll> v1;
	for(int i=0;i<n;i++)
	{
		if(v[i].empty())
		continue;
		cnt++;
		sort(v[i].begin(),v[i].end());
		ans+=v[i][0];
		for(int j=1;j<v[i].size();j++)
		v1.emplace_back(v[i][j]);
	}
	if(cnt==1)
	{
		cout<<0;
		return 0;
	}
	sort(v1.begin(),v1.end());
	for(int i=0;i<2*(n-m-1)-cnt;i++)
	{
	if(v1.size()<=i)
	{
		cout<<"Impossible";
		return 0;
	}
	ans+=v1[i];
}
	cout<<ans;

  return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
char f[101][101];
int a[101][101];
int n,m;
int main()
{
    cin>>n>>m;
    int i,j;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
    {
    	cin>>f[i][j];
    	if(f[i][j]=='#')
    	{
    		a[i-1][j-1]++;
            a[i-1][j]++;
            a[i-1][j+1]++;
            a[i][j-1]++;
            a[i][j+1]++;
            a[i+1][j-1]++;
            a[i+1][j]++;
            a[i+1][j+1]++;
    	}
    }
    for(i=1;i<=n;i++)
    {
    	for(j=1;j<=m;j++)
        if(f[i][j]=='#')
        cout<<'#';
        else cout<<a[i][j];
        cout<<endl;
    }
    return 0;
}


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


int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x;
	cin >> x;
	x >= 30 ? cout << "Yes" : cout << "No";
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n);
	ll cnt[200007] = {};
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i]--;
		cnt[a[i]]++;
	}
	
	ll ans = 0;
	for(int i = 0; i < n; ++i) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	
	for(int i = 0; i < n; ++i) {
		int x = a[i];
		ans -= cnt[x] * (cnt[x] - 1) / 2;
		ans += (cnt[x] - 1) * (cnt[x] - 2) / 2;
		cout << ans << endl;
		ans -= (cnt[x] - 1) * (cnt[x] - 2) / 2;
		ans += cnt[x] * (cnt[x] - 1) / 2;
	}

	return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		if (R < 1200) {
        	System.out.println("ABC");
        } else if (R < 2800) {
        	System.out.println("ARC");
        } else {
        	System.out.println("AGC");
        }
	}
}

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

signed main()
{
	int a[10];
	cin>>a[1]>>a[2]>>a[3]>>a[4];
	sort(a+1,a+4+1);
	if(a[1]==1&&a[2]==4&&a[3]==7&&a[4]==9){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    //freopen("test.txt","r",stdin);
double n;
cin>>n;
    double x=ceil(n/1000);
    printf("%.0lf\n",x*1000-n);
    return 0;
}



Measured memory_bytes: 3804
#include <iostream>
#define int long long
using namespace std;

int n, d1, x;
double dp[200001];	//dp[n] = (N=n, d1=1, x=0)のときの答え
double dp2[200001];	//dp2[n] = (N=n, d1=0, x=1)のときの答え

signed main() {
	int i, j;
	
	cin >> n >> d1 >> x;
	
	double dpSum = 0;
	for (i = 1; i <= n; i++) {
		dp[i] = 2 * dpSum;
		dp[i] /= i;
		dp[i] += (i - 1) * 0.5 + 1;
		dpSum += dp[i];
	}
	
	double dp2Sum = 0;		//dp2Sum = dp2[0] + dp2[1] + … + dp2[i - 1];
	double rdp = 0;			//rdp = 2 * dp[i - 1] + 4 * dp[i - 2] + … + 2 * i * dp[0];
	dpSum = 0;				//dp[0] + … + dp[i - 1]
	for (i = 1; i <= n; i++) {
		dpSum += dp[i - 1];
		rdp += 2 * dpSum;
		
		double miku = (2 * i - 1) * i * (i + 1) * 0.25;
		
		dp2[i] = 2 * dp2Sum + rdp + miku;
		dp2[i] /= i;
		dp2Sum += dp2[i];
	}
	
	printf("%.14f\n", d1 * dp[n] + x * dp2[n]);
	return 0;
}

//d1 * (d1=1, x=0の解) + x1 * (d1=0, x=1の解)が答え。d1=1, x=0が本質。
//設定が複雑なので逆再生してみる。ここで、最後に動かすボールiに注目すると、dp[n] = (N=n,d1=1,x=0)の解
//として、dp[0]～dp[N]をO(N^2)で計算できることが分かる。また、累積和をもっておくことでO(N)に改善できる。
//また、dp2[n] = (N=n, d1=0, x=1)の解とすると、最後に動かすボールiに注目し解の線形性を用いることでdp, dp2を用いた漸化式が立つ。
//↑ただし、立式にはかなりの注意力が必要。全体計算量はO(N)。
//
//この問題、思いついてしまえば大したことがないけど、外れの方針を引いたときに考え続けてしまうと一生解けないので、
//「外れの方針を引いたと思ったら拾える情報を拾ってさっさと他をあたる」というのが大事になってきそう。あと、リラックスしてないと
//線形性パートに気付くのは難しいので、ちゃんと寝て疲れを取ってください。

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		//スキャナーを宣言する
	    Scanner sc = new Scanner(System.in);

	    //入力を受け取る
	    int r = Integer.parseInt(sc.next());
	    int g = Integer.parseInt(sc.next());
	    int b = Integer.parseInt(sc.next());

	    //スキャナーを閉じる
	    sc.close();

	    //入力値を数字に直す
	    int num = (r * 100) + (g * 10) + b;

	    //もしnumが4で割り切れる(4の倍数)ならば
	    if(num % 4 == 0) {
	    	System.out.print("YES");
	    }
	    else {
	    	System.out.println("NO");
	    }

	}


}

Measured memory_bytes: 21972
n, d = map(int, input().split())
a = [[int(i) for i in input().split()] for i in range(n)]
ans = 0
def dis(x,y):
    T = []
    for i in range(len(x)):
        T.append((x[i]-y[i])**2)
    return sum(T)
for i in range(n):
    for j in range(i+1,n):
        r = dis(a[i], a[j])
        for k in range(r + 1):
            if k ** 2 == r:
                ans += 1
print(ans)

Measured memory_bytes: 3064