akhauriyash/Code-Regression huggingface dataset:
/*#include "unp.h"
int main()
{
    int listenfd,connfd;
    pid_t childpid;
    socklen_t chilen;
    struct sockaddr_in chiaddr,servaddr;
    listenfd=Socket(AF_INET,SOCK_STREAM,0);
    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family=AF_INET;
    servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
    servaddr.sin_port=htons(SERV_PORT);
    Bind(listenfd,(SA*)&servaddr,sizeof(servaddr));
    Listen(listenfd,LISTENQ);
    for(;;)
    {
        chilen=sizeof(chiaddr);
        connfd=Accept(listenfd,(SA*)&chiaddr,&chilen);
        if((childpid=Fork())==0)
        {
            Close(listenfd);
            str_echo(connfd);
            exit(0);
        }
        Close(connfd);
    }
}*/
#include <bits/stdc++.h>
using namespace std;
string str[10];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int sum=0;
        for(int i=0; i<n; i++)
        {
            cin>>str[i];
            for(int j=0; j<m; j++) if(str[i][j]=='#') sum++;
        }
        int x=0,y=0,step=n+m-1;
        int t=1;
        if(sum!=step||str[0][0]!='#'||str[n-1][m-1]!='#')
        {
            puts("Impossible");
            continue;
        }
        while(t<step)
        {
            int l,r;
            l=r=0;
            if(y+1<m&&str[x][y+1]=='#') r=1;
            if(x+1<n&&str[x+1][y]=='#') l=1;
            if(l^r)
            {
                if(r) y+=1;
                else
                    x+=1;
            }
            else break;
            t+=1;
        }
        puts(t==step?"Possible":"Impossible");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end(), greater<int>());
  int a = 0, b = 0;
  REP(i, N) {
    if (i % 2 == 0)
      a += A[i];
    else
      b += A[i];
  }
  cout << a - b << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n=0,K=0,X=0,Y=0;
	cin>>n>>K>>X>>Y;
	if(n < K)
	cout<<X*n<<endl;
	else
	cout<<X*K+(n-K)*Y<<endl;
	return 0;
}

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

const int MOD=1e9+7;

int n,a[100001],vis[100001];
int fact[100002];
int power(int a,int p) {
    int res=1;
    while(p) {
        if(p&1) res=1ll*res*a%MOD;
        a=1ll*a*a%MOD;
        p>>=1;
    }
    return res;
}
int inv(int a) {return power(a,MOD-2);}
int comb(int n,int r) {
    if(n<r) return 0;
    else return 1ll*fact[n]*inv(fact[r])%MOD*inv(fact[n-r])%MOD;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n+1;i++) scanf("%d",a+i);

    fact[0]=1;
    for(int i=1;i<=n+1;i++) fact[i]=1ll*fact[i-1]*i%MOD;
    
    int s=-1,t=-1;
    memset(vis,-1,sizeof(vis));
    for(int i=0;i<=n;i++) {
        if(vis[a[i]]!=-1) {
            s=i; t=vis[a[i]];break;
        }
        vis[a[i]]=i;
    }
    for(int i=1;i<=n+1;i++) {
        int v=(comb(n+1,i) - comb(n-s+t, i-1) + MOD)%MOD;
        printf("%d\n",v);
    }

    return 0;
}


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

int main(void){
	char c;
	cin >> c;
	
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void QSort(int data[], int left, int right);
void Swap(int data[], int i, int j);

int main(){
  int data[100], a, i, ans[100], max=0, n=1, k, j=0;

  for(i=0;i<100;i++){
    if(scanf("%d", &data[i])==EOF) break;
  }
  a=i;
  QSort(data, 0, a-1);

  for(i=1;i<a;i++){
    if(data[i]==data[i-1]){
      n++;
    }
    else{
      n=1;
    }
    if(max<n){
      max=n;
      for(k=0;k<j;k++){
	ans[k]=0;
      }
      j=0;
      ans[j]=data[i];
    }
    else if(max==n){
      j++;

      ans[j]=data[i];
    }
  }
  for(i=0;i<j+1;i++){
    printf("%d\n", ans[i]);
  }
  return 0;
}

void QSort(int data[], int left , int right){
  int i, j, pivot;

  i=left;
  j=right;

  pivot=data[(left+right)/2];
  while(1){
    while(data[i]<pivot) i++;
    while(pivot<data[j]) j--;
    if(i>=j) break;
    Swap(data, i, j);
    i++;
    j--;
  }
  if(left<i-1) QSort(data, left, i-1);
  if(j+1<right) QSort(data, j+1, right);
}

void Swap(int data[], int i, int j){
  int temp;

  temp=data[i];
  data[i]=data[j];
  data[j]=temp;
}

Measured memory_bytes: 0
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)

//  鏡文 Mirror String.cpp
//
//  Created by WinnieJt on 2019/3/21.
//
//  Copyright © 2019 金天. All rights reserved.

//åß∂ƒ∆Ω≈µç∫πø∑¢∞§¶

#include<bits/stdc++.h>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
typedef double db;
typedef std::string str;
typedef long long ll;
using namespace std;
str s;
str f;
int main(void)
{
    std::ios::sync_with_stdio(false);
    std::cin >> s;
    f=s;
    std::reverse(s.begin(),s.end());
    for(ll i=0;i<s.length();i++)
    {
        if(s[i]=='b') s[i]='d';
        else if(s[i]=='d') s[i]='b';
        if(s[i]=='p') s[i]='q';
        else if(s[i]=='q') s[i]='p';
    }
    if(s==f) cout << "Yes" << endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

class Main{
  public static int abs(int a){
    return (a>0)?a:(-a);
  }
  
  public static int max2(int a,int b){
    return (a>b)?a:b;
  }
  
  public static int max3(int a,int b,int c){
    return (max2(a,b)>c)?max2(a,b):c;
  }
  
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int A=sc.nextInt();
    int B=sc.nextInt();
    int C=sc.nextInt();
    
    int ab=abs(A-B);
    int bc=abs(B-C);
    int ca=abs(C-A);
    
    int minus=max3(ab,bc,ca);
    
    System.out.println(ab+bc+ca-minus);
  }
}

Measured memory_bytes: 23892
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>b)System.out.println(a + a-1);
        else if(a==b)System.out.println(a+a);
        else System.out.println(b + b-1);
        
    }
  
}


Measured memory_bytes: 22740
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 5e5 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n, c, k, a[N], ans;

void solve() { 
  cin >> n >> c >> k;
  for (int i = 1;i <= n;i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1;i <= n;i++) {
    int lim = min(n, i + c - 1);
    int j = i;
    while(j < lim && a[j + 1] <= a[i] + k) {
      j++;
    }
    i = j;
    ans++;
  }
  cout << ans << endl;
}

int main() {
  #ifdef wws
   freopen("in", "r", stdin);
   // freopen("in", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 640
import math
h, w, d = list(map(int, input().split()))
grid = []
num = [[] for i in range(h*w+1)]
for i in range(h):
    grid.append(list(map(int, input().split())))
for i in range(h):
    for j in range(w):
        num[grid[i][j]]=[j+1, i+1]
k = math.ceil((h*w+1) / d)
#initialize
cost = [[0 for i in range(k)] for j in range(d)]
for i in range(d + 1,h*w+1):
    x, y = num[i]
    prex, prey = num[i - d]
    cost[i % d][i//d] = abs(prex - x) + abs(prey - y)
    cost[i % d][i//d] += cost[i % d][(i - d)// d]
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(cost[r%d][r//d] - cost[l%d][l//d])


Measured memory_bytes: 72956
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = 'z' - 'a' + 1;
        String s = in.next();
        int[] c = new int[n];
        for (int i = 0; i < s.length(); i++) {
            c[s.charAt(i) - 'a']++;
        }

        for (int i = 0; i < n; i++) {
            if (c[i] == 0) {
                out.println((char)('a' + i));
                return;
            }
        }

        out.println("None");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
long long A,B,C,S;
int main(){
    //while(1){
    cin >> A >> B >> C; S = A+B+C;
    //srand(time(0));
    //int P = rand()/999; for(int i=1; i<P; i++) S = rand();
    //A = rand(); B = rand(); C =rand(); S = A+B+C;
    //cout << endl << A << " " << B << " " << C << ":";
    if(A&1||B&1||C&1) {cout << 0; return 0;}
    if(A==B&&B==C){cout << -1; return 0;}
    for(int i=0; ; i++){
        if(A&1||B&1||C&1) {cout << i; break;}
        A = (S-A)/2; B = (S-B)/2; C = (S-C)/2;
    }
}


Measured memory_bytes: 256
a,b,k = gets.split.map(&:to_i)
arr = []
k.times do |i|
  break if a+i > b
  arr << a+i
end
k.times do |i|
  next if b - (k - 1) + i < a
  arr << b - (k-1) + i
end
puts arr.uniq

Measured memory_bytes: 1788
N, K = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)

result = 10**9

0.upto(N - K) do |i|
  left = i
  right = K - 1 + i
  time = x[left].abs + (x[right] - x[left]).abs
  result = time if time < result
  time = x[right].abs + (x[left] - x[right]).abs
  result = time if time < result
end

puts result


Measured memory_bytes: 8452
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        String S = sc.next();

        if(S.length() > K) {
            String ans = S.substring(0, K);
            System.out.println(ans +"...");
        } else {
            System.out.println(S);
        }
    }
}

Measured memory_bytes: 38496
//DEEPANSHU RAWAT
//BTECH/10530/18
//INFORMATION TECHNOLOGY

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
 */
/*************************************************************************************************************************/
#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 1000000007
#define modd 20000
using namespace std ;
/**************************************************************************************************************************/

/**************************************************************************************************************************/
int main()
    {
        ios_base::sync_with_stdio(false);//FOR FAST INPUT OUTPUT METHOD
        cin.tie(NULL);
        cout.tie(NULL);
 
        double n;
        cin>>n;
        double ans=(n/3)*(n/3)*(n/3);
        cout<<setprecision(100)<<ans;
}
       
/**************************************************************************************************************************/                            

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


int main(){
  int N;
  cin >> N;
  double sum = 0;
  for(int ii=0; ii<N; ii++){
    double x;
    string u;
    cin >> x >> u;
    sum += (u=="JPY") ? x : x * 380000;
  }
  cout << fixed << setprecision(6) << sum << endl;
  return 0;
}

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

const int maxN = 205;

int n, m, ans, now;
int f[2][maxN + 1][maxN + 1][maxN + 1], g[2][maxN + 1][maxN + 1][maxN + 1];
int r[maxN + 1][maxN + 1], d[maxN + 1][maxN + 1];
char s[maxN + 1][maxN + 1];

inline void init()
{
	for(int i = 1; i <= n; i++)
		for(int j = m; j >= 1; j--)
			r[i][j] = (s[i][j] == s[i][j + 1] ? r[i][j + 1] : j);

	for(int j = 1; j <= m; j++)
		for(int i = n; i >= 1; i--)
			d[i][j] = (s[i][j] == s[i + 1][j] ? d[i + 1][j] : i);

	for(int i = n; i >= 1; i--)
		for(int j = 1; j <= m; j++)
			for(int k = j; k <= m; k++)
				if(r[i][j] >= k && s[i][j] == s[i + 1][j] && r[i + 1][j] >= k) f[now][i][j][k] = f[now][i + 1][j][k];
				else if(r[i][j] >= k) f[now][i][j][k] = i;

	for(int i = m; i >= 1; i--)
		for(int j = 1; j <= n; j++)
			for(int k = j; k <= n; k++)
				if(d[j][i] >= k && s[j][i] == s[j][i + 1] && d[j][i + 1] >= k) g[now][i][j][k] = g[now][i + 1][j][k];
				else if(d[j][i] >= k) g[now][i][j][k] = i;
}

inline void update(int &x, int y) { x = max(x, y); }

inline void work()
{
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			for(int k = j; k <= m; k++)
			{
				if(f[now ^ 1][i][j][k]) update(f[now][i][j][k], f[now ^ 1][ f[now ^ 1][i][j][k] + 1 ][j][k]);
				if(f[now][i][j][k]) update(g[now][j][i][ f[now][i][j][k] ], k);
			}

	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			for(int k = j; k <= n; k++)
			{
				if(g[now ^ 1][i][j][k]) update(g[now][i][j][k], g[now ^ 1][ g[now ^ 1][i][j][k] + 1 ][j][k]);
				if(g[now][i][j][k]) update(f[now][j][i][ g[now][i][j][k] ], k);
			}

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			for(int k = m; k >= j; k--)
				update(f[now][i][j][k], max(f[now ^ 1][i][j][k], f[now][i][j][k + 1]));

	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			for(int k = n; k >= j; k--)
				update(g[now][i][j][k], max(g[now ^ 1][i][j][k], g[now][i][j][k + 1]));
}

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

	now = 0;	
	init();

	while(f[now][1][1][m] < n && g[now][1][1][n] < m)
	{
		now ^= 1;
		ans ++;
		work();
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 130944
from decimal import Decimal

n = int(input())
xs = [int(x) for x in input().split()]

p = Decimal(1)

bad = False

for x in xs:
	if bad:
		if x == 0:
			p = 0
			break
	else:
		p *= Decimal(x)
		if p > 10**18 :
			bad = True
			p = -1

print(p)

Measured memory_bytes: 23120
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    while True:
        if len(set(str(N))) == 1:
            print(N)
            break
        else:
            N += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int x;
  cin >> x;
  while(true){
    bool isPrime=true;
  	for(int i=2; i*i<=x; i++){
      if(x%i==0){
        isPrime=false; 
      }
    }
    if(isPrime){
      cout << x << endl;
      return 0;
    }else{
      x++;
    }
    
  }
}




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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,k;
  cin >> n >> k;

  vll x(n), y(n);
  vll xary(n), yary(n);
  REP(i, n){
    cin >> x[i] >> y[i];
    xary[i] = x[i];
    yary[i] = y[i];
  }

  sort(xary.begin(), xary.end());
  sort(yary.begin(), yary.end());

  ll ans = (xary[n-1]-xary[0])*(yary[n-1]-yary[0]);
  REP(xi, n){
    for(ll xj=xi+1; xj<n; xj++){
      REP(yi, n){
        for(ll yj=yi+1; yj<n; yj++){
          ll c=0;
          REP(i, n){
            if(xary[xi]<=x[i] && x[i]<=xary[xj] && yary[yi]<=y[i] && y[i]<=yary[yj])
              c++;
          }

          if(c==k)
            ans = min(ans, (xary[xj]-xary[xi])*(yary[yj]-yary[yi]));
        }
      }
    }
  }

  cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a) //追加//
#define pp() pop_back() //削除//
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())

signed main(){
  int n;
  cin>>n;
  int b=2;
  int c=1;
  int fib;
  fo(i,n){
    fib=b+c;
    b=c;
    c=fib;
  }
  cout<<b<<endl;
}

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

int Y[2001][2001]={},T[2001][2001]={};

int main(int argc, char const *argv[])
{
    int H,W;
    cin>>H>>W;
    vector<string> S;
    for(int i=0;i<H;i++){
        string s;
        cin>>s;
        S.push_back(s);
    }
    for(int i=0;i<H;i++){
        int c=1;
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                Y[i][j]=0;
                c=1;
            }else{
                Y[i][j]=c++;
            }            
        }
        for(int j=W-1;j>=0;j--){
            if(Y[i][j]!=0)
                Y[i][j]=max(Y[i][j],Y[i][j+1]);
        }        
    }

    for(int j=0;j<W;j++){
        int c=1;
        for(int i=0;i<H;i++){
            if(S[i][j]=='#'){
                T[i][j]=0;
                c=1;
            }else{
                T[i][j]=c++;
            }            
        }
        for(int i=H-1;i>=0;i--){
            if(T[i][j]!=0)
                T[i][j]=max(T[i][j],T[i+1][j]);
        }        
    }
    int ans=-1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            ans=max(ans, T[i][j]+Y[i][j]);
        }
    }
    cout<<ans-1<<endl;
    return 0;
}




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

int main() {
	int grid[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> grid[i][j];
		}
	}
	bool tmp = true;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (grid[i][j] - grid[i + 1][j] != grid[i][j + 1] - grid[i + 1][j + 1])tmp = false;
		}
	}
	if (tmp)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
  string s;
  int i;
  cin>>s;
  for(char c='a';c<='z';c++){
    for(i=0;i<=s.size();i++){
      if(i==s.size()){
        cout<<c<<endl;
        return 0;
      }
      if(s[i]==c){
        break;
      }
    }
  }
  cout<<"None"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
//ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


ll inf=(ll)1E17;

int main(){
    ll n;cin>>n;
    ll a[n+1];rep(i,1,n)cin>>a[i];
    ll s[n+1];
    s[0]=0;
    rep(i,1,n)s[i]=s[i-1]+a[i];
    ll dp[n+1][n+1];rep(i,0,n)rep(j,0,n)dp[i][j]=inf;
    rep(i,1,n)dp[i][i]=0;
    rep(len,1,n-1){
        rep(sta,1,n-len+1){
            ll i=sta;
            ll j=sta+len;
            rep(k,i,j-1){
                Min(&dp[i][j],dp[i][k]+dp[k+1][j]+s[j]-s[i-1]);
            }
        }
    }
    /*rep(i,0,n)cout<<i<<" "<<s[i]<<endl;
    rep(i,1,n){
        rep(j,1,n){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    cout<<dp[1][n]<<endl;
    
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int,int> 
#define int long long 
int visited[100001];


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
//	cin>>t;
	while(t--){
		int n;
		cin>>n;
		double pro[n];
		for(int i=0;i<n;i++){
			cin>>pro[i];
		}
		double **dp=new double *[n+1];
		rep(i,n+1){
			dp[i]=new double[n+1];
			rep(j,n+1){
				dp[i][j]=0;
			}
		}
		dp[1][0]=(1-pro[0]);
		dp[1][1]=pro[0];
		REP(i,2,n+1){
			dp[i][0]=dp[i-1][0]*(1-pro[i-1]);
		}
		REP(i,2,n+1){
			REP(j,1,i+1){
				dp[i][j]=dp[i-1][j]*(1-pro[i-1])+dp[i-1][j-1]*pro[i-1];
			}
		}
		double ans=0;
		REP(i,n/2+1,n+1){
			ans+=dp[n][i];
		}
		cout << fixed << setprecision(10) <<ans<<endl;
	}
	//exit();
	return 0;
}


Measured memory_bytes: 70656
ans = 0
h, w, k = map(int, input().split())
C = [input() for _ in range(h)]
for i in range(2**h):
    for j in range(2**w):
        c = 0
        for y in range(h):
            for x in range(w):
                if C[y][x] == ".":
                    continue
                if i>>y & 1:
                    continue
                if j>>x & 1:
                    continue
                c += 1
        if c == k:
            ans += 1
print(ans)

Measured memory_bytes: 68256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		int max = 0;
		int cnt = 0;
		for (int i = 0; i <= 1; i++) {
			if (A >= B) {
				max = A;
				A -= 1;
			} else {
				max = B;
				B -= 1;
			}
			cnt += max;
		}
		System.out.println(cnt);
	}
}


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

int n,A[50];

int solve(int i,int m){
    if(m==0)return 1;
    if(i>=n)return 0;
    int res=solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    int i,q;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>A[i];
    }
    cin>>q;
    vector<int>m(q);
    for(i=0;i<q;i++){
        cin>>m[i];
        if(solve(0,m[i])){
            cout<<"yes"<<endl;
        }
        else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}    


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll h[n];
	for(ll i=0;i<n;i++)
	{
		cin>>h[i];
	}
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(ll i=2;i<n;i++)
	{
		dp[i]=min(abs(h[i]-h[i-1])+dp[i-1] , abs(h[i]-h[i-2])+dp[i-2]);
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main(){
	vector<int> h,w;
	int temph,tempw;
	do{
		cin>>temph>>tempw;
		h.push_back(temph);
		w.push_back(tempw);
	}while (temph!=0 || tempw!=0);
	for (vector<int>::size_type i=0;i<h.size()-1;i++){
		for (int j=0;j<h[i];j++){
			bool flg;
			if (j%2==0){
				flg=true;
			}
			else{
				flg=false;
			}
			for (int k=0;k<w[i];k++){
				if (flg){
					cout<<"#";
				}
				else{
					cout<<".";
				}
				flg=!flg;
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
h,w=map(int,input().split())

s=[list(input()) for _ in range(h)]

black_cnt=0
for ss in s:
    black_cnt+=ss.count("#")

from collections import deque
stack=deque([(0,0)])
s[0][0]=1
flag=0
while len(stack)>0:
    #print(stack)
    tmp=stack.popleft()
    if tmp[0]==h-1 and tmp[1]==w-1:
        flag=1
        break

    for (my,mx) in [(1,0),(0,1),(-1,0),(0,-1)]:
        ny=tmp[0]+my
        nx=tmp[1]+mx
        #print(ny,nx)
        if 0<=ny and ny<h and 0<=nx and nx<w:
            #print(ny,nx)
            if s[ny][nx]==".":
                #print(ny,nx,tmp[0],tmp[1],stack)
                s[ny][nx]=s[tmp[0]][tmp[1]]+1
                stack.append((ny,nx))

#for item in s:
 #   print(item)
if flag==1:
    print(h*w-s[-1][-1]-black_cnt)
else:
    print(-1)

    

Measured memory_bytes: 73508
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int memo[200010];

signed main() {
    int N, K;
    cin >> N >> K;

    vector<int> A;
    inputVector(A, N);

    rep(i, K) {
        memset(memo, 0, sizeof(memo));
        rep(j, N) {
            memo[max(0LL, j - A[j])]++;
            memo[min(N, j + A[j] + 1)]--;
        }
        rep(j, N) {
            memo[j + 1] += memo[j];
        }
        if (memo[0] == N && memo[N - 1] == N) break;
        rep(j, N) A[j] = memo[j];
    }

    REP(i, 0, N - 1) cout << memo[i] << ' ';
    cout << endl;

    return 0;
}


Measured memory_bytes: 6408
# -*- coding: utf-8 -*-


while n = gets

  n = n.chomp.to_i
  ans = 0

  i = 0
  while i<=9
    j = 0
    while j<=9
      k = 0
      while k<=9
        l = 0
        while l<=9
          ans+=1 if i+j+k+l == n
          l+=1
        end
        k+=1
      end
      j+=1
    end
    i+=1
  end

  puts ans

end

Measured memory_bytes: 6088
#include <iostream>
#define MAX(x,y) (x>y?x:y)
using namespace std;

int main(){
	int l,a,b,c,d,day1,day2;

	cin>>l>>a>>b>>c>>d;

	day1=(a%c==0?a/c:a/c+1);
	day2=(b%d==0?b/d:b/d+1);

	cout<<l-MAX(day1,day2)<<endl;

	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    while(cin>>a>>b>>c)
    {
        string d;
        d+=a[0]-32;
        d+=b[0]-32;
        d+=c[0]-32;
        cout<<d<<endl;
    }
    return 0;
}


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

using namespace std;

int main(){
    int N, Q;
    while(cin >> N >> Q){
        vector<string> word(N + 1, "kogakubu10gokan");
        vector<int> year(N + 1, 0);
        REP(i, N) cin >> year[i + 1] >> word[i + 1];
        year.push_back(INT_MAX);
        for(int i = 0; i < N + 1; i++){
            if(year[i] <= Q && Q < year[i + 1]){
                cout << word[i] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,ans=0;
  int k[50],a[50][50];
  cin>>n>>m;
  for (int i=0;i<n;i++)
  {
  	cin>>k[i];
  	for (int j=0;j<k[i];j++)
  	  cin>>a[i][j];
  }
  for (int i=1;i<=m;i++)
  {
  	int b=1;
  	for (int j=0;j<n;j++)
  	{
  	  int b0=0;
  	  for (int h=0;h<k[j];h++)
  	    if (a[j][h]==i) b0=1;
  	  if (!b0) {b=0;break;}
    }
  	if (b) ans++;  
  }
  cout<<ans;
  return 0;
}


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

using namespace std;
int const MaxN = 100000;
long long const Mod = 1000000007;
long long T[MaxN];
long long A[MaxN];
int main(){
	int N;
	cin >> N;
	for(int i=0; i<N; i++) cin >> T[i];
	for(int i=0; i<N; i++) cin >> A[i];
	long long res = 0;
	int maxT = 0, maxA = 0, Ti, Ai;
	for(int i=0, j=N-1; i<N, j>=0; i++, j--){
		if(T[i] >= maxT) maxT = T[i];
		else{
			res = 0;
			cout << res << endl;
			return 0;;
		}
		if(A[j] >= maxA) maxA = A[j];
		else{
			res = 0;
			cout << res << endl;
			return 0;
		}
	}
	for(int i=0; i<N; i++)
			if(T[i] == maxT){ Ti = i; break;}
	for(int j=N-1; j>=0; j--)
			if(A[j] == maxA){ Ai = j; break;}
	if(maxA != maxT || Ti > Ai){
		cout << 0 << endl;
		return 0;
	}else{
		res = 1;
		for(int i=1; i<Ti; i++){
			if(T[i] == T[i-1]){
				res = (res * T[i-1]) % Mod;
			}
		}
		for(int i=Ti+1; i<Ai; i++){
			res = (res * maxT) % Mod;
		}
		for(int i=N-2; i>Ai; i--){
			if(A[i] == A[i+1]){
				res = (res * A[i+1]) % Mod;
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

void solve()
{
    int x;
    cin >> x;
    
    if(x >= 30)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    // int t;
    // cin >> t;
    
    // while(t--)
    // {
        solve();
    // }

    return 0;
}


Measured memory_bytes: 3604
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-18 00:07:16
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

using graph = vector<vector<int>>;

using pii = pair<int, int>;

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

  int n, m; cin >> n >> m;
  graph g(n);
  for (int i = 0; i < m; ++i) {
    int a, b; cin >> a >> b; --a; --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  vector<int> ans(n, -1);

  vector<bool> visited(n, false);
  visited[0] = true;

  queue<int> que;
  que.emplace(0);
  while (!que.empty()) {
    int cur = que.front(); que.pop();
    for (int nxt : g[cur]) {
      if (visited[nxt]) continue;
      ans[nxt] = cur;
      visited[nxt] = true;
      que.emplace(nxt);
    }
  }

  cout << "Yes" << '\n';
  for (int i = 1; i < n; ++i) {
    cout << ans[i] + 1 << '\n';
  }

  return 0;
}

Measured memory_bytes: 10332
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

int main() {
  set<ll> st;
  ll a, b, c;
  cin >> a >> b >> c;
  st.insert(a);
  st.insert(b);
  st.insert(c);

  if (st.size() == 2)
    puts("Yes");
  else
    puts("No");

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

INF = 10**7
p = 1<<n
dp = [INF]*p
dp[0] = 0

for _ in range(m):
    a, _ = map(int, input().split())
    c = sum([1<<(int(i)-1) for i in input().split()])
    def k(s):
        dp[s|c] = dp[s] + a
    [k(s) for s in range(p) if dp[s|c] > dp[s] + a]
ans = dp[-1]
if ans==INF:
    ans = -1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;cin >> n;
    int bef=0;
    bool ok = true;
    rep(i,n){
        int a;
        cin >> a;
        if(bef==a){
            continue;
        }else if(bef<a){
            a--;
            bef = a;
        }else if(bef>a){
            ok = false;
            break;
        }
    }
    cout << (ok?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<bitset<maxn> > v(n);
	for(int i = 1; i < n; ++i) {
		string s;
		cin >> s;
		for(int j = 0; j < i; ++j) {
			if(s[j] == '1') {
				v[i][j] = 1;
			} else {
				v[j][i] = 1;
			}
		}
	}
	vector<bitset<maxn> > l(n);
	vector<bitset<maxn> > r(n);
	for(int i = 0; i < n; ++i) {
		l[i][i] = r[i][i] = 1;
	}
	for(int i = 1; i < n; ++i) {
		for(int j = 0; i + j < n; ++j) {
			l[i + j][j] = (l[i + j] & r[j + 1] & v[j]).any();
			r[j][i + j] = (r[j] & l[i + j - 1] & v[i + j]).any();
		}
	}
	cout << (r[0] & l[n - 1]).count() << '\n';
	return 0;
}

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

int main()
{
    int M1, M2, D1, D2;

    cin >> M1 >> D1 >> M2 >> D2;
    if (D2 == 1)
        cout << "1" << endl;
    else
        cout << "0" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

#define rep(i, n) for(int i=0;i<(int)(n);i++)

using namespace std;

string S;

bool ok() {
    if (S[0] != 'A') return false;

    int num_c = 0;
    for (int i = 2; i < S.length() - 1; i++) {
        if (S[i] == 'C') num_c++;
    }
    if (num_c != 1) return false;

    for (int i = 1; i < S.length(); i++) {
        if (S[i] == 'C') continue;
        if (S[i] < 'a' || 'z' < S[i]) return false;
    }

    return true;
}

int main() {
    cin >> S;

    if (ok()) cout << "AC" << endl;
    else cout << "WA" << endl;
}


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

bool IsPrime(long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (long i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    long A,i;
    cin>>A;
    for(i=A;i>0;i++){
        if(IsPrime(i)){
            break;
        }
    }
    cout<<i;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>



using namespace std;


int main() {
	int n, q;
	cin >> n >> q;
	
	vector<vector<int>> tree(n);
	vector<vector<int>> children(n);
	vector<int> parent(n, -1);
	vector<int> score(n);

	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		tree[a].emplace_back(b);
		tree[b].emplace_back(a);

	}

	queue<int> que;
	que.push(0);
	
	while (!que.empty()) {
		int v = que.front();
		
		que.pop();
		vector<int> children_v;
		for (int child : tree[v]) {
			if (child != parent[v]) {
				parent[child] = v;
				children_v.emplace_back(child);
				que.push(child);
			}
		}
		children[v] = children_v;
	}


	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		
		p--;
		score[p] += x;

	}

	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int child : children[v]) {
			score[child] += score[v];
			que.push(child);
		}

	}

	for (int i = 0; i < n; i++) {
		printf("%d ", score[i]);
	}
}


Measured memory_bytes: 25856
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// nがあり、nの数だけの整数の入力
			long n = sc.nextLong();
			Map<Integer, Map<Integer, Integer>> honestMap = new HashMap<>();
			// 証言マップ作製
			for (int i = 1; i <= n; i++) {
				long a = sc.nextLong();
				Map<Integer, Integer> oneMap = new HashMap<>();
				for (long j = 1; j <= a; j++) {
					oneMap.put(sc.nextInt(), sc.nextInt());
				}
				honestMap.put(i, oneMap);
			}
			// 仮定していく
			int result = 0;
			Long max = (long) Math.pow(2, n);
			for (int i = 0; i < max; i++) {
				String bin = Integer.toBinaryString(i);
				bin = String.format("%0" + n + "d", Long.parseLong(bin));
				boolean isOk = true;
				for (int si = 0; si < bin.length(); si++) {
					if (bin.charAt(si) == '1') {
						for (Entry<Integer, Integer> entry : honestMap.get(si + 1).entrySet()) {
							int search = entry.getKey() - 1;
							int target = Character.getNumericValue(bin.charAt(search));
							if (target != entry.getValue()) {
								isOk = false;
								break;
							}
						}
					}
					if (!isOk) {
						break;
					}
				}
				if (isOk) {
					int candCnt = 0;
					for (int si = 0; si < bin.length(); si++) {
						if (bin.charAt(si) == '1') {
							candCnt++;
						}
					}
					if (result < candCnt) {
						result = candCnt;
					}
					// System.out.println(bin);
				}
			}
			System.out.println(result);

		}
	}
}


Measured memory_bytes: 52008
#include<stdio.h>

int main(void)
{
  int num[5];
  int dumy,i,j;
  
  for(i = 0 ; i < 5 ; i++)
    {
      scanf("%d",&num[i]);
    }
  
  for(i = 0 ; i < 4 ; i++)
    {
      for(j = i + 1 ; j < 5 ; j++)
	{
	  if(num[i] < num[j])
	    {
	      dumy = num[i];
	      num[i] = num[j];
	      num[j] = dumy;
	    }
	}
    }
  for(i = 0 ; i < 4 ; i++)
    {
      printf("%d ",num[i]);
    }
  printf("%d\n",num[i]);
  return 0;
}

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

typedef long long ll;
const int maxn = 2e5+10;
const int mod = 1e9+7;

ll a[maxn];
ll sum[maxn];
int main(void){
	string s,t;
	cin >> s >> t;
	int len1 = s.size();
	int len2 = t.size();
	int maxx = 0;
	for(int i = 0; i < len1-len2+1; i++){
		int ans = 0;
		for(int j = 0; j < len2; j++){
			if(t[j]==s[i+j]){
				ans++;
				maxx = max(ans,maxx);
			}
		}
	}
	cout<<len2-maxx<<endl;
	return 0;
}



Measured memory_bytes: 3620
type Room      = Int
type Floor     = [Room]
type Building  = [Floor]
type Buildings = [Building]

setupBuildings :: Buildings
setupBuildings = replicate 4 $ replicate 3 $ replicate 10 0

getBuilding :: Int -> Buildings -> Building
getBuilding b blds = blds !! (b - 1)

getFloor :: Int -> Int -> Buildings -> Floor
getFloor b f blds = getBuilding b blds !! (f - 1)

getRoom :: Int -> Int -> Int -> Buildings -> Room
getRoom b f r blds = getFloor b f blds !! (r - 1)

addMember :: Int -> Int -> Floor -> Floor
addMember 1 v (x:xs) = (x + v):xs
addMember r v (x:xs) = x:(addMember (r - 1) v xs)

updateMemberAtFloor :: Int -> Int -> Int -> Building -> Building
updateMemberAtFloor 1 r v (x:xs) = (addMember r v x):xs
updateMemberAtFloor f r v (x:xs) = x:(updateMemberAtFloor (f - 1) r v xs)

updateMember :: Int -> Int -> Int -> Int -> Buildings -> Buildings
updateMember 1 f r v (x:xs) = (updateMemberAtFloor f r v x):xs
updateMember b f r v (x:xs) = x:(updateMember (b - 1) f r v xs)

printFloor :: Floor -> IO ()
printFloor []     = putStrLn ""
printFloor (x:xs) = (putStr $ " " ++ show x) >> printFloor xs

printBuilding :: Building -> IO ()
printBuilding []     = return()
printBuilding (x:xs) = printFloor x >> printBuilding xs

printBuildings :: Buildings -> IO ()
printBuildings (x:[]) = printBuilding x
printBuildings (x:xs) = printBuilding x >> (putStrLn $ replicate 20 '#') >> printBuildings xs

readRoomData :: Int -> Buildings -> IO Buildings
readRoomData 0 blds = return blds
readRoomData n blds = do
    [b, f, r, v] <- getLine >>= return.(map (\n -> read n :: Int)).words
    readRoomData (n - 1) $ updateMember b f r v blds

main :: IO ()
main = do
    n <- getLine >>= return.read :: IO Int
    readRoomData n setupBuildings >>= printBuildings



Measured memory_bytes: 4272
import math
from functools import reduce
import itertools
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))






n,k=input2()
r,s,p=input2()
t=str(input())
V = {'r':p, 's':r, 'p':s}

ans_list=[]
ans=0

for i in range(k):
	check=t[i]
	ans+=V[check]
	for _ in range(n):
		i+=k
		if i>=n:
			break
		elif check==t[i]:
			check="-1"
		else:
			check=t[i]
			ans+=V[t[i]]

print(ans)











# 逆ポーランド記法
# ８クイーン
# 単純換字暗号





Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long a, b;
	while (cin >> a >> b){
		long long gcd;
		long long c = max(a, b);
		long long d = min(a, b);
		while (true){
			if (c % d == 0) {
				gcd = d;
				goto C;
			}
			else{
				c -= d;
				if (c <= d){
					swap(c, d);
				}
			}
		}
	C:
		cout << gcd << ' ' << a*b / gcd << endl;
	}
}

Measured memory_bytes: 3040
#include <stdio.h>
 
int main(void){

	int n, x;
	int i, j, k;
	int count=0;

	while(1){
		scanf("%d %d", &n, &x);	/* n?????\?????????3??\???100??\?????¨?????? */
			if((n==0)&&(x==0)) {
			break;	/* n x??±???0????????\????????? */
	}

	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			for (k=1; k<=n; k++) {
				if (i+j+k==x && i!=j && j!=k && k!=i) {
					count++;	/* ???????????????????????£?????¨??????????????????????????? */
				}
			}
		}
	}

	printf("%d\n", count/6);	/* ??????????????????????????????????????°????????? */
		count=0;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

int n, k;
int a[111];
int dp[100100];
int f(int rem)
{
    int &ret = dp[rem];
    if (~ret) return ret;
    set < int > st;
    for (int i = 0; i < n; ++i)
        if (a[i] <= rem)
            st.insert(f(rem-a[i]));
    int cnt = 0;
    while (st.find(cnt) != st.end())
    {
        ++cnt;
    }
    return ret = cnt;
}

int fIter()
{
    for (int i = 1; i <= k; ++i)
    {
        set <int> st;
        for (int j = 0; j < n; ++j)
        {
            if (a[j] <= i)
            {
                st.insert(dp[i-a[j]]);
            }
        }
        while (st.find(dp[i]) != st.end())
        {
            ++dp[i];
        }
    }
    return dp[k];
}

int main()
{
//    memset(dp, -1, sizeof dp);

    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    printf("%s\n", !fIter() ? "Second" : "First");

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>


int main()
{
    int dice[6],a,front,top;
    for(int i=0;i<6;i++){
        scanf("%d",&dice[i]);
    }
    scanf("%d",&a);
    int box,flg,cnt;
    for(int i=0;i<a;i++)
    {
        cnt = 0;
        flg = 0;
        scanf("%d %d",&front,&top);
        while(1)
        {
            if(dice[1]==front||4 < cnt){
                cnt = 0;
                box = dice[5];
                dice[5] = dice[2];
                dice[2] = dice[0];
                dice[0] = dice[3];
                dice[3] = box;
                if(dice[1]==front&&dice[0]==top) break;
            }else {
                cnt += 1;
                box = dice[5];
                dice[5] = dice[1];
                dice[1] = dice[0];
                dice[0] = dice[4];
                dice[4] = box;
            }
        }
        printf("%d\n",dice[3]);
    }
    return 0;
}


Measured memory_bytes: 2040