akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define sort stable_sort 
using namespace std; 

int _; 

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

int n,m,sx,sy,gx,gy,iidx[maxn*maxn],cnt,sum[maxn*maxn];
bool vis[1000050];
vector<int> idx[maxn*maxn]; 
string s[maxn];

void dfs(int x,int y)
{
	if(x<0 || y<0 || x >= n || y >= m || s[x][y] != '.' || iidx[x*maxn+y])
		return;
	idx[cnt].push_back(x*maxn+y);
	iidx[x*maxn+y]=cnt;
	for(int i=0;i<4;i++)
		dfs(x+dx[i],y+dy[i]);
} 

inline bool bfs()
{
	queue<int> q;
	sum[sx*maxn+sy]=1;
	for(auto v : idx[iidx[sx*maxn+sy]])
	{		
		sum[v]=sum[sx*maxn+sy];
		q.push(v);		
	}
	vis[iidx[sx*maxn+sy]]=true;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		if(u == gx*maxn+gy)
			return true;
		for(int i=-2;i <= 2;i++)
			for(int j=-2;j <= 2;j++)
				if(i || j)
				{
					int x=u/maxn+i,y=u%maxn+j;
					if(x >= 0 && y >= 0 && x<n && y<m && s[x][y] == '.' && !sum[x*maxn+y] && !vis[iidx[x*maxn+y]])
					{
						vis[iidx[x*maxn+y]]=true;
						for(auto v : idx[iidx[x*maxn+y]])
						{
							sum[v]=sum[u]+1;
							q.push(v);
						}
					}
				}
	}
	return false;
}

int main()
{ 
	//for(scanf("%d",&_);_;_--) 
	scanf("%d%d%d%d%d%d",&n,&m,&sx,&sy,&gx,&gy);
	sx--;
	sy--;
	gx--;
	gy--;
	for(int i=0;i<n;i++)
		cin >> s[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if(!iidx[i*maxn+j] && s[i][j] == '.')
			{
				cnt++;
				dfs(i,j);
			} 
	if(bfs())
		printf("%d\n",sum[gx*maxn+gy]-1);
	else
		printf("-1\n");
	return 0;
}  


Measured memory_bytes: 43860
#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];
    sort(a.begin(), a.end());
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a = n / 1000;
    n -= a * 1000;
    int b = n / 100;
    n -= b * 100;
    int c = n / 10;
    n -= c * 10;
    int d = n;

    char pm[2] = {'+', '-'};

    int sum = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                if (pm[i] == '+') sum += a + b;
                else sum += a - b;
                if (pm[j] == '+') sum += c;
                else sum -= c;
                if (pm[k] == '+') sum += d;
                else sum -= d;

                if (sum == 7) {
                    cout << a << pm[i] << b << pm[j] << c << pm[k] << d << "=7" <<endl;
                    return 0;
                }
                sum = 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
from math import *
x = int(input())
if x == 2 or x == 3:
    print(x)
else:
    while True:
        done = True
        if x % 6 != 1 and x % 6 != 5:
            done = False
        else:
            upper = floor(sqrt(x))
            for i in range(2, upper+1):
                if x % i == 0:
                    done = False
                    break
        if done:
            print(x)
            break
        x += 1


Measured memory_bytes: 3060
from collections import deque

N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

# print(edges)

def bfs(v):
    dist = [N] * N
    dist[v] = 0
    q = deque()
    q.append(v)
    while q:
        p = q.popleft()
        d = dist[p]
        for e in edges[p]:
            if dist[e] == N:
                dist[e] = d + 1
                q.append(e)
    return dist

fennec = bfs(0)
snuke = bfs(N-1)

cnt = 0
for i in range(N):
    if fennec[i] <= snuke[i]:
        cnt += 1
if 2 * cnt > N:
    print('Fennec')
else:
    print('Snuke')

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

//highlight color RGB = [70,70,70]
#define asll unsigned long long
#define ll long long
#define ld long double
#define imt int
#define pii pair<int,int>
#define st first
#define nd second
#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES "<<x<<endl;
#define psbk(x) push_back(x);
#define For(x,a,b) for(int x=(a);x<(b);x++)
#define FOR(x,n) for(int x=0;x<(int)(n);x++)
#define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml

asll M=1e9+7;
int n,m,tc;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	srand(time(0));
	string s,s1;
	getline(cin,s);
	getline(cin,s1);
	int kesama=0;
	int makskes=0;//maks kesamaan
	FOR(i,s.size()-s1.size()+1){
		kesama=0;
		FOR(j,s1.size()){
			//co s[i+j] kj "==" kj s1[j] ml
			kesama+=(s[i+j]==s1[j]);
			/*
			if(s[i+j]==s[j]){
				kesama++;
			}
			*/
		}
		//co s.substr(i,s1.size()) kj kesama ml
		if(makskes<kesama){
			makskes=kesama;
		}
	}
	//co (int)s1.size() kj kesama ml
	co (int)s1.size()-makskes ml
}


Measured memory_bytes: 3640
if __name__ == "__main__":
    N, W = map(lambda x: int(x), input().split())
    items = [[0, 0] for _ in range(N)]
    for i in range(N):
        items[i] = list(map(lambda x: int(x), input().split()))

    items = sorted(items, key=lambda x: - x[0] / x[1])

    total_value = 0.0
    total_weight = 0.0
    for (v, w) in items:
        if total_weight + w <= W:
            total_weight += w
            total_value += v
            if W == total_weight:
                break
        else:
            rest_weight = W - total_weight
            total_value += (v / w) * rest_weight
            break

    print(f"{total_value:.6f}")



Measured memory_bytes: 27140
n = int(input())
s = list(input())
allwest = s.count("W")
alleast = n-allwest
left_west = 0
right_east = alleast if s[0] == "W" else alleast-1
answer = left_west + right_east
for i in range(1,n):
    left_west += 1 if s[i-1]=="W" else 0
    right_east -= 1 if s[i] == "E" else 0
    answer = min(answer,left_west+right_east)
print(answer)
    
    



Measured memory_bytes: 5792
abc="abcdefghijklmnopqrstuvwxyz"
n=int(input())
hoge=[]
for i in range(n):
  hoge.append(input())

for i in range(len(abc)):
  huga=[]
  for j in range(n):
    huga.append(hoge[j].count(abc[i]))
  for j in range(min(huga)):
    print(abc[i],end="")

Measured memory_bytes: 3064
ls=list(input())
lt=list(input())
if ls!=lt:
  ls.sort()
  lt.sort(reverse=True)
  s_sorted=''.join(ls)
  t_sorted=''.join(lt)
  before=[s_sorted,t_sorted]
  after=[s_sorted,t_sorted]
  after.sort()
  if before==after:
    print('Yes')
  else:
    print('No')

else:
  print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
#define pb push_back
#define PI acos(-1.0)
#define EPS 1e-4
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fout(S,x)            cout<<fixed<<setprecision(x)<<(S)<<endl
#define present(c,x) ((c).find(x) != (c).end())
#define T() ll t;cin>>t;while(t--)
#define mem(input,b) memset(input,b,sizeof(input))
#define ff first
#define ss second
#define fread(input) freopen("input","r",stdin)
#define fwrite(b) freopen("b","w",stdout)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define FOREACH(i,c) for (__typeof ((c).begin()) i = (c).begin() ; i != (c).end() ; i++)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
const int mod = 1e9+7;
int f[1000005];
ll pow_mod(ll a, ll b=mod-2) {
  ll res=1;
  for(;b;b>>=1, a=a*a%mod) {
    if(b&1) res=res*a%mod;
  }
  return res;
}
ll inv(int x){
    return pow_mod(x,mod-2);
}
int main(){   
    fastio;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
        cin >> a[i];
    for(int i=0;i<n;++i){
        int x = a[i];
        for(int j=2;j*j<=x;++j){
            if(x%j==0){
                int cnt=0;
                while(x%j==0){
                    cnt++;
                    x /= j;
                }
                f[j] = max(f[j],cnt);
            }
            //f[j] = max(f[j],cnt);
        }
        if(x>1)
            f[x] = max(f[x],1);
    }
    ll lcm = 1;
    for(int i=0;i<1000005;++i){
        while(f[i]>0){
            lcm = (lcm*i)%mod;
            f[i]--;
        }
    }
    ll ans = 0;
    for(int i=0;i<n;++i){
        ans = (ans + (lcm*inv(a[i])%mod)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2816
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long n = vs[0];
			long k = vs[1];
			int[][] town = new int[2][];
			town[0] = Console.ReadLine().Split().Select(int.Parse).ToArray();
			town[1] = new int[town[0].Length];
			for (int i = 0; i < n; i++) {
				town[1][i] = -1;
			}

			int index = 0;
			int cnt = 0;
			bool f = true;
			while (k > 0) {
				town[1][index] = cnt;
				cnt++;
				k--;

				int next = town[0][index] - 1;
				if (f && town[1][next] != -1) {
					int x = town[1][index] - town[1][next] + 1;
					//System.Diagnostics.Debug.Write($"{x} {k}->");
					k -= x * (k / x);
					//System.Diagnostics.Debug.WriteLine(k);
					f = false;
				}
				//System.Diagnostics.Debug.WriteLine($"{index + 1}({town[1][index]})->{town[0][index]}");

				index = town[0][index] - 1;
			}
			Console.WriteLine(index + 1);
		}
	}
}


Measured memory_bytes: 43836
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict



MOD = 10**9+7
FACTOR = []

def factrial(n):
  global FACTOR
  FACTOR = [1 for _ in range(n+1)]
  for i in range(1,n+1):
    FACTOR[i] = (FACTOR[i-1]*i) % MOD

def mul(a,b):
  return (a*b) % MOD

def power(a,b):
  ## 二分累乗法
  if   b==0   : return 1
  elif b==1   : return a % MOD
  elif b%2==0 : return power(a,b//2)**2 % MOD
  else        : return power(a,b//2)**2 * a % MOD

def div(a,b):
  ## MOD同士の割り算
  return mul(a,power(b,MOD-2))

## 素因数分解
def factoring(m):
  fact = defaultdict(lambda:0)
  idx = 2
  while m > idx:
    if m%idx==0:
      fact[idx] += 1
      m //= idx
    else:
      idx += 1
  fact[m] += 1
  ret = []
  for k in fact:
    ret.append(fact[k])
  return ret

def combi(a,b):
  if a<b:
    return 1
  else:
    return div(FACTOR[a], (FACTOR[b]*FACTOR[abs(a-b)])%MOD)


def main():
  N,M = map(int, input().split())
  if N == 1 or M==1:
    print(1)
  else:
    fact = factoring(M)
    factrial(N+max(fact))
    ans = 1
    for f in fact:
      ans = (ans * combi(f+N-1,N-1)) % MOD
    print(ans)


if __name__ == "__main__":
  main()

Measured memory_bytes: 44912
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
int a[100]; 
int main(){
//	ios::sync_with_stdio(false);
//	ifstream cin("data.txt");
//	freopen("data.txt", "r", stdin);
	double n, ans;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		ans += a[i]; 
	} 
	ans /= n;
	double cha = 9999999;
	int wei = n;
	for(int i = n - 1; i >= 0; i--){
		if(abs(a[i] - ans) <= cha){
			cha = abs(a[i] - ans);
			wei = i;
		}
	} 
	cout << wei << endl;
	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1) :
    for j in range(B+1) :
        for k in range(C+1) :
            if 500 * i + 100 * j + 50 * k == X :
                cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	
	int a;
	double b[100];
	double sum = 0;
	
	cin  >> a;
	syc(a,1,100);
	
	for(int i=0;i<a;i++){
		cin >> b[i];
		syc(a,1,1000);
		//cout << 1/b[i] << endl;
		sum += 1/b[i];
	}
	
	cout<< 1/sum << endl;
	
	return 0;	
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, g; cin >> n >> g;
  vector<int> p(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) cin >> p[i] >> c[i];

  int res = 1001001001;
  for (int i = 0; i < (1 << n); i++) {
    int tot = 0;
    int cnt = 0;
    int k = -1;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        cnt += p[j];
        tot += 100 * (j + 1) * p[j] + c[j];
      } else {
        k = j;
      }
    }
    if (tot >= g) {
      res = min(res, cnt);
    } else {
      int d = (g - tot + 100 * (k + 1) - 1) / (100 * (k + 1));
      if (d >= p[k]) continue;
      res = min(res, cnt + d);
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

int D, T, S;

int main()
{
	cin >> D >> T >> S;
	int cnt = (D / S) + (D % S > 0);
	if(cnt <= T)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

Measured memory_bytes: 3616
import sys
input = sys.stdin.readline
n, x = map(int,input().split())
a = [int(i) for i in input().split()]
ans = max(0,a[0]-x)
now = max(0,a[0]-x)
for i in range(n-1):
  m = a[i]+a[i+1]-now
  if m <= x:
    now = 0
  else:
    now = m - x
    ans += now
    
print(ans)

Measured memory_bytes: 14416
import sys
n=int(input())
a=list(map(int,input().split()))
max=-sys.maxsize-1
min=sys.maxsize
sum=0
for i in range(n):
	sum+=a[i]
	if a[i]>max:
		max=a[i]
	if a[i]<min:
		min=a[i]
print(str(min)+" "+str(max)+" "+str(sum))


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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

set<int> G[205];
int vis[205];
bool deu = true;

void dfs(int v, int c) {
	vis[v] = c;

	c = c == 1 ? 2 : 1;
	for(int x : G[v]) {
		if(vis[x] && vis[x] != c)
			deu = false;
		else if(!vis[x])
			dfs(x, c);
	}
}

int bfs(int v, int n) {
	queue<int> Q;
	memset(vis, -1, sizeof vis);

	Q.push(v);
	vis[v] = 0;
	while(!Q.empty()) {
		int x = Q.front();
		Q.pop();

		for(int u : G[x]) {
			if(vis[u] == -1) {
				vis[u] = vis[x]+1;
				Q.push(u);
			}
		}
	}

	int ret = 0;
	for(int i = 0; i < n; i++)
		ret = max(ret, vis[i]);

	return ret+1;
}

int main() {
    int n;
    char s[205];

    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
    	scanf(" %s", s);
    	for(int j = 0; j < n; j++) {
    		if(s[j] == '1') {
    			G[i].insert(j);
    			G[j].insert(i);
    		}
    	}
    }

    dfs(0,1);

    if(!deu) {
    	printf("-1\n");
    	return 0;
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
    	ans = max(ans, bfs(i, n));
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int H,W;
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		H=scan.nextInt();
		W=scan.nextInt();
		if((H==0) && (W==0))break;
		for(int i=0;i<H;i++)
		    {
		
			for(int j=0;j<W;j++)
			    {
				if((i%2==0) && (j%2==0) || (i%2!=0) && (j%2!=0))System.out.print("#");
				else System.out.print(".");
			    }
			System.out.println();
		    }
		System.out.println();
	    }
    }
}

Measured memory_bytes: 26948
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A9x9 solver = new A9x9();
        solver.solve(1, in, out);
        out.close();
    }

    static class A9x9 {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int a = s.nextInt();
            int b = s.nextInt();
            if (a <= 9 && b <= 9) {
                out.println(a * b);
            } else {
                out.println(-1);
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

struct dsu0 {
    vector<int> par, siz;
    int n;
    int cc;
    int largest;
    void init(int n) {
	assert(n>0);
	this->n=n;
	cc=n;
	par.resize(n+10);siz.resize(n+10);
	for (int i=0; i<n; i++) par[i]=i,siz[i]=1;
	largest=1;
    }
    int parent(int x) {
	assert(x>=0 && x<n);
	return par[x]==x?x:par[x]=parent(par[x]);
    }
    bool join(int x, int y) {
	x=parent(x);y=parent(y);
	if (x==y) return false;
	cc--;
	if (siz[x]<siz[y]) swap(x,y);
	siz[x]+=siz[y];par[y]=x;
	largest=max(largest,siz[x]);
	return true;
    }
};

int n, m;

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

    cin>>n>>m;
    dsu0 dsu;
    dsu.init(n);
    while (m--) {
	int a,b;
	cin>>a>>b;
	--a;
	--b;
	dsu.join(a,b);
    }

    cout<<dsu.largest<<endl;
    
    
    return 0;
}


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

int main(){
    int n,ans;
    ans=1;
    cin>>n;
    string s;
    cin>>s;
    for(int i=1;i<n;i++){
        if(s.at(i-1)!=s.at(i)){
            ans+=1;
        }
    }
    cout<<ans<<endl;
   
            
        
}


Measured memory_bytes: 512
#include <stdio.h>

#define INF 100000000

#define DIR_UP		0
#define DIR_RIGHT	1
#define DIR_DOWN	2
#define DIR_LEFT	3

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

/* [y][x[dir]][next_dir] */
int node_cost[30][30][4];
int node_rinsetu_cost[30][30][4][4];
int kakutei[30][30][4];

int w,h;
int board[30][30];
int c[4];

int getboard(int y,int x) {
	if(y<0 || y>=h || x<0 || x>=w)return 5;
	return board[y][x];
}

int main(void) {
	int i,j,k,l;
	int nx,ny,nd;
	int ans;
	for(;;) {
		scanf("%d%d",&w,&h);
		if(w==0 && h==0)break;
		for(i=0;i<h;i++) {
			for(j=0;j<w;j++)scanf("%d",&board[i][j]);
		}
		for(i=0;i<4;i++)scanf("%d",&c[i]);
		for(i=0;i<h;i++) {
			for(j=0;j<w;j++) {
				for(k=0;k<4;k++) {
					node_rinsetu_cost[i][j][k][k]=c[0];
					node_rinsetu_cost[i][j][k][(k+1)%4]=c[1];
					node_rinsetu_cost[i][j][k][(k+2)%4]=c[2];
					node_rinsetu_cost[i][j][k][(k+3)%4]=c[3];
					if(board[i][j]!=4) {
						node_rinsetu_cost[i][j][k][(k+board[i][j])%4]=0;
					}
				}
			}
		}
		for(i=0;i<h;i++) {
			for(j=0;j<w;j++) {
				for(k=0;k<4;k++) {
					node_cost[i][j][k]=INF;
					kakutei[i][j][k]=0;
				}
			}
		}
		node_cost[0][0][DIR_RIGHT]=0;
		nx=ny=0;nd=DIR_RIGHT;
		kakutei[0][0][DIR_RIGHT]=1;
		for(i=0;i<w*h*4;i++) {
			int mincost=INF;
			for(j=0;j<4;j++) {
				if(getboard(ny+dy[j],nx+dx[j])!=5) {
					if(node_cost[ny+dy[j]][nx+dx[j]][j]>
							node_cost[ny][nx][nd]+node_rinsetu_cost[ny][nx][nd][j]) {
						node_cost[ny+dy[j]][nx+dx[j]][j]=
							node_cost[ny][nx][nd]+node_rinsetu_cost[ny][nx][nd][j];
					}
				}
			}
			for(j=0;j<h;j++) {
				for(k=0;k<w;k++) {
					for(l=0;l<4;l++) {
						if(!kakutei[j][k][l] && node_cost[j][k][l]<mincost) {
							ny=j;
							nx=k;
							nd=l;
							mincost=node_cost[j][k][l];
						}
					}
				}
			}
			kakutei[ny][nx][nd]=1;
		}
		ans=INF;
		for(i=0;i<4;i++) {
			if(node_cost[h-1][w-1][i]<ans)ans=node_cost[h-1][w-1][i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int64_t ans = 0;
  rep(i,N){
    if((i+1) % 3 == 0 || (i+1) % 5 == 0){
      continue;
    }
    ans += i + 1;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3628
<?php

$n = (int)trim(fgets(STDIN));
$s = trim(fgets(STDIN));
$stack = new SimpleStack();

for ($i=0; $i < $n; $i++) { 
	$tmp = $s[$i];
	if ($tmp === '(') {
		$stack->push($tmp);
	}else{
		if ($stack->isEmpty()) {
			$stack->push('()');
		}else{
			$new = '';
			while (true) {
				$prev = $stack->pop();
				if ($prev === '(') {
					$stack->push('(' . $new . ')');
					break;
				}else{
					$new = $prev . $new;
					if ($stack->isEmpty()) {
						$stack->push('(' . $new . ')');
						break;
					}
				}
			}
		}
	}
	// $stack->printData();
}
$result = '';
while (!$stack->isEmpty()) {
	$v = $stack->pop();
	if ($v === '(') {
		$result = '(' . $result . ')';
	}else{
		$result = $v . $result;
	}
}
echo $result;



/**
 * 
 */
class SimpleStack
{
	private $idx = 0;
	private $data =[];

	function push($v)
	{
		$this->idx += 1;
		$this->data[$this->idx] = $v;
	}
	function pop(){
		$d = null;
		if (!$this->isEmpty()) {
			$d = $this->data[$this->idx];
			$this->idx -= 1;
		}
		return $d;
	}
	function isEmpty(){
		return !($this->idx > 0);
	}

	function printData(){
		echo 'idx: ' . $this->idx . '  ' . implode(', ', $this->data) . PHP_EOL;
	}
}

Measured memory_bytes: 4728
#include <iostream>

using namespace std;

int main()
{
    string s;
    int cost = 700;
    cin >> s;
    for (int i = 0 ; i < 3 ; i++){
        switch (s[i]){
        case 'o':
            cost += 100;
            break;
        case 'x':
            cost += 0;
            break;
        }
    }
    cout << cost;
    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>

const int MAXS = 12;

char s[MAXS];

int main() {
    scanf("%s", s);
    int len = strlen(s);

    bool ans = false, lower = true;
    if (s[0] == 'A') for (int i = 1; i < len; i++) {
        if (i > 1 && i < len - 1 && !ans && s[i] == 'C') ans = true;
        else if ('A' <= s[i] && s[i] <= 'Z') lower = false;
    }

    puts(ans && lower ? "AC" : "WA");
    
    return 0;
}

Measured memory_bytes: 128
n,a,b = gets.split.map(&:to_i)

if (b-a).even?
  puts (b-a)/2
else
  if a-1 < n-b # 前
    diff = a-1
    puts diff+1 + (b-diff-1 - 1)/2
  else
    diff = n-b # 後ろ
    puts diff+1 + (b+diff - (a+diff+1))/2
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a[3];
    long long now=0,ans=0;
    for(int i=0;i<3;i++){
        cin>>a[i];
        if(a[i]=='R'){
            now++;
        }
        else{
            ans=max(ans,now);
            now=0;
        }
    }
    cout<<max(ans,now)<<endl;
    return 0;
}

Measured memory_bytes: 3580
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,sum;
        int[] A = new int[100];
        int[][] B = new int[100][100];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);
        }
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                B[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[1];i++){
            A[i] = Integer.parseInt(in.readLine());
        }
        for(i=0;i<n[0];i++){
            sum=0;
            for(j=0;j<n[1];j++){
                sum+=B[i][j]*A[j];
            }
            System.out.println(sum);
        }
        System.out.flush();
    }
}

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

int gcd(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(y>0){
    int r=x%y;
    x=y;
    y=r;
  }
  return x;
}

int main(){
  int x,y;
  cin >> x >> y;
  cout << gcd(x,y) << endl;

  return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <functional>
using namespace std;

int main() {
	long long A, B;
	cin >> A >> B;
	cout << A - B + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int X; cin >> X;
    int y=0;
    int hour;
    for (hour=1; y<X; hour++){
        y+=hour;
    }
    cout << hour-1 << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
k=[input().split() for i in range(n)]
ans=0
for i in range(1,m+1):
 kari=0
 for s in range(n):
  if str(i) in k[s][1:]:
   kari+=1 
 if kari==n:
  ans+=1
print(ans)





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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> Ball(N,1);
  vector<bool> Red(N,false);
  Red[0] = true;
  
  for (int i = 0; i < M; i++) {
    int F, T;
    cin >> F >> T;
    F--; T--;
    Ball[F] -= 1;
    Ball[T] += 1;
    if (Red[F]) {
      Red[T] = true;
      if (Ball[F] == 0) Red[F] = false;
    }
  }
  
  int c = 0;
  for (int i = 0; i < N; i++) {
    if (Red[i]) c += 1;
  }
  cout << c << endl;
}

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

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

  int n;
  cin >> n;
  int a[100010];
  rep(i, n) cin >> a[i];

  sort(a, a+n);

  vector <int> l;
  ll ans = 0;

  if (n%2 == 0) {
    l = {1, -1};
    rep(i, (n-2)/2) l.push_back(2);
    rep(i, (n-2)/2) l.push_back(-2);
    sort(l.begin(), l.end());
    rep(i, n) ans += a[i] * l[i];
  } else {
    l = {1, 1};
    rep(i, n/2) l.push_back(-2);
    rep(i, n/2-1) l.push_back(2);
    sort(l.begin(), l.end());
    rep(i, n) ans += a[i] * l[i];

    ll cnt = 0;
    l = {-1, -1};
    rep(i, n/2) l.push_back(2);
    rep(i, n/2-1) l.push_back(-2);
    sort(l.begin(), l.end());
    rep(i, n) cnt += a[i] * l[i];

    ans = max(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1276
//C
//#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>


#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Hang in there!

using namespace std;


int main() {
	int D;
	cin >> D;
	if (D == 25) {
		cout << "Christmas";
	}
	else {
		cout << "Christmas";
		for (int i = 0; i < 25 - D; i++) {
			cout << " " << "Eve";
		}
	}
	cout << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v)   v.begin(),v.end()
#define all(v) v.begin(),v.end()
#define meow ios::sync_with_stdio(0);cin.tie(0);

typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
    meow;
    ll i,n,j,cnt=0,k;
    cin>>n;
    for(i=0;i<=n;i++){
        string str;
        ///str=stream(n);
         ///str=to_string(n);
       str=to_string(i);
        if(str.size()%2==1){
            cnt++;
        }
    }
    cout<<cnt-1<<endl;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, M;
        cin >> N >> M;

        N = N % M;
        Int ans = min(N, abs(N - M));

        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
//ダイクストラ
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    REP(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    REP(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    vector<graph> g;
    for(int i=0;i<n;i++){
        graph temp(n);
        g.push_back(temp);
    }
    vector<pair<int,int> > v;
    vector<int> c; 
    for (int i = 0; i < m; i++)
    {
        int tempa, tempb, tempc;
        cin >> tempa>>tempb>>tempc;
        for(int j=0;j<n;j++){
            g[j].add_edge(tempa-1,tempb-1,tempc);
            g[j].add_edge(tempb-1,tempa-1,tempc);
        }
        v.push_back(make_pair(tempa-1,tempb-1));
            c.push_back(tempc);
    }
    for(int j=0;j<n;j++){
            g[j].dijkstra(j);
        }
    vector<bool> used(m,false);
    int ans=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(abs(g[j].d[v[i].first]-g[j].d[v[i].second])==c[i]){
                used[i]=true;
                break;
            }
            if(j==n-1)
            ans++;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

void run(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=c-a;
    int y=d-b;
    cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x<<endl;
}

signed main(){
    cout<<fixed;
    run();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int i = 1;
	int a = 1;//0~3
	int n;
	int x;
	
	scanf("%d", &n);
	
	do {
		if(a == 1) {
			//check num
			x = i;
			if(x%3 == 0) {
				printf(" %d", i);
				a = 3;
			} else {
				a = 2;
			}
		} else if(a == 2) {
			//include3
			if(x%10 == 3) {
				printf(" %d", i);
				a = 3;
			} else {
				x /= 10;
				if(x) {
					a = 2;
				} else {
					a = 3;
				}
			}
		} else if(a == 3) {
			//end check num
			if(++i <= n) {
				a = 1;
			} else {
				printf("\n");
				a = 0;
			}
		}
	} while(a != 0);
	
	return 0;
}

Measured memory_bytes: 600
def solve(n, a, b):
    total = sum(b) - sum(a)
    num1, num2 = 0, 0
    for i in range(n):
        if a[i] > b[i]:
            num1 += a[i] - b[i]
        elif a[i] < b[i]:
            num2 += (b[i] - a[i] + 1) // 2
    return "Yes" if (total >= num1) and (total >= num2) else "No"

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))

Measured memory_bytes: 4596
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;


int main()
{
	int N; cin >> N;
	vec degree(N,0);
	vector<lst> Edge(N);
	for(int i=0;i<N-1;++i)
	{
		int a, b; cin >> a >> b;
		--a; --b;
		Edge[a].emplace_back(b);
		Edge[b].emplace_back(a);
	}

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

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

	int ans = 0;
	for(int i=0;i<N-1;++i)
	{
		ans += A[i];
	}
	cout << ans << endl;

	lst Q;
	vec used(N, 0);
	Q.push_back(0);
	used[0] = 1;
	int j = N;

	while(!Q.empty())
	{
		int v = Q.front(); Q.pop_front();
		used[v] = A[--j];
		for (auto & u : Edge[v])
		{
			if (used[u] == 0)
			{
				Q.push_back(u);
			}
		}
	}

	for (int i = 0; i < N; ++i)
	{
		cout << used[i] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
const int MAX = (1e5)+1;

int n, dsu[MAX];
long long ans;
vector<pair<int,int> > x, y;
priority_queue<pair<int, pair<int,int> > > pq;
int root(int v) { return (dsu[v] < 0 ? v : dsu[v] = root(dsu[v])); }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	fill(dsu, dsu+n, -1);
	for(int i = 0, xx, yy; i < n; i++) {
		cin >> xx >> yy;
		x.emplace_back(xx-1, i);
		y.emplace_back(yy-1, i);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	for(int i = 0; i < n-1; i++) {
		pq.emplace(x[i].first-x[i+1].first, make_pair(x[i].second, x[i+1].second));
		pq.emplace(y[i].first-y[i+1].first, make_pair(y[i].second, y[i+1].second));
	}
	while(!pq.empty()) {
		int u, v, w;
		w = pq.top().first;
		tie(u, v) = pq.top().second;
		pq.pop();
		if((u = root(u)) == (v = root(v))) continue;
		if(dsu[u] > dsu[v]) swap(u, v);
		dsu[u] += dsu[v];
		dsu[v] = u;
		ans -= w;
	}
	cout << ans;
}

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

using namespace std;

const int MAXN = 100000;
int A[MAXN+1];

int main()
{
    int n,k, mn = MAXN;
    scanf("%d%d",&n,&k);

    for(int i=1;i<=n;i++)
        scanf("%d",&A[i]);
    int pos;
    for(int i=1;i<=n;i++)
    if(A[i]==1)pos = i;

    for(int i=0;i<k;i++){
        int sum = ((pos-(i+1))+k-2)/(k-1);
        sum+=(n-pos+i+k-2)/(k-1);
        mn = min(mn,sum);

    }

    printf("%d",mn);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int main(){
	char ch;
	int checker[26] = {};
	while (cin >> ch){
		if (ch == '\n'){
			break;
		}
		ch = tolower(ch);
		if (isalpha(ch)){
			checker[ch - 'a']++;
		}
	}
	for (int i = 0; i < 26; i++){
		printf("%c : %d\n", i + 'a', checker[i]);
	}
	return 0;
}

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

int main() {
	int n;
	std::cin >> n;
	double a[50];
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for (int i = n; i > 1; i--) {
		for (int j = 0; j < i - 1; j++) {
			if (a[j] > a[j + 1]) {
				double temp = a[j];
				a[j] = a[j + 1];
				a[j + 1] = temp;
			}
		}
	}
	for (int i = 0; i < n - 1; i++) {
		a[i + 1] = (a[i] + a[i + 1]) / 2;
	}
	std::cout << a[n - 1] << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<cmath>
#define LL long long
using namespace std;
inline void read(LL &x){
	x=0;int f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();	}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x*=f;
}
LL n;
LL a[100100];
LL b[100100];
LL sum;
int main()
{
	read(n);
	for(int i=1;i<=n+1;i++) read(a[i]);
	for(int i=1;i<=n;i++) read(b[i]);
	for(int i=n;i>=1;i--)
	{
		if(a[i+1]<=b[i])
		{
			sum+=a[i+1];
//			sum+=a[i+1];
			b[i]-=a[i+1];
			a[i+1]=0;
		}
		else
		{
			sum+=b[i];
	    	a[i+1]-=b[i];
			b[i]=0;
		}
		
		if(a[i]<=b[i])
		{
			sum+=a[i];
			b[i]-=a[i];
			a[i]=0;
		}
		else
		{
			sum+=b[i];
			a[i]-=b[i];
			b[i]=0;
		}
	}
    printf("%lld",sum);
	return 0;	
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define MAXN 101
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll N, W, w[MAXN], v[MAXN], dp[MAXN][100005];
int main(){
    //freopen("data.txt","r",stdin);
    cin >> N >> W;
    for (int i = 1; i<=N; i++){
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i<=N; i++){
        for (int j = 0; j<=W; j++){
            if (w[i]>j){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 78336
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
using namespace std;

int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	map<int, int> input;
	for (int i = 0; i < M; i++) {
		int s, c;
		scanf("%d %d", &s, &c);
		if (N > 1 && s == 1 && c == 0) {
			printf("-1\n");
			return 0;
		}
		if (input.find(s) != input.end() && input[s] != c) {
			printf("-1\n");
			return 0;
		}
		input[s] = c;
	}
	for (int i = 1; i <= N; i++) {
		if (N > 1 && i == 1) {
			if (input.find(1) != input.end()) {
				cout << to_string(input[1]);
			} else {
				cout << 1;
			}
		} else {
			cout << to_string(input[i]);
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3744
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int g = 0;
        int x = 0;
        int y = 0;
        while (n != 0) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = scanner.nextInt();
            }
            for (int s = 0; s < n; s++) {
                g = g + a[s];
            }
            x = g / n;
            for (int s = 0; s < n; s++) {
                if (a[s] <= x) {
                    y = y + 1;
                }
            }
            System.out.println(y);
            n = scanner.nextInt();
            g = 0;
            x = 0;
            y = 0;
        }
    }
}



Measured memory_bytes: 58884
import sys
c = int (input())
words = []
No=" "
for i in range (c) :
    words.append(input())
for x in range(len(words)-1):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 


if No != "No":
     print ("Yes")

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int a;
std::string s;
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> a >> s;

    if (a >= 3200)
        std::cout << s << std::endl;
    else
        std::cout << "red" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main() {
    int n;
    cin >> n;
    map<char, long long> mp;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        mp[s[0]]++;
    }
    long long result = 0;
    char march[5] = {'M', 'A', 'R', 'C', 'H'};
    for (int i=0; i<3; i++) {
        for (int j=i+1; j<4; j++) {
            for (int k=j+1; k<5; k++) {
                result += mp[march[i]]*mp[march[j]]*mp[march[k]];
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3636
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]

gr = {i:[] for i in range(2 * n)}
for i in range(n):
    ai, bi = ab[i]
    for j in range(n):
        cj, dj = cd[j]
        if ai < cj and bi < dj:
            gr[i].append(n + j)
            gr[n + j].append(i)

ans = 0
ab = list(reversed(sorted(ab)))
cd = list(sorted(cd))
used = [False for _ in range(2 * n)]
match = [-1 for _ in range(2 * n)]

def dfs(v):
    global used, n, gr, match
    used[v] = True
    for u in gr[v]:
        w = match[u]
        if w < 0 or (not used[w] and dfs(w)):
            match[v] = u
            match[u] = v
            return True
    return False

for v in range(2 * n):
    if match[v] < 0:
        used = [False for _ in range(2 * n)]
        if dfs(v):
            ans += 1

print(ans)

Measured memory_bytes: 42204
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))


from bisect import bisect_right as br
def main():
    dic = {}
    for i in range(1,N + 1):
        A[ i ] += A[ i - 1 ]
    for j in range(N + 1):
        if (A[j] - j)%K in dic:
            dic[(A[j] - j)%K].append(j)
        else:
            dic[(A[j] - j)%K] = [j]

    ans = 0
    
    for i in range(1,N + 1):
        tmp = dic[(A[i] - i)%K]
        left = br(tmp,i - K)
        right = br(tmp,i) - 1
        ans += right - left
    print(ans)
    return 

if __name__ == "__main__":
    main()

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

bool func(int a, int b, int sum)
{
	for (int i = 0; a * i <= sum; i++)
	{
		if ((sum - a * i) % b == 0)
		{
			return true;
		}
	}
	return false;
}

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

	/*
100A+100B+C+D<=F
(A+B)*E>=C+D

*/
	int A, B, C, D, E, F;
	int water, sugar;
	double dense;
	scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
	double max_dense = 0;
	double max_dense_water = 100 * A;
	double max_dense_sugar = 0;

	for (water = 0; water <= F; water += 100)
	{
		dense = 0;
		if (!func(A * 100, B * 100, water))
		{
			continue;
		}
		for (sugar = min(F - water, water / 100 * E); sugar >= 0; sugar--)
		{
			if (func(C, D, sugar))
			{
				dense = (double)sugar / (double)(sugar + water);
				break;
			}
		}
		if (dense > max_dense)
		{
			max_dense = dense;
			max_dense_water = water;
			max_dense_sugar = sugar;
		}
		// if (max_dense == (double)E / (double)(100 + E))
		// {
		// 	break;
		// }
	}

	cout << max_dense_water + max_dense_sugar << " " << max_dense_sugar;
	return 0;
}

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

int main()
{
    string s;
    int i,j,m;

    cin>>s;

    for(i=0;i<s.size();i++)
    {
        if(s[i]=='R' && s[i+1]=='R' && s[i+2]=='R')
        {
            cout<<3<<endl;
            return 0;
        }

        else if(s[i]=='S' && s[i+1]=='S' && s[i+2]=='S')
        {
            cout<<0<<endl;
            return 0;
        }

        else if(s[i]=='R' && s[i+1]=='R')
        {
            cout<<2<<endl;
            return 0;
        }
    }

    cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3620