akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n, m, s, t, u, v, a, b, mem;
vector<pair<int, pair<int, int>>>g[100000];
pair<ll, bool>djy[100000], djs[100000];
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>ynque, skque;
stack<ll>ans;
ll mn;

int dijyen(int x) {
	lp(g[x].size()) {
		if (!djy[g[x][i].first].second) {
			ynque.push(make_pair(djy[x].first + g[x][i].second.first, g[x][i].first));
		}
	}
	while ( !ynque.empty()&&djy[ynque.top().second].second) {
		ynque.pop();
	}
	if (ynque.empty())return 0;
	mem = ynque.top().second;
	djy[mem] = make_pair(ynque.top().first, true);
	ynque.pop();
	dijyen(mem);
	return 0;
}

int dijsnk(int x) {
	lp(g[x].size()) {
		if (!djs[g[x][i].first].second) {
			skque.push(make_pair(djs[x].first + g[x][i].second.second, g[x][i].first));
		}
	}
	while (!skque.empty() && djs[skque.top().second].second)
		skque.pop();
	if (skque.empty())return 0;
	mem = skque.top().second;
	djs[mem] = make_pair(skque.top().first, true);
	skque.pop();
	dijsnk(mem);
	return 0;
}


int main() {
	cin >> n >> m >> s >> t;
	lp(m) {
		cin >> u >> v >> a >> b;
		g[u - 1].push_back(make_pair(v - 1, make_pair(a, b)));
		g[v - 1].push_back(make_pair(u - 1, make_pair(a, b)));
	}
	lp(n)
		djy[i] = djs[i] = make_pair(intmax, false);
	djy[s - 1] = make_pair(0, true);
	dijyen(s - 1);
	djs[t - 1] = make_pair(0, true);
	dijsnk(t - 1);
	mn = llmax;
	for (int i = n - 1; i >= 0; i--) {
		mn = min(djy[i].first + djs[i].first, mn);
		ans.push(mn);
	}
	lp(n) {
		cout << 1000000000000000 - ans.top() << endl;
		ans.pop();
	}
	return 0;
}

Measured memory_bytes: 19572
import java.util.*;

class Main {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        for (int i=0;i<a;i++){
            int b = sc.nextInt();
            list.add(b);
        }
            
        //System.out.println(list);
        
        int x = list.remove(0);
        int y;
        int z;
        for (int i=0;list.size()>0;i++){
            y = list.remove(0);
            x = saidaiKoyaku(x,y);
        }
        System.out.println(x);


    }
    
    static private int saidaiKoyaku(int x, int y){
        if (y==0){
            return x;
        }
        return saidaiKoyaku(y, x % y);
    }
}

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

int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	long long MIN = min({ A,B,C,D,E });
	cout << (N + MIN - 1) / MIN + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int n, m, dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
bool arr[1000][1000];
int dist[1000][1000];
queue<pair<int, int> > q;
int main()
{
  cin >> n >> m;
  for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
  {
    dist[i][j] = 0;
  	char c;
    cin >> c;
    if(c=='#')
    {
      arr[i][j] = 0;
      dist[i][j] = 0;
      q.push(make_pair(i, j));
    }
    else arr[i][j] = 1;
  }
  while(!q.empty())
  {
    // do bfs
    pair<int, int> p = q.front();
    q.pop();
    for(int i = 0; i < 4; i++)
    {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(0 <= nx && nx < n && 0 <= ny && ny < m)
      {
      	if(arr[nx][ny])
        {
          arr[nx][ny]=0;
          dist[nx][ny] = dist[p.first][p.second] + 1;
          q.push(make_pair(nx, ny));
        }
      }
    }
  }
  int md = 0;
  for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
  {
    md = max(dist[i][j], md);
  }
  cout << md << endl;
}


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

using namespace std;

int main()
{
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int a1 = (x * a + y * b);
	int a2 = max(x, y) * c * 2;
	int a3 = (min(x, y) * c * 2);
	if (x > y)
		a3 += (x - y) * a;
	else
		a3 += (y - x) * b;
	int ans = min(a1, a2);
	ans = min(ans, a3);
	cout << ans;
 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define sd(x) scanf("%d",&x)
#define sdl(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define pdl(x) printf("%lld\n",x)
#define MAXN 200009
using namespace std;
pll a[MAXN];
ll suf[MAXN],pre[MAXN],suf_max[MAXN],pre_max[MAXN];
int main()
{
	ll n;
	sdl(n);
	ll c;
	sdl(c);
	for(int i=1;i<=n;i++)
	{
		sdl(a[i].first);
		sdl(a[i].second);
	}
	a[0].first=a[0].second=0;
	pre[0]=0;
	ll fans=0;
	for(int i=1;i<=n;i++)
	{
		pre[i]=pre[i-1]+(a[i].second)-(a[i].first-a[i-1].first);
		fans=max(fans,pre[i]);
	}
	a[n+1]=mk(c,0);
	suf[n+1]=0;
	for(int i=n;i>=1;i--)
	{
		suf[i]=suf[i+1]+(a[i].second)-(-a[i].first+a[i+1].first);
		fans=max(fans,suf[i]);
	}
	suf_max[n+1]=0;
	for(int i=n;i>=1;i--)
	{
		suf_max[i]=max(suf_max[i+1],suf[i]);
	}
	pre_max[0]=0;
	for(int i=1;i<=n;i++)
	{
		pre_max[i]=max(pre_max[i-1],pre[i]);
	}
	for(int i=1;i<n;i++)
	{
		fans=max(fans,pre[i]-a[i].first+suf_max[i+1]);
	}
	for(int i=n;i>1;i--)
	{
		fans=max(fans,suf[i]-(c-a[i].first)+pre_max[i-1]);
	}
	pdl(fans);
	return 0;
}

Measured memory_bytes: 7680
M = int(input())
T = input()
ans = 0
for l in range(M):
    i, j = 1, 0
    S = T[l:]
    N = M-l
    Z = [0]*N
    Z[0] = N
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k+Z[k] < j:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    for i in range(N):
        ans = max(ans, min(i, Z[i]))

print(ans)


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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 110;

bool vis[N][100100];
ll n,W,w[N],v[N];
ll mem[N][100100],inf=2e18;

ll dp(int i,int rem)
{
    if( rem < 0 )
        return -inf;
    if( i == n+1 )
        return 0;

    ll &ret = mem[i][rem];
    if( vis[i][rem] )
        return ret;
    vis[i][rem] = 1;

    return ret = max( dp(i+1,rem) , dp(i+1,rem-w[i]) + v[i] );
}

int main()
{
    scanf("%lld%lld",&n,&W);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&w[i],&v[i]);

    printf("%lld\n",dp(1,W));
}


Measured memory_bytes: 85040
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

let readInt () = stdin.ReadLine() |> int

()
|> readIntArray
|> fun [| n; x |] ->
    [| 1 .. n |]
    |> Array.map (fun _ -> () |> readInt)
    |> fun y ->
        let rest = y |> Array.sum |> (-) x
        y
        |> Array.min
        |> (/) rest
        |> (+)
        <| Array.length y
    |> printfn "%d"


Measured memory_bytes: 30148
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    N,M = map(int,input().split())
    ad = [[] for i in range(N)]
    for _ in range(M):
        x,y = map(int,input().split())
        x -= 1; y -= 1
        ad[x].append(y)

    dp = [-1]*N

    def rec(nodes):
        if dp[nodes] != -1:
            return dp[nodes]
        res = 0
        for ne in ad[nodes]:
            option = rec(ne)+1
            if res < option:
                res = option
        dp[nodes] = res
        return dp[nodes]

    ans = 0
    for i in range(N):
        res = rec(i)
        if ans < res:
            ans = res
    print(ans)
    
main()

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

int main() {
  #define int long long
  int k, s;
  cin >> k >> s;
  int res = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (s - i - j >= 0 && s - i - j <= k) {
        res++;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var d = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < d; i++)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            var map = new int[n, n];
            for (int j = 0; j < n; j++) map[j, 0] = 1;
            writeSharp(map, n - 1, 2, 0, n , 0, 0);
            if (i > 0) Console.WriteLine();
            display(map);
        }
    }
    public static void display (int[,] map)
    {
        var n = map.GetLength(0);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                if (map[i, j] == 0)
                    if (j == n - 1) Console.WriteLine(" ");
                    else Console.Write(" ");
                else
                    if (j == n - 1) Console.WriteLine("#");
                else Console.Write("#");
            }
    }
    public static void writeSharp(int[,] map, int bn, int bt, int ud, int n, int x, int y)
    {
        var a = map.GetLength(0);
        if (a % 2 == 0 && bn == 1 && bt == 1) return;
        if (a % 2 == 1 && bn == 0 && bt == 2) return;
        map[x, y] = 1;
        n--;
        if (n == 0)
        {
            bt--;
            if (bt == 0) { bn -= 2; bt = 2; }
            ud++; if (ud > 3) ud = 0;
            if (ud == 0) y++;
            else if (ud == 1) x++;
            else if (ud == 2) y--;
            else x--;
            n = bn;
        }
        else
        {
            if (ud == 0) y++;
            else if (ud == 1) x++;
            else if (ud == 2) y--;
            else x--;
        }
        writeSharp(map, bn, bt, ud, n, x, y);
    }
}

Measured memory_bytes: 9512
#include <cstdio>
#include <algorithm>

using namespace std;

int a[11];

int main(void) {
  for (int i = 0; i < 5; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + 5);
  int res = 114514;
  do {
    int t = 0;
    for (int i = 0; i < 5; i++) {
      t += (10 - t % 10) % 10;
      t += a[i];
    }
    res = min(res, t);
  } while (next_permutation(a, a + 5));
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n,ans[100005],idx=1,par[100005],jarak[100005],akhir;
bool utama[100005];
vector <int> node[100005],mainpath;
int terjauh(int s){
	int ret;
	queue<int> cari;
	for(int i=1;i<=n;i++)
		jarak[i]=-1;
	par[s]=-1;
	jarak[s]=0;
	cari.push(s);
	while(!cari.empty())
	{
		int u=cari.front();
		cari.pop();
		ret=u;
		for(auto v:node[u])
		{
			if(jarak[v]==-1)
			{
				jarak[v]=jarak[u]+1;
				par[v]=u;
				cari.push(v);
			}
		}
	}
	return ret;
}
void tandaiutama(){
	int temp=terjauh(terjauh(1));
	akhir=temp;
	while(temp!=-1)
	{
		mainpath.pb(temp);
		utama[temp]=true;
		temp=par[temp];
	}
}
bool caterpillar(){
	for(int i=1;i<=n;i++)
	{
		if(!utama[i])
		{
			if(!utama[par[i]])
				return false;
		}
		
	}
	return true;
}
int main()
{
	scan(n);
	for(int i=1;i<=n-1;i++)
	{
		int u,v;
		scan(u,v);
		node[u].pb(v);
		node[v].pb(u);
	}
	tandaiutama();
	if(!caterpillar())
	{
		printf("-1\n");
	}
	else
	{
		int l=0,r=mainpath.size()-1;
		bool putar=false;
		for(int ulang=0;ulang<mainpath.size();ulang++,l++,r--)
		{
			if(node[mainpath[l]].size()==node[mainpath[r]].size())
				continue;
			putar=(node[mainpath[l]].size()>node[mainpath[r]].size());
			break;
		}
		if(putar)
			reverse(all(mainpath));
		
		idx=1;
		for(auto now:mainpath)
		{
			ans[idx]=idx;
			idx++;
			for(auto v:node[now])
			{
				if(utama[v])
					continue;
				ans[idx]=ans[idx-1];
				ans[idx-1]=idx;
				idx++;
			}
		}
		
		for(int i=1;i<=n;i++)
		{
			printf("%d",ans[i]);
			if(i==n)
				printf("\n");
			else
				printf(" ");
		}
	}
}

Measured memory_bytes: 8312
#include<cstdio>
#include<string>
using namespace std;

int P[10010];
void init(int N){
  for(int i=0;i<N;i++){
    P[i]=i;
  }
}
int root(int a){
  if(P[a]==a) return a;
  return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
  return root(a)==root(b);
}
void unite(int a,int b){
  P[root(a)]=root(b);
}

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  init(n);
  for(int i=0;i<q;i++){
    int com;
    int x;
    int y;
    scanf("%d %d %d",&com,&x,&y);
    if(com){
      if(is_same_set(x,y)){
	printf("1\n");
      }else{
	printf("0\n");
      }
    }else{
      unite(x,y);
    }
  }
  return 0;
}
	      
		    

Measured memory_bytes: 2748
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	int n;
	scanf("%d",&n);
	bool f=true;
	for(int i=0,x;i<n;i++) {
		scanf("%d",&x);
		if(x&1) continue;
		if(x%3&&x%5) f=false;
	}
	printf("%s\n",f?"APPROVED":"DENIED");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <cmath>
#include <utility>
#include <string>

using namespace std;

int main(){

    int N = 0;
    cin >> N;

    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        if(s == "Y"){
            cout << "Four";
            return 0;
        }
    }
    //cout << hina[0];
    cout << "Three";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
using ll = long long;


int main(void)
{
  ll n,m,l;
  cin >> n >> m >> l;
  ll dist[301][301];
  REP(i,301) REP(j,301) dist[i][j]=l+1;
  REP(i,m) {
    ll a,b,c;
    cin >> a >> b >> c;
    dist[a][b]=c;
    dist[b][a]=c;
  }
  REP(k,n+1)REP(i,n+1)REP(j,n+1)
    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
  REP(i,n+1)REP(j,n+1)
    if(dist[i][j]<=l) dist[i][j]=1;
    else dist[i][j]=n;
  REP(k,n+1)REP(i,n+1)REP(j,n+1)
    dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
  ll q;
  cin >> q;
  REP(i,q) {
    ll s,t;
    cin >> s >> t;
    ll answer = dist[s][t];
    if(answer>=n) answer = 0;
    cout << answer-1 << endl;
  }
  return 0;
}



Measured memory_bytes: 1280
import time
import random

start_time = time.time()

def calc(d, q):
    select_rand = select.copy()
    select_rand[d] = q
    last = [0] * 26
    satisfied_rand = 0
    for i in range(1, D+1):
        t = select_rand[i-1]
        satisfied_rand += s[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            satisfied_rand -= c[j] * (i-last[j])
    return (satisfied_rand, select_rand)

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [0] * 26
select = []
satisfied = 0
for i in range(1, D+1):
    last_d = [c[j]*(i-last[j]) for j in range(26)]
    last_d_sum = sum(last_d)
    #選択肢A 満足度の高いものから選ぶ
    s_d = s[i-1]
    maxindexA = max(enumerate(s_d), key = lambda x:x[1])[0]
    satis_optA = s_d[maxindexA] - last_d_sum + last_d[maxindexA]
    
    #選択肢B コストが大きいものから選ぶ
    last_d = [c[j]*(i-last[j]) for j in range(26)]
    maxindexB = max(enumerate(last_d), key = lambda x:x[1])[0]
    satis_optB = s_d[maxindexB] -last_d_sum + last_d[maxindexB]

    if satis_optA >= satis_optB:
        #Aを選択
        select.append(maxindexA+1)
        satisfied += satis_optA
        last[maxindexA] = i
    else:
        #Bを選択
        select.append(maxindexB+1)
        satisfied += satis_optB
        last[maxindexB] = i

while time.time() - start_time < 1.8:
    d = random.randint(0, D-1)
    q = random.randint(1, 26)
    result = calc(d, q)
    if satisfied < result[0]:
        select = result[1]

for i in range(D):
    print(select[i])


Measured memory_bytes: 83472
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a1 = Integer.parseInt(sc.next());
        int a2 = Integer.parseInt(sc.next());
        int a3 = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = 22 <= a1 + a2 + a3;
        String result = judge ? "bust" : "win";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#!/usr/bin/ python3.8
# K   : 青
# N-K : 赤

MOD=10**9+7
M=10**6
fac=[1]*M
ifac=[1]*M
inv=[1]*M
for i in range(2,M):
    fac[i]=i*fac[i-1]%MOD
    inv[i]=MOD-(MOD//i)*inv[MOD%i]%MOD
    ifac[i]=inv[i]*ifac[i-1]%MOD

def comb(n,k):
    if n<0 or n-k<0 or k<0:
        return 0
    return fac[n]*ifac[n-k]%MOD*ifac[k]%MOD

N,K=map(int,input().split())
R=N-K

for i in range(1,K+1):
    ans=comb((K-i)+i-1,(K-i))*comb((R-(i-1))+i,i)%MOD
    print(ans)

Measured memory_bytes: 127780
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#define INF 99999999
using namespace std;
typedef pair <int,int> P;
int sx,sy;  
int H,W,N;
int ans=0,g=0;
char S[1010][1010];
int gx,gy;
int d[1010][1010];
int dx[4] = {0,1,0,-1},dy[4] = {1,0,-1,0};
int bfs();
int main(){
  cin >> H >> W >> N;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> S[i][j];
      if(S[i][j] == 'S'){
	sx = i;
	sy = j;
      }
    }
  }
  for(int i=0;i<N;i++){
    int res = bfs();
    ans += res;
    g++;
  }
  cout << ans <<  endl;
}
int bfs(){
  queue <P> qu;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      d[i][j] = INF;
      if(S[i][j] == '1' + g){
	gx = i;
	gy = j;
      }
    }
  }
  qu.push(P(sx,sy));
  d[sx][sy] = 0;
  while(!qu.empty()){
    P p = qu.front();
    qu.pop();
    if(p.first == gx && p.second == gy)break;
    for(int i=0;i<4;i++){
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if(0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] != 'X' && d[nx][ny] == INF){
	qu.push(P(nx,ny));
	d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  sx = gx;
  sy = gy;
  return d[gx][gy];
}

Measured memory_bytes: 6192
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<string,int> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;
int a[2][100001];

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


Measured memory_bytes: 256
// tested by Hightail: https://github.com/dj3500/hightail
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int a[200200];

int main () {
   wez(n)
   FOR(i,n) {
      scanf("%d", a+i);
   }
   vi v(a,a+n);
   sort(ALL(v));
   FOR(i,n) {
     printf("%d ", a[i] == v.back() ? v[n-2] : v[n-1]);
   }
}

Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

//Mが非常に大きいので登場しうる余りが高々N+1個であることを移用して連想配列なりを用意する

int main() {
	int N, M, A[100100];
	cin >> N >> M;
	for (int i = 0; i < N; ++i)cin >> A[i];
	map<int, int>cnt;
	cnt[0] = 1;
	ll ans = 0, sm = 0;
	for (int i = 0; i < N; ++i) {
		sm += A[i];
		ans += cnt[sm%M];
		cnt[sm%M]++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3584
def main():
    h, w = map(int, input().split())
    n = int(input())
    a = [int(x) for x in input().split()]
    answer = [[0 for _ in range(w)] for _ in range(h)]
    dir = [[0, w, 1], [-1, -w - 1, -1]]
    count = 0
    color = 1
    for i in range(h):
        for j in range(dir[i % 2][0], dir[i % 2][1], dir[i % 2][2]):
            answer[i][j] = color
            count += 1
            if count == a[color - 1]:
                count = 0
                color += 1
    for ans in answer:
        print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3568
def kari():
    N = list(map(int, input().split()))
    A, B = map(int, input().split())

def main():
    N = list(map(int, input().split()))
    if N[0] <= N[2] <= N[1] or N[0] >= N[2] >= N[1]:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
typedef long long lint;
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(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    rep(i, M) { cin >> B[i]; }
    int A[N][M];
    rep(i, N) {
        rep(j, M) { cin >> A[i][j]; }
    }
    int cnt = 0;
    int ans = 0;
    rep(i, N) {
        cnt = 0;
        rep(j, M) { cnt += A[i][j] * B[j]; }
        cnt += C;
        if(cnt > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
    long long i,n,a,b[200010],ans=0;
    set<long long> s;
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> a;
        b[a] = i;
    }
    s.insert(0);
    s.insert(n+1);
    for(i=1;i<=n;i++){
        auto x = s.upper_bound(b[i]);
        auto y = x--;
        ans += i*(*x-b[i])*(b[i]-*(y));
        s.insert(b[i]);
    }
    cout << ans << endl;
}

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

namespace ABC167
{
    class C
    {
        static void Main(string[] args)
        {
            var NMX = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = NMX[0]; var M = NMX[1]; var X = NMX[2];
            var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();

            var ans = long.MaxValue;
            for (int bit = 0; bit < (1 << (int)N); bit++)
            {
                var res = new long[M];
                var sum = 0L;
                for (int i = 0; i < N; i++)
                {
                    if ((bit & (1 << i)) > 0)
                    {
                        sum += CA[i][0];
                        for (int j = 0; j < M; j++)
                        {
                            res[j] += CA[i][j + 1];
                        }
                    }
                }
                if (res.Count(x => X <= x) == M) ans = Math.Min(ans, sum);

            }

            if (ans == long.MaxValue) Console.WriteLine(-1);
            else Console.WriteLine(ans);

        }
    }
}



Measured memory_bytes: 28856
// AOJ 2824: Coastline
// 2017.9.23 bal4u@uu
// 2017.11.25
// 2018.1.4

#include <stdio.h>

int a[100000], size;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int t, d, l, x, i, ans;

	while (t = in()) {
		d = in(), l = in();
		size = 0;
		for (i = 0; i < t; i++) if (in() >= l) a[size++] = i;

		t--, ans = 0;
		for (i = 1; i < size; i++) {
			x = d;
			if (   t - a[i-1] < d) x = t - a[i-1];
			if (a[i] - a[i-1] < x) ans += a[i] - a[i-1];
			else ans += x;
		}
		if (size > 0) ans += (a[size-1] + d > t)? t - a[size-1]: d;
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int h, w;
  cin >> h >> w;
  char s[55][55];
  int c[55][55];  
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> s[i][j];
      if(s[i][j] == '.') {
        c[i][j] = 0;
      }
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> s[i][j];
      c[i][j] = 0;        
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(s[i][j] == '#'){
        for(int k = i - 1 ; k <= i + 1; ++k){
          for(int l = j - 1; l <= j + 1; ++l){
            if(s[k][l] != '#')
              c[k][l] += 1;
          }
        }
      }     
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(s[i][j] == '#') {      
        cout << s[i][j];
      }
      else {
        cout << c[i][j];
      }
    }
    cout << endl;
  }
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int n; cin>>n;
    stack<string> sta;
    REP(i,n){
        string t; cin>>t;
        if(sta.size()==0){
            sta.push(t);
        }else{
            if(sta.top()=="A"&&t=="Un")sta.pop();
            else{
                sta.push(t);
            }
        }
    }
    
    if(sta.size()==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3180
from itertools import permutations

N,M = map(int,input().split())

L = [[False for i in range(N)] for j in range(N)]

for i in range(N) :
    L[i][i] = True
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    L[a][b] = True
    L[b][a] = True

arange = range(2,N+1)

res = 0
for P in permutations(arange) :
    P = [1] + list(P)
    for S,G in zip(P,P[1:]) :
        if not L[S-1][G-1] :
            break
    else :
        res += 1
print(res)


Measured memory_bytes: 3064
#include<cstdio>
#include<queue>

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

#define MAX_V 100000
#define INF 2147483647

struct edge{ int to, cost; };//to,cost
typedef pair<int,int> P;//first:Minimum distance/second:Vertex number

int V;
vector<edge> G[MAX_V];
int d[MAX_V];


void dij(int s){
//use greater<P> to pop minimum struct in the P-queue
	priority_queue<P,vector<P>,greater<P> >que;
	fill(d,d+V,INF);//insted of "for"loop
	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.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
	int s,E;
	scanf("%d%d%d",&V,&E,&s);
	REP(i,E){
		int rs,rt,rd;
		scanf("%d%d%d",&rs,&rt,&rd);
		edge ine={rt,rd};
		G[rs].push_back(ine);
	}
	dij(s);
	REP(i,V){
		if(d[i]>=INF)
			printf("INF\n");
		else
			printf("%d\n",d[i]);
	}
	return 0;
}

Measured memory_bytes: 11184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m;ll ans,msk[25];
vector<int> v[55],id[55];
vector<int> path;
bool fnd;
void dfs(int x,int fa,int ter){
    //printf("%d %d %d\n",x,fa,ter);
    if(x == ter){
        fnd = 1;
        return;
    }
    rap(i,0,v[x].size()){
        int to = v[x][i];
        if(to == fa) continue;
        path.pb(id[x][i]);
        dfs(to,x,ter);
        if(fnd) return;
        path.pop_back();
    }
}
void dfs2(int x,int num,ll cur){
    if(x == m + 1) {
        int u = __builtin_popcountll(cur);
        if(num & 1) ans -= 1ll << (n - 1 - u);
        else ans += 1ll << (n - 1 - u);
        return;
    }
    dfs2(x+1, num+1, cur | msk[x]);
    dfs2(x+1, num  , cur);
}
int main()
{
    scanf("%d",&n);
    rep(i,1,n-1){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        v[t1].pb(t2);v[t2].pb(t1);
        id[t1].pb(i);id[t2].pb(i);
    }
    scanf("%d",&m);
    rep(i,1,m) {
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        fnd = 0;
        dfs(t1,0,t2);
        //rap(j,0,path.size()) printf("%d ",path[j]);
        //puts("");
        rap(j,0,path.size()) msk[i] |= 1ll<<(path[j]-1);
        path.clear();
    }
    dfs2(1,0,0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3756
/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define N 100

int main() {
	static char s[N + 1];
	int n, i, yes;

	scanf("%s", s);
	n = strlen(s);
	yes = 1;
	for (i = 0; i < n; i++)
		if (s[i] == (i % 2 == 0 ? 'L' : 'R')) {
			yes = 0;
			break;
		}
	printf(yes ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
int coun[500000],coun2[500000],coun3[500000],coun4[500000];
int  main(){
  coun[1]=1;
  coun2[2]=1;
  coun3[3]=1;
  coun4[4]=1;
  for(int i=2;i*i<50000;i++){
    coun[i*i]++;
    for(int j=i*i;j<50000;j++){
      coun2[j]+=coun[j-i*i];
      coun3[j]+=coun2[j-i*i];
      coun4[j]+=coun3[j-i*i];
    }
  }
  while(1){
    int x;
    cin>>x;
    if(x==0) break;
    cout<<(coun[x]+coun2[x]+coun3[x]+coun4[x])<<endl;
  }
  return 0;
}



Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,S;
  cin >> K >> S;
 
  
  int ans = 0;
  
  
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if(S - i - j >= 0 && S - i - j <= K)
        ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3556
n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(n):
    j = l[i:].index(min(l[i:])) + i
    l[i], l[j] = l[j], l[i]
    if i != j:
        c += 1
print(" ".join(map(str,l)))
print(c)


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

int main(){
  int n;
  cin >> n;
  int ans=0;
  rep(i,n)rep(j,n)rep(k,n) ans += gcd(i,gcd(j,k));
  cout << ans << endl; 
  return 0;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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 main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;
  ll ans = infll;
  for(ll i = 1; i*i <= n; i++) {
    if(n % i != 0) continue;
    chmin(ans, i+n/i-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
int t[]={850,1100,1230,1400,1610,1520,1950,1870,2070,2250,2244,2620,2624,2794,3004,3040,3344,3390,3590,3740,3764,4120,4114,4314,4494,4488,4864,4868,5038,5248,5284,5588,5634,5834,5984,6008,6364,6358,6558,6738,6732,7108,7112,7282,7492,7528};int main(n){while(scanf("%d",&n),n){printf("%d\n",t[n/100-5]);}return 0;}

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

int main() {
  int N; cin >> N;
  vector<int>a(N);
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
  }
  
  int p = 0;
  int res = 0;
  bool undone = true;
  while(res < 10 * N) {
    res++;
    p = a[p];
    if(p == 1){
      undone = false;
      break;
    }
  }
  
  if(undone) cout << -1 << endl;
  else cout << res << endl;
}

Measured memory_bytes: 3792
n, m = (int(x) for x in input().split())
a_list = list(map(int, input().split()))

border = sum(a_list) / (4 * m)

# print('border')
# print(border)

count = 0

for i in range(len(a_list)):

    # print('a_list')
    # print(a_list[i])

    if border <= a_list[i] :
        # print('カウント!')
        count = count + 1

if m <= count :
    print('Yes')
else:
    print('No')

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    ll x;
    cin >> x;
    ll now = 100;
    int ans = 0;
    while (now < x) {
        now += now / 100;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

ll gcd(const ll a, const ll b) {
    assert(a <= b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

ll lcm(const ll a, const ll b) {
    assert(a <= b);
    return a * b / gcd(a, b);
}

ll calc(const ll A, const ll B, const ll m) {
    if (m > B) return 0LL;
    ll x = A % m;
    ll y = x == 0 ? A : A + m - x;
    return (B - y) / m + 1;
}

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

    if (D < C) {
        swap(C, D);
    }

    ll g1 = calc(A, B, C);
    ll g2 = calc(A, B, D);
    ll g3 = calc(A, B, lcm(C, D));

    // printf("%lld, %lld, %lld\n", g1, g2, g3);

    ll dividable = g1 + g2 - g3;
    cout << (B - A + 1) - dividable << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby

require 'pp'

N,M = gets.chomp.split(" ").map(&:to_i)

table = Array.new(N+1){|i| [0,[]]}

1.upto(M){|i|
   x,y,z = gets.chomp.split(" ").map(&:to_i)
   table[x][1] << y
   table[y][1] << x
}

#pp table

count = 0
1.upto(N){|n|
   node = table[n]
   if node[0] == 0
      count+=1
      node[0] = 1
      queue = [node]
      while !queue.empty? do
         current = queue.shift
         current[1].each{|n|
            if table[n][0] == 0
               table[n][0] = 1
               queue << table[n]
            end
         }
      end
   end
}

puts count

Measured memory_bytes: 17788
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int masu[10][10]={};
int x,y;
void sho(int i,int j){
  if(abs(i)+abs(j)<2) masu[i+y][j+x]++;
}
void chu(int i,int j){
  if(abs(i)<2&&abs(j)<2) masu[i+y][j+x]++;
}
void dai(int i,int j){
  if(abs(i)+abs(j)<=2) masu[i+y][j+x]++;
}
int main(){
  int s;
  while(scanf("%d,%d,%d",&x,&y,&s)!=EOF){
    for(int i=-2;i<=2;i++){
      for(int j=-2;j<=2;j++){
	if(i+y<0||j+x<0||i+y>=10||j+x>=10) continue;
	if(s == 1) sho(i,j);
	if(s == 2) chu(i,j);
	if(s == 3) dai(i,j);
      }
    }
  }
  int a=0,b=0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      a+=masu[i][j]==0;
      b = max(b,masu[i][j]);
    }
  }
  printf("%d\n%d\n",a,b);
  return(0);
}



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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1000000000 + 7;
const int N = 1e5 + 5;

typedef int ll;

ll n, odd, ar[N], cnt;

ll calc(ll player)
{
    ll cn = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(ar[i] % 2 == 0)
            cn ++;
        if(ar[i] & 1) odd = i;
    }
    if(cn % 2) return player;

    if(cn + 1 < n) return player ^ 1;

    if(ar[odd] == 1) return player ^ 1;

    ar[odd] --;

    ll gcd = 0;

    for(int i = 1; i <= n; i ++)
    {
        gcd = __gcd(gcd, ar[i]);
    }

    for(int i = 1; i <= n; i ++)
        ar[i] /= gcd;

    calc(player ^ 1);
}

inline void solve()
{
    scanf("%d", &n);

    for(int i = 1; i <= n; i ++)
    {
        scanf("%d", &ar[i]);
    }

    if(calc(1)) cout << "First" << endl;
    else cout << "Second" << endl;
}

int tests = 1;

int main()
{
//    scanf("%d", &tests);

    while(tests --)
        solve();
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys

YES = "Possible"  # type: str
NO = "Impossible"  # type: str

def solve(N: int, a: "List[int]"):
    amax = max(a)
    vmin = (amax + 1) // 2
    nmin = amax % 2 + 1

    for i in range(1, amax+1):
        if i < vmin and a.count(i) > 0:
            print(NO)
            return
        if i == vmin and a.count(i) != nmin:
            print(NO)
            return
        if i > vmin and a.count(i) < 2:
            print(NO)
            return
    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  printf("%d\n", (a-1)*(b-1));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lim 1e9
#define on 100005
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR for(int i=1;i<=n;i++)
typedef long long int lo; 
typedef pair<int,int> PII;
int n,m,cev,a[100005],vis[on],cevv,mx=lim,flag;
char c;
string s;
stack<int> st;
vector<int> v;
int main(){
	scanf("%d",&n);
	if(n<=111){
		printf("111");
		return 0;
	}
	if(n<=222){
		printf("222");
		return 0;
	}
	if(n<=333){
		printf("333");
		return 0;
	}
	if(n<=444){
		printf("444");
		return 0;
	}
	if(n<=555){
		printf("555");
		return 0;
	}
	if(n<=666){
		printf("666");
		return 0;
	}
	if(n<=777){
		printf("777");
		return 0;
	}
	if(n<=888){
		printf("888");
		return 0;
	}
	if(n<=999){
		printf("999");
		return 0;
	}
	return 0;
}



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

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

using namespace std;

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 A, B, C;

int main(){
	cin >> A >> B >> C;
	REP(i, 1000){
		int t = 60 * i + C;
		if(t % (A + B) <= A){
			cout << t << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long n,i,k,ans;
struct nyh{
	long long x,y,z;
}o[105];
double ans2;
long long read(){
	long long xx=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
long long pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
}
int ss(long long j,long long u,long long v){
	if(j>n){
		ans=max(ans,u*u+v*v);
		return 0;
	}
	if(j<=10||u*u+v*v<=(u+o[j].x)*(u+o[j].x)+(v+o[j].y)*(v+o[j].y))
		ss(j+1,u+o[j].x,v+o[j].y);
	if(j<=10||u*u+v*v>(u+o[j].x)*(u+o[j].x)+(v+o[j].y)*(v+o[j].y))
		ss(j+1,u,v);
}
bool cmp(nyh u,nyh v){
	return u.z<v.z;
}
int main(){
	n=read();
	for(i=1;i<=n;i++)
		scanf("%lld%lld",&o[i].x,&o[i].y);
	for(i=1;i<=1000;i++){
		srand(i*i*123+i*456);
		for(k=1;k<=n;k++)
			o[k].z=rand();
		sort(o+1,o+n+1,cmp);
		ss(1,0,0);
	}
	ans2=sqrt(ans);
	printf("%.13lf\n",ans2);
	return 0;
}

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

#define MAX 100000
#define M   1000000007

typedef unsigned long long ULL;


ULL training(ULL N) {
    ULL power = 1;
    for(ULL i = 1; i <= N; i++) {
        power *= i;
        power %= M;
    }
    return power;
}

int main(int argc, const char * argv[]) {
    ULL N;
    scanf("%llu", &N);
    if(N < 1 || N > 100000) {
        return 1;
    }
    
    printf("%lld\n", training(N));
    return 0;
}


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

int main() {
	long long n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	cout << (n + min({ a, b, c, d, e }) - 1) / min({a, b, c, d, e}) + 4 << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func primeFactors(n int) []int {
	factors := make([]int, 0)
	i := 2
	for i*i <= n {
		r := n % i
		if r != 0 {
			i++
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	f := primeFactors(n)
	i := 0
	z := 0
	ok := false
	zcount := 0
	ncount := 0
	for i < len(f) {
		if z != f[i] {
			zcount = 0
		}
		z = f[i]
		if zcount == 0 {
			ok = true
		} else {
			if i+zcount < len(f) {
				for j := 1; j <= zcount; j++ {
					// fmt.Println(zcount)
					if z != f[i+j] {
						ok = false
						zcount = j
						break
					}
					ok = true
				}
			} else {
				ok = false
				for j := 1; j < len(f)-i; j++ {
					if z != f[i+j] {
						zcount = j
					}
				}
			}
		}
		if ok {
			zcount++
			ncount++
		}
		i += zcount
	}
	fmt.Println(ncount)
}


Measured memory_bytes: 1772
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double pi = 3.14159265359;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int k, s;

int main()
{
	cin >> k >> s;
	int ans = 0;
	for (int x = 0; x <= k;x++) {
		for (int y = 0; y <= k; y++) {
			if (s - x - y <= k && s - x - y >= 0) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int N, A, B, C, T; string S[100009];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		for (int j = 0; j < (int)S[i].size() - 1; j++) {
			if (S[i].substr(j, 2) == "AB") T++;
		}
		if (S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A') C++;
		if (S[i][0] != 'B' && S[i][S[i].size() - 1] == 'A') A++;
		if (S[i][0] == 'B' && S[i][S[i].size() - 1] != 'A') B++;
	}
	
	if (A == 0 && B == 0) cout << T + max(0LL, C - 1LL) << endl;
	else cout << T + min(A, B) + C << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
int rec(int ans,char c,int n){
      if(c=='+')return ans+n;
      if(c=='-')return ans-n;
      if(c=='*')return ans*n;
      if(c=='/')return ans/n;
}
int main(){
      int ans,n;
      char c;
      cin>>ans;
      while(cin>>c&&c!='='){
            cin>>n;
            ans=rec(ans,c,n);
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 1160