akhauriyash/Code-Regression huggingface dataset:
N = gets.to_i

size = N.to_s.size

ans = 0

(3..(size - 1)).each do |i|
  ans += [3, 5, 7].repeated_permutation(i).count { |l| l.uniq.size == 3 }
end

ans += [3, 5, 7].repeated_permutation(size).count { |l| l.uniq.size == 3 && l.join.to_i <= N }

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define rep(i, n, k) for(int i = k; i < n; ++i)
using namespace std;

int main(){
  long long int n;
  cin >> n;
  vector<long long int> xa, xb;
  rep(i,n,0){
    long long int v;
    cin >> v;
    if(i % 2 == 0) xa.push_back(v);
    else xb.push_back(v);
  }
  sort(xa.begin(), xa.end());
  sort(xb.begin(), xb.end());
  
  long long int af = 0, as = 0, am = 1, bf = 0, bs = 0, bm = 1;
  long long int adf, ads, bdf, bds;
  rep(i,xa.size(),0){
    if(xa[i+1] != xa[i] || i == xa.size()-1){
      if(am > as){
        as = am;
        ads = xa[i];
        if(as > af){
          swap(af,as);
          swap(ads, adf);
        }
      }
      am = 1;
    } 
    else am++;
  }
  rep(i,xb.size(),0){
    if(xb[i+1] != xb[i] || i == xb.size()-1){
      if(bm > bs){
        bs = bm;
        bds = xb[i];
        if(bs > bf){
          swap(bf,bs);
          swap(bds, bdf);
        }
      }
      bm = 1;
    } 
    else bm++;
  }
  long long int ans;
  if(adf != bdf) ans = n-bf-af;
  else ans = n - max(af + bs, bf + as);
  cout << ans << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>

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

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

	ll ans = 0;
	rep(i,n)
	{
		ll temp;
		cin >> temp;

		ans += temp;
	}
	ans /= n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1156
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            Console.WriteLine((X-A)%B);
        }
    }
}


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

int main() {
    string s;
    cin >> s;

    string ans = "Yes";
    if (s[2] != s[3]) ans = "No";
    if (s[4] != s[5]) ans = "No";

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

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

typedef pair<int, int> Pair;

int N, M;
vector<vector<int>> nbr;
map<Pair, char> dir;
vector<bool> visited;

void mkDir(int x, int y) {
  dir[make_pair(x, y)] = 1;
  dir[make_pair(y, x)] = -1;
}

void dfs(int p, int c) {
  char parity = 0;
  if (visited.at(c)) {
    mkDir(p, c);
    return;
  }
  visited.at(c) = true;
  for (int g : nbr.at(c)) {
    if (g == p) continue;
    char d = dir[make_pair(c, g)];
    if (d == 0) {
      dfs(c, g);
      d = dir[make_pair(c, g)];
    }
    if (d == 1) parity = 1 - parity;
  }
  if (p >= 1) {
    if (parity) mkDir(c, p);
    else        mkDir(p, c);
  }
  return;
}

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  cin >> N >> M;
  if (M % 2 == 1) {
    cout << "-1\n";
    return 0;
  }
  nbr.resize(N+1);
  visited.resize(N+1);
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    nbr.at(a).push_back(b);
    nbr.at(b).push_back(a);
    dir[make_pair(a,b)] = dir[make_pair(b,a)] = 0;
  }
  dfs(-1, 1);
  for (auto m : dir) {
    int x = m.first.first, y = m.first.second;
    char d = m.second;
    if (x > y) continue;
    if (d == 1) { cout << x << " " << y << "\n"; }
    else        { cout << y << " " << x << "\n"; }
  }

  return 0;
}



Measured memory_bytes: 30336
n = int(input())
a = list(map(int,input().split()))
a.append(0)

bf = 0
maxcost = 0
for i in range(n+1):
        maxcost += abs(bf-a[i])
        bf = a[i]

a.insert(0,0)
for i in range(1,n+1):
    dc = abs(a[i-1]-a[i])+abs(a[i]-a[i+1])-abs(a[i-1]-a[i+1])
    print(maxcost - dc)


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


int main() {
    ll N; cin >> N;
    vector<ll> A(N); 
    for(ll i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(i < N-1){
            ans += A[i]/2;
            A[i] %= 2;
            if(A[i] == 1 && A[i+1] != 0){
                ans++;
                A[i+1]--;
            }
        }
        else ans += A[i]/2;
    }

    
    cout << ans << endl;

}

Measured memory_bytes: 1024
import sys
N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))
bin_k = bin(K)[2:].zfill(50)
cnt = [0] * 50

for a in A:
    bin_a = bin(a)[2:]
    for i, b in enumerate(bin_a[::-1]):
        if b == "1":
            cnt[i] += 1

cnt = cnt[::-1]
dp = [[0] * 2 for _ in range(50 + 1)]
ans = 0
base = 2 ** (50 - 1)
flag = False

for i, c in enumerate(cnt, 1):
    if flag:
        if bin_k[i - 1] == "1":
            dp[i][0] = dp[i - 1][0] + base * (N - c)
            dp[i][1] = max(dp[i - 1][0] + base * c, dp[i - 1][1] + base * c,
                        dp[i - 1][1] + base * (N - c))
        else:
            dp[i][0] = dp[i - 1][0] + base * c
            dp[i][1] = max(dp[i - 1][1] + base * c, dp[i - 1][1] + base * (N - c))
    else:
        if bin_k[i - 1] == "1":
            dp[i][0] = dp[i - 1][0] + base * (N - c)
            tmp1 = dp[i - 1][0] + base * c
            tmp2 =  dp[i - 1][1] + base * c
            tmp3 = dp[i - 1][1] + base * (N - c)
            if tmp3 <= tmp1 and tmp3 <= tmp2:
                dp[i][1] = max(tmp1, tmp2)
                flag = True
            elif tmp3 <= tmp1:
                dp[i][1] = tmp1
                flag = True
            else:
                dp[i][1] = tmp3
        else:
            dp[i][0] = dp[i - 1][0] + base * c
            dp[i][1] = dp[i - 1][1] + base * c

    base //= 2

print(max(dp[50][0], dp[50][1]))

Measured memory_bytes: 14748
#include <iostream>
#include <cstdio>
using namespace std;
int n;
char ch[40];
int l[20], qr;
long long f[20][20][20], ans;
bool inq[20][20][20];
pair <int, pair <int, int> > q[8010];
inline void dfs (int step, int l1, int l2) {
	if (step > n) {
		f[0][l1][l2] = 1;
		qr = 0, q[++qr] = make_pair (0, make_pair (l1, l2));
		for (int i = 1; i <= qr; i++) {
			int p = q[i].first, lx = q[i].second.first, ly = q[i].second.second; ++p;
			if (p > n) ans += f[p - 1][lx][ly];
			else {
				if (ch[p + n] == ch[lx]) {
					f[p][l[lx]][ly] += f[p - 1][lx][ly];
					if (!inq[p][l[lx]][ly])
						q[++qr] = make_pair (p, make_pair (l[lx], ly));
					inq[p][l[lx]][ly] = true;
				}
				if (ch[p + n] == ch[ly]) {
					f[p][lx][l[ly]] += f[p - 1][lx][ly];
					if (!inq[p][lx][l[ly]])
						q[++qr] = make_pair (p, make_pair (lx, l[ly]));
					inq[p][lx][l[ly]] = true;
				}
			}
			f[p - 1][lx][ly] = inq[p - 1][lx][ly] = 0;
		}
		return;
	}
	l[step] = l1;
	dfs (step + 1, step, l2);
	l[step] = l2;
	dfs (step + 1, l1, step);
}
int main () {
	scanf ("%d", &n);
	scanf ("%s", ch + 1);
	dfs (2, 1, 0);
	printf ("%lld\n", ans << 1);
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int slcompare(const void *a,const void *b){
    if(*(long long *)a>*(long long  *)b)return 1;
    return -1;
}
int lscompare(const void *a,const void *b){
    if(*(long long *)a>*(long long  *)b)return -1;
    return 1;
}
long long MAX(long long a,long long  b){
    return a>b?a:b;
}
int main()
{   long long  n,k;
    scanf("%lld%lld",&n,&k);
    long long a[n],f[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%lld",&f[i]);
    }
    qsort(a,n,sizeof(long long),slcompare);
    qsort(f,n,sizeof(long long),lscompare);
    long long l=-1,r=1000000000000;
    while(l+1<r){
        long long mid=(l+r)/2;
        long long sum=0;
        for(int i=0;i<n;i++){
            sum+=MAX(0,a[i]-mid/f[i]);
        }
        if(sum<=k){
            r=mid;
        }else{
            l=mid;
        }
    }
    printf("%lld",r);
    return 0;
}


Measured memory_bytes: 4860
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

char A[505][505];

int col[505];
int row[505];

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

  bool ok=false;
  for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(A[i][j]=='#') ok=true;
  if(!ok){
    cout<<-1<<endl;
    return 0;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(A[i][j]=='#'){
          row[i]++;
          col[j]++;
      }
    }
  }

  int macol=0;
  for(int j=0;j<N;j++) if(col[j]==N) macol++;

  int ans=2*N;
  for(int i=0;i<N;i++){
    if(col[i]>0) ans=min(ans,(N-macol)+(N-row[i]));
    else ans=min(ans,(N-macol)+(N-row[i])+1);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 512
#create date: 2020-07-03 14:00

import sys
stdin = sys.stdin

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

def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x); y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True
    def same(x, y):
        return find(x) == find(y)
    def size(x):
        return -par[find(x)]


    n, m, k = na()
    par = [-1] * n
    friend = [0] * n
    block = [list() for i in range(n)]
    for i in range(m):
        a, b = na()
        a -= 1; b -= 1
        unite(a, b)
        friend[a] += 1
        friend[b] += 1
    for i in range(k):
        c, d = na()
        c -= 1; d -= 1
        block[c].append(d)
        block[d].append(c)
    #print(par, fb)
    for i in range(n):
        ans = size(i) - friend[i] - 1
        for b in block[i]:
            if same(i, b):
                ans -= 1
        print(ans, end=" ")
if __name__ == "__main__":
    main()

Measured memory_bytes: 92456
using System;
using System.Linq;

namespace _011_DrawingLots
{
	class Program
	{
		static void Main ( string[] args )
		{
			int lineCount = int.Parse (Console.ReadLine ());
			int dataSetCount = int.Parse (Console.ReadLine ());

			int[] lineArray = Enumerable.Range (1, lineCount).ToArray ();

			for (int lp = 0; lp < dataSetCount; lp++)
			{
				int[] moveData = Console.ReadLine ().Split (',').Select (str => int.Parse (str)).ToArray ();

				int index1 = moveData[0] - 1;
				int index2 = moveData[1] - 1;

				int tmp = lineArray[index1];
				lineArray[index1] = lineArray[index2];
				lineArray[index2] = tmp;
			}

			foreach (var item in lineArray)
			{
				Console.WriteLine (item);
			}
		}
	}
}

Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m = n;
  int s = 0;
  while(m>0){
    s += m%10;
    m /= 10;
  }
  if(n%s==0) cout << "Yes" <<endl;
  else cout <<"No" <<endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

bool prime[2000000] = {};
void Eratosthenes(int n)
{
  for (int i = 2; i <= (int)sqrt(n) + 1; ++i)
  {
    if (prime[i] == 0)
    {
      for (int j = i * 2; j <= n; j += i)
      {
        prime[j] = 1;
      }
    }
  }
}

int main()
{
  Eratosthenes(1299709);
  int k;
  vector<int> ans;
  while (cin >> k, k)
  {
    int cnt = 0;
    int pk = k, nk = k;
    while (prime[pk] && pk < 1299709)
    {
      cnt++;
      pk++;
    }
    while (prime[nk] && nk > 1)
    {
      cnt++;
      nk--;
    }
    ans.push_back(cnt);
  }
  for (auto &e : ans)
    cout << e << endl;

  return 0;
}



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

int main(){
	int i, j;
	char C[5][5];
	for(i=1; i<=2; i++){
		for(j=1; j<=3; j++){
			cin >> C[i][j];
		}
	}
	
	if(C[1][1]==C[2][3] && C[1][2]==C[2][2] && C[1][3]==C[2][1])	cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    num, a, b = MI()

    total = 0
    for n in range(num + 1):
        s = sum(list(map(int, str(n))))
        if a <= s <= b:
            total += n
    print(total)
    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 41196
import math

K = int(input())

total = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab = math.gcd(a, b)
        if ab == 1:
            total += K
        else:
            for c in range(1, K + 1):
                total += math.gcd(ab, c)

print(total)

Measured memory_bytes: 9184
#include <stdio.h>
int main(){
    int n,a[100][100],x,y,now;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=0;
        x=n/2+1;
        y=n/2;
        now=1;
        while(now<=n*n){
            if(a[x][y]!=0){
                x++;
                y--;
            }
            x=(x+n)%n;
            y=(y+n)%n;
            //printf("%d %d\n",x,y);
            a[x][y]=now;
            x++;
            y++;
            x=(x+n)%n;
            y=(y+n)%n;
            now++;
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)printf("%4d",a[i][j]);
            printf("\n");
        }
    }
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)

int main()
{

	char a;

	cin>>a;

	cout<<(char)(a+1)<<endl;

	return 0;
}

Measured memory_bytes: 256
ABC = [int(i) for i in input().split()]
count5 = 0
count7 = 0
ans = "NO"

for i in ABC:
    if i == 5: count5 += 1
    if i == 7: count7 += 1

if count5 == 2 and count7 == 1:
    ans = "YES"

print(ans)

Measured memory_bytes: 3060
import collections
N = int(input())
A = [int(i) for i in input().split()]

Cnt = collections.Counter(A)
S = sum(A)

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    S += (C-B)*Cnt[B]
    print(S)
    Cnt[C] += Cnt[B]
    Cnt[B] = 0


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

const int INF = 500000005;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> c(m);
  rep(i,m) cin>>c[i];
  
  int dp[50002];
  rep(i,50002) dp[i] = INF;
  dp[0] = 0;
  rep(j,m)rep(i,n+1){
    if(i+c[j] < n+1)
      dp[i+c[j]] = min(dp[i+c[j]],dp[i]+1);
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3284
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		StringBuilder all = new StringBuilder();
		StringBuilder out = new StringBuilder();
		
		while(true){
			
			int h = sc.nextInt();
			int w = sc.nextInt();
			
			if((h + w) <= 0){break;}
			
			//top
			for(int t = 0; t < w; t++){
				out = out.append("#");
			}
			out = out.append("\n");
			
			//center
			
			for(int j = 0; j < (h-2); j++){
				out = out.append("#");
				for(int i = 0; i < (w-2); i++){
						out = out.append(".");
					}
				out = out.append("#");
				out = out.append("\n");
			}
			
			//bottom
			for(int b = 0; b < w; b++){
				out = out.append("#");
			}
			
			out = out.append("\n");
			//inputAll
			all = all.append(out + "\n");
			out.delete(0, out.length());
			
		}
		//output
		System.out.print(all);
	}
}


Measured memory_bytes: 28008
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  int x, a; cin >> x >> a;
  cout << (x<a? 0:10) << endl;
  return 0;
}


Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   unsigned long long ll;
// typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  if(n%2) {
    cout << 0 << endl;
  } else {
    ll curr = 5;
    ll ans = 0;
    while(curr <= n) {
      ll pp = n/curr;
      ans+= pp/2;
      curr*=5;
    }
    cout << ans << endl;
  }
  return 0;
} //good night.

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

string s;

int main()
{
    cin>>s;
    
    if(s=="SAT")
    	cout<<'1';
    else if(s=="FRI")
    	cout<<'2';
    else if(s=="THU")
    	cout<<'3';
    else if(s=="WED")
    	cout<<'4';
    else if(s=="TUE")
    	cout<<'5';
    else if(s=="MON")
    	cout<<'6';
    else if(s=="SUN")
    	cout<<'7';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <map>
#include <set>
#include <algorithm>
#include <stack>

using namespace std;

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vll> vvl;
typedef pair<ll, ll> pll;
typedef pair<string, ll> psl;
typedef vector<psl> vpsl;
typedef vector<pll> vpl;
typedef unordered_set<ll> usl;
typedef set<ll> sl;
typedef unordered_map<ll, ll> uml;
typedef map<ll, ll> ml;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

#define all(v) v.begin() , v.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll inf = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';

template<typename Type>
istream &operator>>(istream &in, vector<Type> &v)
{
    ll n = v.size();
    for (int i = 0; i < n; i++)
        in >> v[i];
    return in;
}

template<typename Type>
ostream &operator<<(ostream &out, vector<Type> &v)
{
    for (auto value : v)
        out << value << " ";
    out << endl;
    return out;
}

void solve()
{
    ll n;
    cin >> n;
    vector <double> p(n + 1);
    for (ll i = 1; i <= n; ++i)
        cin >> p[i];
   vector<vector<double>> dp (n + 1, vector <double>(n + 1, 0.0));
    dp[0][0] = 1.0;
    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = 0; j <= i; ++j)
        {
            if (j == 0)
                dp[i][j] = (1.0 - p[i]) * dp[i - 1][j];
            else
                dp[i][j] = (p[i] * dp[i - 1][j - 1]) + (1.0 - p[i]) * dp[i - 1][j];
        }
    }
//    for (const auto& v : dp)
//    {
//        for (float i : v)
//            cout << i << ' ';
//        cout << nl;
//    }
    double ans = 0.0;
    for (ll j = 0; j <= n; ++j)
    {
        if (j > n - j)
            ans += dp[n][j];
    }
    printf("%.10lf\n", ans);
}

int main()
{
    IOS
    ll t;
    t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 73756
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main () {
    int N,A;

    cin >> N >> A;

    if (N% 500 <= A)cout << "Yes" << endl;
    else cout << "No" << endl;


}

    


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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int tmp = -1;
    rep(i,n){
        if(tmp <= h[i]-1) tmp = h[i]-1;
        else if(tmp <= h[i]) tmp = h[i];
        else {
            printf("No");
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

sumA = sum(A)
factors = []

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

div =  make_divisors(sumA)
ans = 1
for div_ in div:
    A_ = sorted([a % div_ for a in A])[::-1]
    if sum(A_[sum(A_) // div_:]) <= K:
        ans = div_
print(ans)


Measured memory_bytes: 74028
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<i64>();
    let mut anss = vec![];
    let mut sum = 0;
    if n == 0 {
        anss.push(0);
    }
    for i in 0..40 {
        let v = 1 << i;
        let sign = if i % 2 == 0 { 1 } else { -1 };
        if sum == n {
            break;
        }
        if ((n - sum).abs() & v) > 0 {
            anss.push(1);
            sum += v * sign;
        } else {
            anss.push(0);
        }
    }
    anss.reverse();
    for &b in anss.iter() {
        print!("{}", b);
    }
    println!("");
    assert!(sum == n);
}


Measured memory_bytes: 4352
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

T = ir()

def check(a, b, c, d):
    if a < b or d < b:
        answer = 'No'
    # 以降 d >= b とする
    elif c >= b:
        answer = 'Yes'
    else:
        a %= b; d %= b
        # c < x < b の間に個数が入ると'No'
        g = gcd(b, d)
        if b - g + (a % g) > c:
            answer = 'No'
        else:
            answer = 'Yes'
    print(answer)

for _ in range(T):
    check(*lr())

# 16

Measured memory_bytes: 5116
import java.util.Scanner;

public class Main {
	static boolean is_cap(char c) {
		return 'A' <= c && c <= 'Z';
	}
	static boolean is_sml(char c) {
		return 'a' <= c && c <= 'z';
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		for (int i = 0; i < str.length(); ++i) {
			char c = str.charAt(i);
			System.out.print(is_cap(c) ? (char) (c - 'A' + 'a') : is_sml(c) ? (char) (c - 'a' + 'A') : c);
		}
		System.out.println();
	}
}


Measured memory_bytes: 26820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1001001001001001;
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,e;
    cin>>v>>e;
    ll dp[v][v];
    for(int i=0;i<v;i++)for(int j=0;j<v;j++){
        if(i==j)dp[i][j]=0;
        else dp[i][j]=INF;
    }
    for(int i=0,s,t,d;i<e;i++){
        cin>>s>>t>>d;
        dp[s][t]=min(dp[s][t],(ll)d);
    }
    for(int k=0;k<v;k++){
        for(int i=0;i<v;i++){
            if(dp[i][k]==INF)continue;
            for(int j=0;j<v;j++){
                if(dp[k][j]==INF)continue;
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=0;i<v;i++){
        if(dp[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    for(int i=0;i<v;i++){
        for(int j=0;j<v;j++){
            if(j>0)cout<<' ';
            if(dp[i][j]==INF)cout<<"INF";
            else cout<<dp[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3308
#include <iostream>
#include<string>
#include<algorithm>
int main()
{
	std::string a;
	std::cin >> a;
	for (auto ite = a.begin(); ite != a.end(); ++ite)
	{
		if (*ite == '1')
			*ite = '9';
		else if (*ite == '9')
			*ite = '1';
	}
    std::cout << a<<std::endl; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define PB(n) push_back(n)
#define endl '\n'
#define DOUT(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(ll ii = 0; ii < (ll)(V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define OUT2(n1,n2) cout << n1 << " " << n2 << endl
#define OUT3(n1,n2,n3) cout << n1 << " " << n2 << " " << n3 << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
constexpr long long MOD = 1000000007;
constexpr long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  // cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  ll h,w;
  IN3(h,w,k);
  vvi rck(h,vi(w,0));
  ll r,c,v;
  REP(i,k) {
    IN3(r,c,v);
    rck[r-1][c-1] = v;
  }
  vi dp(w, 0);
  vi a;
  FOR(j,0,w) {
    a.push_back(rck[0][j]);
    RSORT(a);
    if (a.size() > 3) a.pop_back();
    FOR(i,0,a.size()) dp[j] += a[i];
  }

  FOR(i,1,h) {
    FOR(k,0,3) {
      vi dp2(w, 0);
      FOR(j, 0, w) {
        if (j == 0 && k == 0) {
          dp2[j] = dp[j] + rck[i][j];
        } else if (j < k) {
          dp2[j] = dp[j];
        } else {
          if (k == 0) {
            dp2[j] = max(dp[j], max(dp2[j-1], dp[j] + rck[i][j]));
          } else {
            dp2[j] = max(dp[j], max(dp2[j-1], dp[j-1] + rck[i][j]));
          }
        }
      }
      dp = dp2;
    }
  }

  OUT(dp[dp.size()-1]);
}


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

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			StringBuilder sb = new StringBuilder();
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					sb.append(max);
					sb.append(" ");
					//System.out.println(max);
				}else{
					if(maxdub==0) {
						sb.append(B[N-2]);
						sb.append(" ");
						
						//System.out.println(B[N-2]);
					}else{
						sb.append(max);
						sb.append(" ");
						//System.out.println(max);
					}
				}
			}
			
			
			System.out.println(sb.toString());
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 94780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cerr<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const ll MAX=1e16;
const ll MM=1e18;
const ll mod=998244353;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll gcd(ll p, ll q){
    while(q != 0) {
        ll r = p % q;
        p = q;
        q = r;
    }
    return p;
}

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}
const ll MaxSize = 3e5;
ll facts[MaxSize], invFacts[MaxSize];

void preproc() {
  facts[0] = 1;
  for (int i = 1; i < MaxSize; i++) {
    facts[i] = ((ll)facts[i - 1] * i) % mod;
  }
  invFacts[MaxSize - 1] = expo(facts[MaxSize - 1], mod - 2,mod);

  for (int i = MaxSize - 2; i >= 0; i--) {
    invFacts[i] = ((ll)invFacts[i + 1] * (i + 1)) % mod;
  }
}

ll combination(ll n, ll k) {
  if(n<k) return 0;
  ll res = facts[n];
  res = ((ll)res * invFacts[k]) % mod;
  return ((ll)res * invFacts[n - k]) % mod;
}

////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////


void solve()
{
    int k;
    string s;
    cin >> k >> s;
    string ans = "";
    if(s.size() > k) {
        ans += s.substr(0, k);
        ans += "...";
        cout << ans << endl;
    }
    else {
        cout << s << endl;
    }
} 
int main()
{
  boost;
  int m;
  //cin >> m;
  int t=1;
  //cin>>t;
  while(t--)
  {
      solve();
  }
}



Measured memory_bytes: 3656
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()

dest = 0
nokori = 0
for i in reversed(range(N)):
	if A[i + 1] >= nokori:
		dest += nokori
		mons_hp = A[i + 1] - nokori
	else:
		dest += A[i + 1]
		mons_hp = 0

	if mons_hp > B[i]:
		nokori = 0
		dest += B[i]
	else:
		nokori = B[i] - mons_hp
		dest += mons_hp

if A[0] > nokori:
	dest += nokori
else:
	dest += A[0] 

print(dest)

Measured memory_bytes: 20544
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = (map(int,input().split())) 

score=0
for A in combinations_with_replacement(range(1,m+1),n):
    s = 0
    for j in range(q):
        if A[b[j]-1]-A[a[j]-1]==c[j]:
            s+=d[j]
    score = max(score,s)
print(score)


Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool decision(char c)
{
    if (c == '0') return true;
    else return false;
}

int main()
{
    string S;
    cin >> S;

    int ans = 0;

    for (int i = 0; i < S.size(); ++i)
    {
        if (decision(S[i]) && i%2 == 0) 
         ans++;
        else if (!(decision(S[i])) && i%2 == 1)
         ans++;
    }

    if (ans > S.size()/2) 
        ans = S.size() - ans;

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define l long long
#define pis acos(-1)
int main()
{
    l n,m,a,b,i,j,sum = 0,mx = LONG_LONG_MIN,mn = LONG_LONG_MAX;
    string str;
    vector<l>v;
    map<l,l>mp;
    set<l>s;
    for(i = 0;i < 5;i++)
    {
        cin>>a;
        if(a==0)
            m = i+1;
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    int n,d,dist,dist2,cnt=0,ans;
    cin>>n>>d;
    vector<vector<int>>pt(n,vector<int>(d));
    rep(i,n)rep(j,d)cin>>pt[i][j];
    rep(i,n){
        rep(j,n){
            dist2=0;
            if(i!=j){
                rep(k,d){
                    dist2+=pow(pt[i][k]-pt[j][k],2);
                }
                dist=sqrt(dist2);
                if(pow(dist,2)==dist2)cnt++;
            }
        }
    }
    ans=cnt/2;
    cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int a, b, c;

int main() {
	cin >> a >> b >> c;
	
	cout << (a == b && b == c ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> num; //木の要素数（根だけに有効！！）

    UnionFind(int N) : par(N),num(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
          par[i] = i;
          num[i] = 1;
        } 
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    llong unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return 0; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        llong GJ = (llong)num[rx] * (llong)num[ry];//減った不便さを計算
        num[ry] += num[rx];//併合するときに要素数を合算する
        return GJ;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){

  int n,m;
  cin>>n>>m;
  UnionFind UF(n);
  P bridge[m];
  REP(i,m){
    int a,b;
    cin>>a>>b;
    bridge[i].first = a-1;
    bridge[i].second = b-1;
  }

  //cout<<"heihe-i"<<endl;
 
  llong hubensa[m];
  hubensa[m-1] = (llong)n*(llong)(n-1)/(llong)2;
  for(int i=m-2;i>=0;i--){
    int a,b;
    a = bridge[i+1].first;
    b = bridge[i+1].second;
    //cout<<hubensa[i+1]<<endl;
    hubensa[i] = hubensa[i+1] - UF.unite(a,b);
  }

  REP(i,m){
    cout<<hubensa[i]<<endl;
  }


  return 0;
}

Measured memory_bytes: 3712
import sys 
sys.setrecursionlimit(10**6) 

def C():
    N, M, Q = map(int, input().split())
    ans = 0
    possibles = []
    def generate(cur_list, last):
        if len(cur_list) == N:
            possibles.append(cur_list)
            return
        for j in range(last, M+1):
            generate(cur_list+[j], j)

    generate([], 1)

    D = [0 for i in range(len(possibles))]

    # print(possibles)
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        for i, p in enumerate(possibles):
            if p[b-1] - p[a-1] == c:
                D[i] += d
    
    print(max(D))

C()

Measured memory_bytes: 26468
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

bool check(string s){
    REP(i, s.length()){
        if(s[i]=='#')
            return true;
    }
    return false;
}

int main(){
    ll H, W, K;
    cin >> H >> W>>K;
    vector<string> S(H);
    ll cnt = 0;
    vector<vll> ans(H);
    bool isGood = false;
    REP(i, H){
        cin >> S[i];
        if(check(S[i])){
            cnt++;
            isGood = true;
        }
        else if(isGood){
            REP(j, W){
                ans[i].push_back(ans[i-1][j]);
            }
        }
        else{
            continue;
        }
        bool meet=false, needchange=false;
        REP(j, W){
            if(S[i].at(j)=='.'){
                ans[i].push_back(cnt);
            }
            else{
                if(meet ==true)
                    cnt++;
                ans[i].push_back(cnt);
                meet = true;
            }
        }
    }
    //* check first line
    ll recheck = 0;
    REP(i, H){
        if(check(S[i])){
            recheck = i;
            break;
        }
    }
    REP(i, recheck){
        REP(j, W){
                ans[i].push_back(ans[recheck][j]);
        }
    }

    REP(i, H){
        REP(j, W){
            cout << ans[i][j] << " ";
        }
        cout << endl;
        
    }


    return 0;
}


Measured memory_bytes: 3072
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete


main = do
    [a,b,c,x] <- replicateM 4 getInt
    print $ length [() | i <- [0..a], j <- [0..b], k <- [0..c], 500*i+100*j+50*k==x]

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

int main() {
    int X;
    cin >> X;
    int ans = 1;
    int T = X;
    while (T%360 != 0) {
        T += X;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
xy=list(map(int,input().split()))
if sum(xy)%3!=0 or 2*xy[0]<xy[1] or 2*xy[1]<xy[0]:
    print(0)
else:
    n=sum(xy)//3
    r=2*n-xy[0]
    #p=int(input("enter p as mod"))
    p=10**9+7
    g=[1,1] #元(各整数の階乗)のリスト/g[i]=i!
    inv=[1,1] #n^-1を保存するリスト
    ig=[1,1] #逆元(各整数の階乗のmod pにおける逆数)のリスト/ig[i]=(i!)^-1 mod p
    for i in range(2,n+1):
        gi=g[-1]*i%p
        g.append(gi)
        invi=-inv[p%i]*(p//i)%p
        inv.append(invi)
        igi=ig[-1]*inv[-1]%p
        ig.append(igi)
    ans=g[n]*ig[r]*ig[n-r]%p
    print(ans)


Measured memory_bytes: 82448
#include<stdio.h>
#include<stdlib.h>
char c[8];
char d[3];
char ret[8][10]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
int R[]={0,0,0,0,255,255,255,255};
int G[]={0,0,255,255,0,0,255,255};
int B[]={0,255,0,255,0,255,0,255};
int main(){
	while(1){
		scanf("%s",c);
		if(c[0]!='#')return 0;
		d[0]=c[1];
		d[1]=c[2];
		d[2]='\0';
		int r=strtol(d,NULL,16);
		d[0]=c[3];
		d[1]=c[4];
		int g=strtol(d,NULL,16);
		d[0]=c[5];
		d[1]=c[6];
		int b=strtol(d,NULL,16);
		int min=99999999;
		int at=0;
		for(int i=0;i<8;i++)
			if(min>(r-R[i])*(r-R[i])+(g-G[i])*(g-G[i])+(b-B[i])*(b-B[i])){
				min=(r-R[i])*(r-R[i])+(g-G[i])*(g-G[i])+(b-B[i])*(b-B[i]);
				at=i;
			}
		
		printf("%s\n",ret[at]);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll r=0,g=0,b=0;
  rep(i,n){
    if(s[i]=='R'){
      r++;
    }else if(s[i]=='G'){
      g++;
    }else{
      b++;
    }
  }
  ll ans=r*g*b;
  for(int gap=1;gap<=((double)n-1)/2;gap++){
    for(int k=gap;k<=n-1-gap;k++){
      if(s[k-gap]!=s[k] && s[k-gap]!=s[k+gap] && s[k]!=s[k+gap] ){
        ans--;
      }
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
using Tree = vector<pair<int, int>>;

int main()
{
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0)
        cout << (a + b) / 2 << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	var S, T string
	fmt.Scanf("%d\n%s %s\n", &N, &S, &T)
	s := []rune{}
	for i := 0; i < N; i++ {
		s = append(s, []rune(S)[i], []rune(T)[i])
	}
	fmt.Println(string(s))
}


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

using namespace std;
#define N 100100
#define SIGMA 26
string s;
int main()
{
    int T = 1;
    //cin >> T;
    for (int tt = 0; tt < T; ++tt){
        cin >> s;
        for (int i = 0; i < s.size(); ++i)
            cout << 'x';
    }
    return 0;
}


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

int main() {
  int n, x, y, ans=0;
  cin >> n;
  vi v(n), c(n);
  rep(i,n) cin >> v[i];
  rep(i,n) cin >> c[i];
  rep(i,n){
    if(v[i] - c[i] > 0) ans += v[i]-c[i];
  }
  cout << ans << endl;
}


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

#define fi  first
#define se  second
#define mp  make_pair
#define pb  push_back

typedef long long ll;
typedef queue <int> qi;
typedef vector <int> vi;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <string, int> msi;
typedef pair <string, int> psi;
typedef map <string, string> mss;
typedef unsigned long long ull;

const ll mod = 10e9+7;
const double eps = 1e-11;
const double PI = 2 * acos(0.0);

int main() {
    int n;
    cin >> n;
    cout << n / 3 << endl;
}


Measured memory_bytes: 256