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

using namespace std;
#define MV 10000
#define INF 1e9

struct edge{int to,cost;};
vector <edge> G[MV];
bool used[MV];
int V,E;
int d[MV];
int prim(){
  
  for(int i = 0;i < V;i++){
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;
  used[0] = true;
  
  for(int i = 0;i < G[0].size();i++)
    d[G[0][i].to] = G[0][i].cost;

  int num = 0;

  while(true){
    int m = -1;
    for(int i = 0;i < V;i++){
      if(used[i] == false && (m == -1 || d[m] > d[i]))
	m = i;
    }
    if (m == -1)
      break;
    used[m] = true;
    num += d[m];
    for(int i = 0;i < G[m].size();i++)
      d[G[m][i].to] = min(d[G[m][i].to],G[m][i].cost);
  }
  return num;
}

int main(){
  int first;
  cin >> V >> E;
  for(int i = 0;i < E;i++){
    int f,t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    /*
      G[f]??????f????????§????????????????´???????????????????
     */
    t = e.to;
    
    e.to = f;
    G[t].push_back(e);
  }

  int fl = prim();
  cout << fl << endl;
  
  
}

Measured memory_bytes: 6032
#include <iostream>
#include<string.h>
using namespace std;
string A; 
void cs()
{
	cin>>A;
	long long n=A.length();
	int *ans=new int[n+10];
	memset(ans,0,sizeof(ans));
	int i1=1,re=n,i2=0;
	for(int i=0;i<n-1;i++)
	{
		i2=i;i1=i+1;
		while(A[i2]=='S'&&A[i1]=='T')
		{
			re=re-2;ans[i2]=ans[i1]=1;
			while(ans[i2]==1&&i2>0)
			{
				i2--;
			}
			if(i2==0)
			{
				if(ans[0])
				{
					i2=i1+1;
					i1=i1+2;
				}else
				{
					i2=0;
					i1=i1+1;
				}
			}else
			{
				i1=i1+1;
			}
			i=i1-1;
		}

	}
	cout<<re<<endl;
}

int main(int argc, char** argv) 
{
    cs(); 
	return 0;
}

Measured memory_bytes: 1412
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

LL f(LL b, LL n, int& e){
	LL ret=0;
	e=0;
	while(n){
		ret+=n%b;
		n/=b;
		e++;
	}
	return ret;
}
int main() {
	LL n,s;
	cin >> n >> s;
	for(LL b=2;b<=n+1;b++){
		int e;
		LL v=f(b,n,e);
		if(v==s){
			cout << b << endl;
			return 0;
		}
		if(e!=2){
			continue;
		}

		LL r=n/b;
		LL u=n/r;
		if((n-s+r)%r==0){
			LL v=(n-s+r)/r;
			if(b<=v&&v<=u){
				cout << v << endl;
				return 0;
			}
		}
		b=u;
	}
	cout << -1 << endl;

	return 0;
}



Measured memory_bytes: 256
from bisect import bisect

A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF]
t = [-INF]
for _ in range(A):
    s.append(int(input()))
s.append(INF)
for _ in range(B):
    t.append(int(input()))
t.append(INF)
x = list(map(int, (input() for _ in range(Q))))
for y in x:
    i = bisect(s, y)
    j = bisect(t, y)
    ans = INF
    for S in [s[i - 1], s[i]]:
        for T in [t[j - 1], t[j]]:
            d1, d2 = abs(S - y) + abs(T - S), abs(T - y) + abs(S - T)
            ans = min(ans, d1, d2)
    # ans = min(
    #     max(abs(s[i] - y), abs(t[j] - y)),
    #     max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
    #     2 * min(abs(s[i] - y), abs(t[j - 1] - y)) + max(abs(s[i] - y), abs(t[j - 1] - y)),
    #     2 * min(abs(s[i - 1] - y), abs(t[j] - y)) + max(abs(s[i - 1] - y), abs(t[j] - y))
    # )
    print(ans)

Measured memory_bytes: 16168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int W = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(b >= a) {
			if(b - (a + W) > 0) {
				System.out.println(b - (a + W));
			} else {
				System.out.println(0);
			}
		} else {
			if(a - (b + W) > 0) {
				System.out.println(a - (b + W));
			} else {
				System.out.println(0);
			}
		}
	}
}


Measured memory_bytes: 35672
// Author : harry
// Language : C++ (GNU C++ 11)
// Upload :
// Time : 2018.9
// Problem :
// All rights reserved

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i,a,b)    for (int (i)=(a);(i)<=(b);(i)++)
#define Rep(i,a,b)    for (int (i)=(a)-1;(i)<(b);(i)++)
#define REP(i,a,b)    for (int (i)=(a);(i)>=(b);(i)--)
#define reg(i,x)      for (int (i)=head[x];(i);i=e[i].next)
#define lowbit(x)     ((x)&(-(x)))
#define ull           unsigned long long
#define ls            ((x)<<1)
#define rs            ((x)<<1|1)
#define ll            long long
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define P             pair<int,int>

const int N = 100010 ;
const int iinf = INT_MAX ;
const ll linf = LONG_MAX ;
const int MOD = 1e9+7 ;

inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

void write(int x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> vs(n);
    for (auto &v:vs) cin>>v;
    ll min_val=10000000000000ll;
    for (int i=0;i<n-(k-1);i++){
        ll dist=min(abs(vs[i]),abs(vs[i+k-1]))+vs[i+k-1]-vs[i];
        min_val=min(min_val,dist);
    }
    cout<<min_val<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {

    int a;
    int b;
    int d;
    int r;
    double f;
    
    scanf("%d %d", &a, &b);

    d = a / b;
    r = a % b;
    f = (double)a / b;

    printf("%d %d %.5f\n", d, r, f);

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j) for(int i=0;i<j;i++)
int main()
{
	long long N,cnt=0;
	scanf("%lld",&N);
	string S[200000];
    char T[10];
	static map<string,long long> m;
	rep(i,N){
		scanf("%s",T);
      sort(T,T+10);
        m[T]++;
	    cnt+=m[T]-1;
	}
	printf("%lld\n",cnt);
	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
using namespace std;
int main(){
    int a,b,h,i=3;
    cin>>a>>b>>h;
    if(a+b==h||a+h==b||b+h==a){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
 
int N, M;
vector<int> G[1010];
int came[1010];
int finish[1010];
vector<int> dat;
bool cycle = false;
bool con[1010];
int st;
 
void dfs(int v){
    if(cycle) return;
 
    came[v] = true;
    dat.push_back(v);
 
    for(auto& u : G[v]){
        if(!came[u]) dfs(u);
 
        if(cycle) return;
 
        if(came[u] && !finish[u]){
            st = u;
            cycle = true;
            return;
        }
    }
    finish[v] = true;
    if(cycle) return;
    dat.pop_back();
 
    return;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    for(int i = 1; i <= N; i++){
        if(!came[i]) dfs(i);
    }
 
    if(dat.size() == 0){
        cout << -1 << endl;
        return 0;
    }
    for(auto it = dat.begin(); it < dat.end(); it++){
        if(*it == st){
            dat.erase(dat.begin(), it);
            break;
        }
    }
    for(auto& u : dat) con[u] = true;
 
    while(true){
        dat.push_back(dat[0]);
        
        int s = 0, t = 0;
        bool flag = false;
        for(int i = 0; i < dat.size() - 2; i++){
            for(auto u : G[dat[i]]){
                if(dat[i + 1] == u) continue;
                if(con[u]) s = dat[i], t = u;
            }
        }
        if(s == 0 && t == 0) break;
        vector<int> dat2 = {t};
        while(true){
            for(auto u : G[t]){
                if(con[u]){
                    dat2.push_back(u);
                    t = u;
                    break;
                }
            }
            if(t == s) break;
        }
        dat = dat2;
        for(int i = 1; i <= N; i++) con[i] = false;
        for(auto& u : dat) con[u] = true;
    }
    cout << dat.size() - 1 << endl;
    for(int i = 0; i < dat.size() - 1; i++) cout << dat[i] << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
from itertools import accumulate

input = sys.stdin.readline


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

    cumsum_A = list(accumulate(A))
    sum_A = sum(A)

    ans = float("inf")
    for i in range(N - 1):
        # cost = abs((sum_A - cumsum_A[i]) - cumsum_A[i])
        cost = abs(sum_A - 2 * cumsum_A[i])
        if cost < ans:
            ans = cost

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25748
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007LL
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	if(exponent<0) exponent+=MOD-1;
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
string s;
bool flag=false;
vector<int> v[MAX];
int visited[MAX][4];
void DFS(int n,int p)
{
	if(visited[n][p]==2)
		return;
	if(visited[n][p]==1)
	{
		flag=true;
		return;
	}
	visited[n][p]=1;
	if(p==0||p==3)
	{
		for(auto j:v[n])
			if(s[j]=='A')
			DFS(j,(p+1)%4);
	}
	else
	{
		for(auto j:v[n])
			if(s[j]=='B')
			DFS(j,(p+1)%4);
	}
	visited[n][p]=2;
}
int main()
{
	csl;
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int n,m;
	cin>>n>>m;
	cin>>s;
	s=" "+s;
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='A')
			DFS(i,0);
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 44476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,ct[2000]={0};
	string s;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		ct[a[i]]++;
	}
	ll st=n,e=n;
	while(1)
	{
		if(st>=0 && ct[st]==0)
		{
			cout<<st;
			break;
		}
		else if(ct[e]==0)
		{
			cout<<e;
			break;
		}
		else if(st<0)
		{
			cout<<st;
			break;
		}
		st--;
		e++;
	}
	return 0;
}

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

int main(){
  string s; cin >> s; bool flg = !(s.size() & 1);
  for(int i = 0 ; i < s.size() ; ++i) flg &= s[i] == (i & 1 ? 'i' : 'h');
  puts(flg ? "Yes" : "No"); return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int ans[1000][1000];
char grid[1000][1000];
int h,w;
#define mod 1000000007
int main()
{
   scanf("%d%d",&h,&w);
   int i,j;
   for(i=0;i<h;i++)
   scanf("%s",grid[i]);
   ans[0][0]=1;
   for(i=1;i<h;i++)
   	{
   		if(grid[i][0]=='.')
   			ans[i][0]=1;
   		else if(grid[i][0]=='#')
   			break;
   	}
   	for(i=1;i<w;i++)
   	{
   		if(grid[0][i]=='.')
   			ans[0][i]=1;
   		else if(grid[0][i]=='#')
   			break;
   	}
   	for(i=1;i<h;i++)
   		for(j=1;j<w;j++)
   		{   
   			if(grid[i][j]=='.')
   			ans[i][j]=(ans[i-1][j]+ans[i][j-1])%mod;
   		}
    printf("%d\n",ans[h-1][w-1]);
    return 0;
}

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

namespace joi2019_yo_d
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();

            bool[] land = new bool[n + 2];//浮いているならtrue
            for (int i = 0; i < n; i++) if (x[i] > 0) land[i + 1] = true;

            int now = 0;
            for (int i = 1; i <= n + 1; i++) if (land[i - 1] != land[i]) { now++; }
            int ret = now / 2; now /= 2;//初期状態での島の数

            int[] count = new int[n]; for (int i = 0; i < n; i++) count[i] = i + 1;
            Array.Sort(x, count);
            for (int i = 0; i < n; i++)
            {
                if (x[i] == 0) continue;
                int where = count[i]; land[where] = false;
                if (land[where - 1] && land[where + 1]) now++;
                else if (!land[where - 1] && !land[where + 1]) now--;
                if (i == n - 1 || x[i] != x[i + 1]) ret = Math.Max(ret, now);
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 27252
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);

using namespace std;

int main(){_
    set<string> items;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string item;
        cin >> item;
        items.insert(item);
    }
    cout << items.size() << endl;
    return 0;
}


Measured memory_bytes: 19208
import sys

N, M, L = list(map(int, input().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
Q = int(input())
st = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

inf = 10 ** 10
D = [[inf] * N for _ in range(N)]
R = {}

for a, b, c in ABC:
  a -= 1
  b -= 1
  D[a][b] = c
  D[b][a] = c
  if a not in R:
    R[a] = [[b, c]]
  else:
    R[a].append([b, c])
  if b not in R:
    R[b] = [[a, c]]
  else:
    R[b].append([a, c])

for i in range(N):
  D[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k] + D[k][j])


for i in range(N):
  for j in range(N):
    if i == j:
      D[i][j] = 0
      continue
    if D[i][j] <= L:
      D[i][j] = 1
    else:
      D[i][j] = inf

for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k] + D[k][j])

for s, t in st:
  s -= 1
  t -= 1
  if D[s][t] == inf:
    print(-1)
  else:
    print(D[s][t] - 1)


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

public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		int map[][]= new int[10][10];
		for(int i=0; i<10; i++)
			Arrays.fill(map[i], 0);
		int count=0;
		int max=0;
		while(in.hasNext())
		{
			String str[] = in.next().split(",");
			int i=Integer.valueOf(str[0]);
			int j=Integer.valueOf(str[1]);
			int size = 	Integer.valueOf(str[2]);
			if(size == 1)
			{
				if(j-1>=0)
					map[i][j-1]++;
				if(i-1>=0)
					map[i-1][j]++;
				map[i][j]++;
				if(i+1<10)
					map[i+1][j]++;
				if(j+1<10)
					map[i][j+1]++;
			}
			if(size == 2)
			{
				if(i-1>=0&&j-1>=0)
					map[i-1][j-1]++;
				if(j-1>=0)
					map[i][j-1]++;
				if(j-1>=0&&i+1<10)
					map[i+1][j-1]++;
				if(i-1>=0)
					map[i-1][j]++;
				map[i][j]++;
				if(i+1<10)
					map[i+1][j]++;
				if(i-1>=0&&j+1<10)
					map[i-1][j+1]++;
				if(j+1<10)
					map[i][j+1]++;
				if(i+1<10&&j+1<10)
					map[i+1][j+1]++;
			}
			if(size == 3)
			{
				if(i-1>=0&&j-1>=0)
					map[i-1][j-1]++;
				if(j-1>=0)
					map[i][j-1]++;
				if(j-1>=0&&i+1<10)
					map[i+1][j-1]++;
				if(i-1>=0)
					map[i-1][j]++;
				map[i][j]++;
				if(i+1<10)
					map[i+1][j]++;
				if(i-1>=0&&j+1<10)
					map[i-1][j+1]++;
				if(j+1<10)
					map[i][j+1]++;
				if(i+1<10&&j+1<10)
					map[i+1][j+1]++;
				if(j-2>=0)
					map[i][j-2]++;
				if(i-2>=0)
					map[i-2][j]++;
				if(i+2<10)
					map[i+2][j]++;
				if(j+2<10)
					map[i][j+2]++;

			}
			 count=0;
			 max=0;
			for(int a=0; a<10; a++)
				for(int b=0; b<10;b++)
				{
					if(map[a][b]==0)
						count++;
					if(max<map[a][b])
						max=map[a][b];
				}
		}
		System.out.println(count);
		System.out.println(max);
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<vector<int>, int> P;
map<vector<int>, int> checked;
queue<P> que;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v;
  FOR(i,0,9){
    int n;
    cin>>n;
    v.push_back(n);
  }
  vector<int> goal = {1,2,3,4,5,6,7,8,0};
  que.push(P(v, 0));
  checked[v] = 0;
  while(!que.empty()){
    P p = que.front();
    que.pop();
    vector<int> now = p.first;
    int dist = p.second;
    bool ok = true;
    FOR(i,0,9){
      if(now[i]!=goal[i]){
        ok = false;
        break;
      }
    }
    if(ok){
      cout << dist << endl;
      return 0;
    }
    int x, y, zero;
    FOR(i,0,9){
      if(now[i]==0){
        x = i % 3;
        y = i / 3;
        zero = i;
        break;
      }
    }
    FOR(i,0,4){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(ny<0||ny>=3||nx<0||nx>=3) continue;
      int j = 3 * ny + nx;
      vector<int> nxt = now;
      swap(nxt[zero], nxt[j]);
      if(checked.count(nxt)==0||checked[nxt] > dist + 1) {
        checked[nxt] = dist + 1;
        que.push(P(nxt, dist+1));
      }
    }
  }
}


Measured memory_bytes: 26320
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;

    vector<int> p(N);

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

    int cnt = 0;
    for (int i = 1; i < N-1; ++i)
    {        
        vector<int> c(3);
        c[0] = p[i-1];
        c[1] = p[i];
        c[2] = p[i+1];

        sort(c.begin(),c.begin()+3);

        if(p[i] == c[1] && c[0] < c[1] && c[1] < c[2]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int ans=0;
  for (int i=0; i<n; i++){
    int c;
    cin >> c;
    a.at(i) = c;
  }
  vector<int> answer(n, 1);
  for (int i=0; i<m; i++){
    int d, e;
    cin >> d >> e;
    if (a.at(d-1) <= a.at(e-1)){
      answer.at(d-1) = 0;
      if (a.at(d-1) == a.at(e-1)){
        answer.at(e-1) = 0;
      }
    }
    else{
      answer[e-1] = 0;
    }
  }
  for (int i=0; i<n; i++){
    ans += answer.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4028
import sys
import random

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
#t = [int(input()) for i in range(D)]
#M = int(input())
#Q = [list(map(int,input().split())) for i in range(M)]

def init():
    cont = 0
    last = [0]*26
    t = []
    for i in range(D):
        max_c = 0
        max_i = -1
        for j in range(26):
            if max_c < s[i][j] + c[j]*(i+1-last[j]):
                max_i = j
                max_c = s[i][j] + c[j]*(i+1-last[j])
        t.append(max_i+1)        
        cont += s[i][t[i]-1]
        last[t[i]-1] = i+1
    return t,cont

def content(t):
    cont = 0
    last = [0]*26
    for i in range(D):
        cont += s[i][t[i]-1]
        last[t[i]-1] = i+1
        for j in range(26):
            cont -= c[j]*(i+1-last[j])
    return cont

def main():
    t,prev = init()
    for i in range(6000):
        d,q = random.randint(0,D-1), random.randint(1,26)
        prev_t = t[d]
        t[d] = q
        now = content(t)
        if prev>content(t):
            t[d] = prev_t
        else:
            prev=now
    for a in t:
        print(a)


if __name__ == '__main__':
    main()





Measured memory_bytes: 87320
#include <iostream>
#include <algorithm>
using namespace std;
long long int solve(long long int a,long long int b,long long int c){
    long long int ans=abs(a-b);
    if(ans<abs(b-c))ans=abs(b-c);
    if(ans<abs(c-a))ans=abs(c-a);
    return ans;
}
int main(void){
    long long int h,w,ans=100000000000,s1,s2,s3;
    cin>>h>>w;
    //横に3分割
    for(int i=1;i<h;i++){
        s1=i*w;
        if((h-i)%2){
            s2=((h-i-1)/2)*w;
            s3=((h-i+1)/2)*w;
        }
        else{
            s2=(h-i)*w/2;
            s3=s2;
        }    
        if(ans>solve(s1,s2,s3))ans=solve(s1,s2,s3);
    }
    //縦に３分割
    for(int i=1;i<w;i++){
        s1=i*h;
        if((w-i)/2){
            s2=((w-i-1)/2)*h;
            s3=((w-i+1)/2)*h;
        }
        else{
            s2=(w-i)*h/2;
            s3=s2;
        }    
        if(ans>solve(s1,s2,s3))ans=solve(s1,s2,s3);
    }
    //横に１つ作った後に縦に分割
    for(int i=1;i<h;i++){
        s1=i*w;
        if(w%2){
            s2=(h-i)*(w-1)/2;
            s3=(h-i)*(w+1)/2;
        }
        else{
            s2=w*(h-i)/2;
            s3=s2;
        } 
        if(ans>solve(s1,s2,s3))ans=solve(s1,s2,s3);
    }
    //1縦に１つ作った後に横に分割
    for(int i=1;i<w;i++){
        s1=i*h;
        if(h%2){
            s2=(w-i)*(h-1)/2;
            s3=(w-i)*(h+1)/2;
        }
        else{
            s2=(w-i)*h/2;
            s3=s2;
        }
        if(ans>solve(s1,s2,s3))ans=solve(s1,s2,s3);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N,C = map(int, input().split())

xv = [tuple(map(int, input().split())) for _ in range(N)]

accum_clockwise = [None] * N
accum_clockwise[0] = xv[0]
tmp = xv[0][1]
for i in range(1,N):
    tmp += xv[i][1]
    accum_clockwise[i] = (xv[i][0], tmp)


accum_anticlockwise = [None] * N
accum_anticlockwise[0] = (C - xv[-1][0], xv[-1][1])
tmp = xv[-1][1]
for i in range(1, N):
    tmp += xv[N-1-i][1]
    accum_anticlockwise[i] = (C - xv[N-1-i][0], tmp)


max_clockwise = [0] * (N+1)
for i in range(N):
    max_clockwise[i+1] = max(max_clockwise[i], accum_clockwise[i][1] - accum_clockwise[i][0] * 2)


max_anticlockwise = [0] * (N+1)
for i in range(N):
    max_anticlockwise[i+1] = max(max_anticlockwise[i], accum_anticlockwise[i][1] - accum_anticlockwise[i][0] * 2)


ans_clockwise = 0
for i in range(N):
    ans_clockwise = max(ans_clockwise, accum_clockwise[i][1] - accum_clockwise[i][0] + max_anticlockwise[N-1-i])

ans_anticlockwise = 0
for i in range(N):
    ans_anticlockwise = max(ans_anticlockwise, accum_anticlockwise[i][1] - accum_anticlockwise[i][0] + max_clockwise[N-1-i])

print(max(ans_clockwise, ans_anticlockwise))


Measured memory_bytes: 47124
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        cout<<max(c-a+b,(ll)0);
    }
 
    return 0;
}

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

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

    string a, b;
    int i = 0;
    int cnt = 0;
    while (i < S.size()) {
        b = S.substr(i, 1);
        if (a == b) {
            if (i+1 == S.size()) {
                break;
            } else {
                b = S.substr(i, 2);
                cnt++;
                i += 2;
            }
        } else {
            cnt++;
            i++;
        }
        a = b;
    }
    cout << cnt << endl;
}

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

int main(){

    int a,b,c;
    cin >> a >> b >> c;

    if(a == b){
        if( a != c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if (a == c){
        if(b != c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        
        }

    }else if (b == c){
        if(a != b){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        
        }
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}




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

using namespace std;

int main() {
    long int n;
    cin>>n;
    int b[n];
    vector<int>a;
    for(auto i = 0 ; i< n ; i++){
        int t;
        cin>>t;
        a.push_back(t);
    }
    b[n-1] = 0;
    for(auto i = n-2 ; i >=0 ; i--){
        int j = i+2;
        b[i] = abs(a[i]-a[i+1]) + b[i+1];
        if(j<n){
            b[i] = min(abs(a[i]-a[j]) + b[j] , b[i]);
        }
        
    }
    cout<<b[0];

    
}

Measured memory_bytes: 4076
#include <iostream>

using namespace std;

int main(){
  int w,h,x,y,r;
  cin >>w>>h>>x>>y>>r;
  bool f;


  //x軸判定
  //x-rが0より小さい、または、x+rがwより大きい時は枠外
  if(((x-r)<0) || ((x+r)>w)){
    f=false;

  }
  //x-rが0以上かつ、x+rがw以下ならば枠内
  else if( ((x-r)>=0) && ((x+r)<=w)){
    f=true;
   }

  if(f){
    //y軸判定
    if( ((y-r)<0) || ((y+r)>h) ){ 
      f=false;
    }
    else if( ((y-r)>=0) && ((y+r)<=h)) {
      f=true;
    }
  }
  
  if(f){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }

  return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
using namespace std;
int n,k;
int a[100000];
int sum[100000];

void solve() {
  sum[0] = a[0];
  for(int i=1;i<n;i++) {
    sum[i] = sum[i-1] + a[i];
  }
  int res = sum[k-1];
  for(int i=0;i<=n-k;i++) {
    res = max(res,sum[i+k-1] - sum[i-1]);
  }
  cout << res << endl;
}

int main() {
  while(cin >> n >> k) {
    if(n==0 && k==0) break;
    for(int i=0;i<n;i++) {
      cin >> a[i];
    }
    solve();
  }
}

Measured memory_bytes: 1236
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
int INF=2e+9+1;
int main(){
	int N;
	int t[100],v[100];
	int tedge[100];
	double vmin[40001];
	double menseki=0;
	rep(i,40001){
		vmin[i]=INF;
	}
	int et=0;
	scan(N);
	rep(i,N){
		scan(t[i]);
		et+=t[i];
		tedge[i]=et;
	}
	rep(i,N){
		scan(v[i]);
	}
	rep(j,2*et+1){
		vmin[j]=min(vmin[j],(double)j/2);
		vmin[j]=min(vmin[j],(double)et-j/2.0);
	}
	rep(i,N){
		if(i){
			for(int j=2*tedge[i-1];j<=2*tedge[i];j++){
				vmin[j]=min(vmin[j],(double)v[i]);
			}
		}
		else{
			for(int j=0;j<=2*tedge[0];j++){
				vmin[j]=min(vmin[j],(double)v[0]);
			}
		}
	}
	rep(i,N){
		if(i<N-1){
			for(int j=2*tedge[i];j<=2*et;j++){
				vmin[j]=min(vmin[j],(double)(v[i]-tedge[i]+(double)j/2));
			}
		}
		if(i>0){
			for(int j=2*tedge[i-1];j>=0;j--){
				vmin[j]=min(vmin[j],(double)(v[i]+tedge[i-1]-(double)j/2));
			}
		}
	}
	/*rep(j,2*et+1){
		printf("t:%5.1f v:%6.3f\n",(double)j/2,vmin[j]);
	}*/
	rep(j,2*et){
		menseki+=(double)(vmin[j]+vmin[j+1])/4.0;
	}
	printf("%f\n",menseki);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string X;
    cin >> X;
    stack<char> S;
    int N = X.size();
    rep(i, N)
    {
        if (S.empty() or S.top() == 'T')
        {
            S.push(X[i]);
        }
        else if (S.top() == 'S')
        {
            if (X[i] == 'T')
            {
                S.pop();
            }
            else
            {
                S.push(X[i]);
            }
        }
    }
    cout << S.size();
    return 0;
}

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

int main() {
  int k, x;
  cin >> k >> x;
  int ans;
  int MIN_IDX = -1000000;
  int MAX_IDX = 1000000;
  for (int i = x - k + 1; i < x + k; i++) {
    if (i < MIN_IDX) {
      continue;
    } else if (i > MAX_IDX) {
      continue;
    } else {
      cout << i << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[][] A = new int[2][N];
		
		for(int i = 0 ; i < 2 ; i++){
			for(int j = 0 ; j < N ; j++){
				A[i][j] = scan.nextInt();
			}	
		}
		
		if(N==1){
			System.out.println(A[0][0]+A[1][0]);
		}
		else{
			int[][] dp = new int[2][N];
			dp[0][0] = A[0][0];

			
			for(int j = 0 ; j < N-1 ; j++){
				if(j==0){
					dp[j+1][0] = A[j+1][0]+dp[0][0] ;
					dp[0][j+1] = A[0][j+1]+dp[0][0] ;
				}
				else{
					dp[0][j+1] = A[0][j+1] + dp[0][j]; 
					dp[1][j] = Math.max(dp[0][j] + A[1][j], dp[1][j-1] + A[1][j]);		
				}
			}
			dp[1][N-1] = Math.max(dp[0][N-1] + A[1][N-1], dp[1][N-2] + A[1][N-1]);	
			
			System.out.println(dp[1][N-1]);
		}
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	ll h;
	cin >> h;
	ll atk = 0;
	ll k = 0;
	while (h > 1) {
		h /= 2;
		k++;
	}
	atk = pow(2, k + 1) - 1;
	cout << atk << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;




int main() {
	int a, b, c, d; 
	cin >> a >> b >> c >> d;
	if (a + b > c + d) cout << "Left" << endl;
	else if (a + b == c + d) cout << "Balanced" << endl;
	else cout << "Right" << endl;

	return 0;
}


Measured memory_bytes: 256
w, h, c = gets.chomp.split
w = w.to_i
h = h.to_i
l1 = [?+] + [?-] * (w - 2) + [?+]
l2 = [?|] + [?.] * (w - 2) + [?|]
a = [l1] + [l2] * (h - 2) + [l1]
a[h / 2] = a[h / 2].dup
a[h / 2][w / 2] = c
a.each {|r| puts r.join}


Measured memory_bytes: 8892
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  cin >> N >> M;
  vi dp(1<<N,INF);
  dp[0] = 0;
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    int key = 0;
    rep(j,b) {
      int c;
      cin >> c;
      c--;
      key |= 1<<c;
    }
    rep(j,1<<N) {
      chmin(dp[j|key],dp[j]+a);
    }
  }
  int ans = dp[(1<<N)-1];
  if(ans==INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

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

int n;
double ans;
double p[3005];
double dp[3005][3005];

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

for (int i=1;i<=n;i++){
  if (i==1){
    dp[i][0]=1-p[i];
    dp[i][1]=p[i];
  } else {
    dp[i][0]=dp[i-1][0]*(1-p[i]);
    dp[i][i]=dp[i-1][i-1]*p[i];
  }
}

for (int j=1;j<=n;j++){
  for (int i=j+1;i<=n;i++){
    dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
  }
}

ans=0;
for (int i=n/2+1;i<=n;i++){
    ans+= dp[n][i];
}
printf("%.12f",ans);
return 0;
}


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

int main() {
  int R, G, B, N, count=0;
  cin >> R >> G >> B >> N;
  int r, g;
  for (r=0; r<=N/R; r++) {
    for (g=0; g<=N/G; g++) {
      if (N - R*r - G*g == 0) count++;
      else {
        if (N - R*r - G*g > 0) {
        int amari = (N - R*r - G*g) % B;
        if (amari == 0) count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define DEV_VAL (1000000000 + 7)

int main()
{
  int n;
  cin >> n;
  int ans = 0;

  while(n > 1000)
  {
    n -= 1000;
  }

  cout << (1000 - n) << endl;


  return 0;
}

Measured memory_bytes: 3632
/**
 * Dictionary
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C
 */

#include<iostream>
#include<map>
using namespace std;

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

  string cmd, val;
  map<string, int> dic; // <key, value> と書くとkey型をキーとし、value型を値とする。
  for (int i = 0; i < n; i++) {
    cin >> cmd >> val;
    if (cmd == "insert") {
      dic[val] = 1;
    } else if (cmd == "find") {
	    cout << (dic.find(val) != dic.end() ? "yes" : "no") << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 36744
#include <stdio.h>

int main(){
	int n,i,j=-2,k,m=0,a[20],b[20],c[20];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<n-1;i++){
		scanf("%d",&c[i]);
	}
	for(i=0;i<n;i++){
		k=a[i]-1;
		m+=b[k];
		if(k==j+1){
			m+=c[j];
		}
		j=k;
	}
	printf("%d",m);
	return(0);
}

Measured memory_bytes: 128
N,M = map(int,input().split())
K = []
for i in range(N):
        A = list(map(int,input().split()))
        del A[0]
        K.append(A)
        result_list = K[0]
for j in range(1,N):
        result_list = set(result_list) & set(K[j])
        
print(len(result_list))

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

int main() {
	int x, y;
	cin >> x >> y;
	vector<int>c = { 300000,200000,100000,0 };
	if (x >= 4)x = 4;
	if (y >= 4)y = 4;
	ll ans = c.at(x - 1) + c.at(y - 1);
	if (x == 1 && y == 1)ans += 400000;
	cout << ans << endl;

}

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

#define fastio {\
    ios::sync_with_stdio(0);\
    cin.tie(0);\
}

#define file {\
    freopen("io\\in.txt", "r", stdin);\
    freopen("io\\out.txt", "w", stdout);\
    freopen("io\\err.txt", "w", stderr);\
}

#ifdef LOCAL
#define debug(args...) {\
    string _s(#args);\
    replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s);\
    istream_iterator<string> _it(_ss);\
    debug1(_it, args);\
}

#pragma GCC diagnostic ignored "-Wunused-parameter"
void debug1(istream_iterator<string> it) {
    cerr << endl;
}
#pragma GCC diagnostic pop

template<class T, class... Args>
void debug1(istream_iterator<string> it, T a, Args... args) {
    cerr << '>' << *it << " = " << a << "; ";
    debug1(++it, args...);
}
#else
#define debug(args...)
#define cerr if (false) cerr
#endif

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < n; i++)
#define dotc()      int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));

signed main() {
    fastio;
#ifdef LOCAL
    file;
#endif

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int mxx = 0;
    rep(i, h) rep(j, w) {
        if (s[i][j] == '#') continue;

        int mx = 0;
        map<ii, int> d;
        queue<ii> q;

        d[{i, j}] = 0;
        q.emplace(i, j);

        while (!q.empty()) {
            auto cur = q.front();
            int step = d[cur];
            mx = step;
            q.pop();

            for (auto& r : vii{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}) {
                int x = cur.fi + r.fi, y = cur.se + r.se;
                if (x < 0 || y < 0 || x >= h || y >= w ||
                    s[x][y] == '#' || d.count({x, y})) continue;
                
                d[{x, y}] = step + 1;
                q.emplace(x, y);
            }
        }
        
        mxx = max(mxx, mx);
    }

    cout << mxx;

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
#define MOD 1000000007 //998244353


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

    // solution comes here

    ll N;
    cin >> N;

    vector<vl> dp(N, vl(3));
    cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
    for(ll i=1; i<N; i++) {
        ll a, b, c, t=i-1;
        cin >> a >> b >> c;
        dp[i][0] = a + max(dp[t][1], dp[t][2]);
        dp[i][1] = b + max(dp[t][0], dp[t][2]);
        dp[i][2] = c + max(dp[t][1], dp[t][0]);
    }

    cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << nl;
}


Measured memory_bytes: 5760
#!/usr/bin/env python3
#D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
t = []
for i in range(n):
    t.append(int(s[i])*pow(10, (n-i-1), 2019) % 2019)
t = list(accumulate(t))
t = [0] + [i % 2019 for i in t]
ans = 0
cnt = defaultdict(int)
for i in range(n+1):
    ans += cnt[t[i]]
    cnt[t[i]] += 1
print(ans)

Measured memory_bytes: 100404
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 40
 
using namespace std;
 
int C,D,W,X;
int E[MAX][MAX];
int F[MAX][MAX];
int dp[40][60][10];//dp[D:day][W:burden][X:kurenai]
 
int main()
{
  while(scanf("%d %d %d %d",&C,&D,&W,&X),C|D|W|X)
    {  
      rep(i,C)rep(j,D)scanf("%d",&E[i][j]);
      rep(i,C)rep(j,D)scanf("%d",&F[i][j]);  
 
      rep(i,D+1)rep(j,W+1)rep(k,X+1)dp[i][j][k] = 0;
 
      rep(day,D)
    {
      rep(burden,W+1)
        {
          rep(x,X+1)
        {
          //何もしない
          dp[day+1][burden][x] = max(dp[day+1][burden][x],
                         dp[day  ][burden][x]);
 
          rep(region,C)
            {
              if(E[region][day] == 0)continue;
               
              //そこでラヴライヴ
              if(burden + F[region][day] <= W)
            {
              dp[day+1][burden+F[region][day]][x] = max(dp[day+1][burden+F[region][day]][x],
                                    dp[day][burden][x]+E[region][day]);
            }
 
              //ラブライブ！
              int cost = 0;
              int value = 0;
               
              for(int cur=region;cur>=0;cur--)
            {
              cost  += F[cur][day];
              value += E[cur][day];
              if(cur == region)continue;
              if(E[cur][day] == 0)break;
              if(burden + cost <= W && x + 1 <= X)
                {
                  dp[day+1][burden+cost][x+1] = max(dp[day+1][burden+cost][x+1],
                                dp[day  ][burden     ][x  ]+value);
                }
              else break;
            }
               
               
              cost = 0;
              value = 0;
              for(int cur=region;cur<C;cur++)
            {
              cost  += F[cur][day];
              value += E[cur][day];
              if(E[cur][day] == 0)break;
              if(cur == region)continue;
              if(burden + cost <= W && x + 1 <= X)
                {
                  dp[day+1][burden+cost][x+1] = max(dp[day+1][burden+cost][x+1],
                                dp[day  ][burden     ][x  ]+value);
                }
              else break;
            }
               
            }
 
        }
        }
    }
 
      int ans = 0;
      rep(i,W+1)rep(j,X+1)
    {
      ans = max(ans,
            dp[D][i][j]);
    }
      printf("%d\n",ans);
 
    }
  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  string s;
  cin >> s;
  s[5] = s[13] = ' ';
  cout << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3604
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt1 = 0
cnt2 = 0
for i in range(N):
    if a[i] > b[i]:
        cnt2 += a[i] - b[i]
    else:
        cnt1 += (b[i] - a[i] + 1) // 2
        cnt2 += (b[i] - a[i]) % 2

# print(cnt1, cnt2)
if cnt1 >= cnt2:
    print("Yes")
else:
    print("No")

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B;
    cin >> A >> B;
    cout << A*B << "\n";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define all(a) begin(a),end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL;
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;


int main()
{   _
    lli n; cin >> n;
    string s;
    cin >> s;
    string ss = s;
    sort(all(ss));
    int cnt = 0;
    int ccnt = 0;
    fore(i, 0, n) {
        if(s[i] != ss[i]) {
            if(s[i] == 'W') ++cnt;
            else ++ccnt;
        }
    }
    cout << min(cnt, ccnt) << ENDL;
    return 0;
}


Measured memory_bytes: 3868