akhauriyash/Code-Regression huggingface dataset:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    N=pin()
    X=tupin()
    ans=0
    for h in range(101):
        if (X)==[0]*(len(X)):
            print(ans)
            return

        cnt=0
        f=0
        for j in range(len(X)):
            if X[j]>0:f=1
            if f and X[j]==0:
                f=0
                cnt+=1
        if X[-1]!=0:cnt+=1
        ans+=(cnt)
        #print(X,cnt)

        temp=[]
        for x in X:
            if x>0:
                temp.append(x-1)
            else:temp.append(x)
        X=temp
        #print("".join(X).split("0"))
#%%submit!      
resolve()


Measured memory_bytes: 65260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
        int x,y;
        for(int count = 1; ;count++){
        	x = scan.nextInt();
    	    y = scan.nextInt();
    	    if(x == 0 && y == 0)
    	    	break;


    	    if(x < y){

    	    	 System.out.println(x + " " + y);

    	     }else{
    	    	 System.out.println(y + " " + x);

    	     }
        }

	}
}

Measured memory_bytes: 35044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int taroScore=0,hanakoScore=0;
        for(int i=0;i<n;i++){
        	String[] str  = br.readLine().split(" ");
        	int compare = str[0].compareTo(str[1]);
        	if(compare > 0){
        		taroScore += 3;
        	}else if(compare==0){
        		taroScore++;
        		hanakoScore++;
        	}else{
        		hanakoScore +=3;
        	}
    	}
        System.out.println(taroScore + " " + hanakoScore);
    }
}

Measured memory_bytes: 25328
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	static int n,m,k;
	static int a[100010],b[100010],l[100010];
	static int s[3002];
	
	scanf("%d%d%d",&n,&m,&k);
	rep(i,m){
		scanf("%d%d%d",&a[i],&b[i],&l[i]);
	}
	rep(i,k){
		scanf("%d",&s[i]);
	}
	
	static vector<P> G[3002];
	static int d[3002];
	static bool used[3002];
	static rpque(P) que;
	
	rep(i,m){
		G[a[i]].pb( P ( b[i] , l[i] ) );
		G[b[i]].pb( P ( a[i] , l[i] ) );
	}
	rep(i,3002){
		d[i] = INF;
		used[i] = false;
	}
	rep(i,k){
		d[s[i]] = 0;
		que.push( P ( 0 , s[i] ) );
	}
	
	while(!que.empty()){
		P p = que.top(); que.pop();
		if(!used[p.sc]){
			rep(i,G[p.sc].size()){
				P ed = G[p.sc][i];
				if(d[ed.fr] > d[p.sc] + ed.sc){
					d[ed.fr] = d[p.sc] + ed.sc;
					que.push( P ( d[ed.fr] , ed.fr ) );
				}
			}
			used[p.sc] = true;
		}
	}
	
	static int ret = 0;
	
	rep1(i,n){
		ret = max ( ret , d[i] );
	}
	rep(i,m){
		ret = max ( ret , ( d[a[i]] + d[b[i]] + l[i] + 1 )/2 );
	}
	
	printf("%d\n",ret);
}

Measured memory_bytes: 5348
from collections import deque


h, w, k = map(int, input().split())
a = [input() for i in range(h)]
INF= 10**9

for i in range(h):
    for j in range(w):
        if a[i][j] == "S":
            si, sj = i, j
            break

cnt = [[INF] * w for i in range(h)]
cnt[si][sj] = 0
q = deque([(si, sj, 0)])
while q:
    pi, pj, cost = q.popleft()
    for nxi, nxj in [(pi+1, pj), (pi, pj+1), (pi-1, pj), (pi, pj-1)]:
        if not (0 <= nxi < h and 0 <= nxj < w):
            continue
        if a[nxi][nxj] == "." and cost + 1 < cnt[nxi][nxj] and cost + 1 <= k:
            cnt[nxi][nxj] = cost + 1
            q.append((nxi, nxj, cost + 1))

ans = 10**9
for i in range(h):
    for j in range(w):
        if cnt[i][j] <= k:
            ans = min(ans, -((-i)//k), -((-(h-i-1))//k), -((-j)//k), -((-(w-j-1))//k))

print(ans+1)

Measured memory_bytes: 59868
S = input()
a = S[0]
b = S[1]
c = S[2]
d = S[3]
not_a = []
for st in S[1:]:
    if st != a:
        not_a.append(st)
if len(not_a) != 2:
    print("No")
    exit()
if not_a[0] == not_a[1]:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
import sys
from collections import deque


def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    G = [[] for _ in range(N + 1)]
    for _ in range(M):
        A, B = map(int, input().split())
        G[A].append(B)
        G[B].append(A)
    ans = [0] * (N + 1  )
    ans[1] = 1
    cnt = 1
    q = deque([1])
    while q:
        v = q.popleft()
        for to in G[v]:
            if ans[to] > 0: continue
            ans[to] = v
            q.append(to)
            cnt += 1
    if cnt < N:
        print('No')
        return
    print('Yes')
    for i in range(2, N + 1):
        print(ans[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 34128
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

rotate n = applyBin (++) (drop n) (take n)

f [n,m] = f' n m [1..n]
  where
    f' 1 _ = head
    f' n m = f' (n-1) m . tail . rotate (mod (m-1) n)


main = map f . takeWhile (any (/=0)) . map (map readInt . words) . lines <$> getContents >>= mapM_ print

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

using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;
    (b - a - 1) & 1 ? cout << "Alice\n" : cout << "Borys\n";

    return 0;
}

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

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);

    ll a, b;
    cin >> a >> b;
    ll ans = 1;
    ll count = 0;
    while (ans < b) {
        ll prev = ans;
        for (ll i=1; i<=prev; i++) {
            ans = a*i + (prev-i);
            count++;
            if (ans >= b) break;
        }
    }
    cout << count << endl;

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define IN 0
#define OUT 1
int N;
ll T;

struct Event {
  ll t;
  int type;
  bool operator < ( const Event &e ) const {
    if( t != e.t ) return t > e.t;
    return type > e.type;
  }
};

void compute() {

}

int main() {
  cin >> N >> T;
  priority_queue<Event> Q;
  rep(i,N) {
    ll t;
    cin >> t;
    Q.push((Event){t,IN});
    Q.push((Event){t+T,OUT});
  }
  int cnt = 0;
  ll cur = Q.top().t, ans = 0;
  while( !Q.empty() ) {
    Event e = Q.top(); Q.pop();
    if( e.type == IN ) {
      if( cnt == 0 ) cur = e.t;
      ++cnt;
    } else {
      ans += ( e.t - cur );
      cur = e.t;
      --cnt;
    }
  }
  cout << ans << endl;
  compute();
  return 0;
}


Measured memory_bytes: 9964
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    string S, T;
    cin >> S >> T;
    int count = 0;
    for (int i = 0; i < 3; ++i)
    {
        if (S[i] == T[i]) ++count;
    }
    cout << count << endl;
}


Measured memory_bytes: 764
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range, core.bitop;

void main()
{
    auto PP = new long[](10^^5*2+1);
    foreach (i; 1..10^^5*2+1) {
        PP[i] = PP[i % popcnt(i)] + 1;
    }
    auto N = readln.chomp.to!int;
    auto X = readln.chomp;
    long bc;
    foreach (b; X) if (b == '1') ++bc;
    auto cs = new long[][](N, 2);
    auto xs = new long[][](N, 2);
    long x1 = 1, x2 = 1;
    foreach_reverse (i, b; X) {
        if (i != N-1) {
            cs[i][0] = cs[i+1][0];
            cs[i][1] = cs[i+1][1];
        }
        if (b == '1') {
            if (bc > 1) (cs[i][0] += x1) %= (bc-1);
            (cs[i][1] += x2) %= (bc+1);
        }
        xs[i][0] = x1;
        xs[i][1] = x2;
        if (bc > 1) (x1 *= 2) %= (bc-1);
        (x2 *= 2) %= (bc+1);
    }
    x1 = 0;
    x2 = 0;
    foreach (i, b; X) {
        if (b == '1') {
            if (bc == 1) {
                writeln(0);
            } else {
                auto n = x1 + (i == N-1 ? 0 : cs[i+1][0]);
                writeln(PP[n % (bc-1)] + 1);
            }
            if (bc > 1) (x1 += xs[i][0]) %= (bc-1);
            (x2 += xs[i][1]) %= (bc+1);
        } else {
            auto n = x2 + xs[i][1] + (i == N-1 ? 0 : cs[i+1][1]);
            writeln(PP[n % (bc+1)] + 1);
        }
    }
}

Measured memory_bytes: 23476
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

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

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


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int mod = 1e9 + 7;
constexpr int N = 1e5;
std::array<int, N + 1> A, B;

int main(void){
    int n, k; scanf("%d%d", &n, &k);
    A[k] = 1;
    REP(_, n){
        int a; scanf("%d", &a);
        for(int x = 1; x <= k; ++x) (A[x] += A[x-1]) %= mod;
        // x + y -> x
        // x + ai ~ x -> x
        for(int x = 0; x <= k; ++x){
            int r = ((x + a) >= k) ? A[k] : A[x + a];
            int l = (x - 1 >= 0) ? A[x - 1] : 0;
            B[x] = r - l;
        }
        for(int x = 0; x <= k; ++x){
            A[x] = B[x] % mod; if(A[x] < 0) A[x] += mod;
        }
    }
    printf("%d\n", A[0]);



    

    
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int i, j, c[4][4] = {};

    i = 0;
    while (i < 3)
    {
        j = 0;
        while (j < 3)
        {
            scanf("%d", &c[i][j]);
            j++;
        }
        i++;
    }

    i = 0;
    while (i < 3)
    {
        j = 0;
        while (j < 3)
        {
            if (c[i][j] - c[i][(j + 1) % 3] != c[(i + 1) % 3][j] - c[(i + 1) % 3][(j + 1) % 3])
            {
                printf("No\n");
                return (0);
            }
            j++;
        }
        i++;
    }

    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    pair<int, int> p[100010];
    rep(i, N) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p, p + N);
    int ans = 0;
    int i = 0;
    while(M > 0) {
        ans += p[i].first * min(p[i].second, M);
        M -= min(p[i].second, M);
        i++;
    }
    cout << ans << endl;

    return 0;
}


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

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

    map<char, int> a;
    for (int i = 0; i < S.length(); i++) {
        a[S[i]]++;
    }
    cout << min(a['0'], a['1']) * 2 << endl;

    return 0;
}


Measured memory_bytes: 3720
#include<stdio.h>
int main(){
    long long int a,n;
    n=100;
    long long int count=0;
    scanf("%lld",&a);
    while (n<a)
    {
        n=(n+n/100);
        //printf("%lld\n",n);
        count++;

    }
    printf("%d",count);
    
}



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

using namespace std;

int64_t v[6];
long long need;
int32_t main() {

	for(int i = 1; i <= 4; ++i) {
		cin >> v[i];
	}
	cin>>need;
	for(int i = 1; i < 4; ++i) {
		v[i + 1] = min(v[i + 1], 2 * v[i]);
	}

	int unu = v[3], doi = v[4];

	if(unu*2 <= doi) {
		cout << unu * need;
	} else {
		if(need % 2 == 0) cout<<doi*(need/2);
		else cout<<doi*(need/2)+unu;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define R register
using namespace std;
const int MAXN=500100;
int next1[MAXN],next2[MAXN];
char s1[MAXN],s2[MAXN];

int reads(char *st)
{
	int len=0;char ch=getchar();
	while(ch<'a'||ch>'z')ch=getchar();
	while(ch>='a'&&ch<='z')st[++len]=ch,ch=getchar();
	return len;
}

void getnext(char *st,int *next,int len)
{
	int j=0;
	for(int i=2;i<=len;++i)
	{
		while(j&&st[i]!=st[j+1])j=next[j];
		if(st[i]==st[j+1])++j;
		next[i]=j;
	}
}

int main()
{
	int n=reads(s1);
	for(R int i=1;i<=n;++i)s2[i]=s1[n-i+1];
	getnext(s1,next1,n);
	getnext(s2,next2,n);
	int t=n-next1[n];
	if(t==1){printf("%d\n1\n",n);}
	else if(t<n&&n%t==0)
	{
		puts("2");
		int ans=0;
		for(int i=1;i<n;++i)
		{
			int t1=i-next1[i],t2=n-i-next2[n-i];
			if(t1<i&&i%t1==0)continue;
			if(t2<n-i&&(n-i)%t2==0)continue;
			++ans;
		}
		printf("%d\n",ans);
	}
	else puts("1\n1");
	return 0;
}

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

int main()
{
    int H[100000];
	int N, i, j;

	cin >> N;

	for(i = 0; i < N; i++)
        cin >> H[i];

    int maximum_move = 0, moves = 0;
    for(i = 0; i < N - 1; i++)
    {
        if(H[i] >= H[i+1])
            moves++;
        else
            moves = 0;

        if(moves > maximum_move)
            maximum_move = moves;
    }

    cout << maximum_move << endl;

	return 0;
}


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

class Program
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var mochis = new List<int>();
		for (var i = 0; i < n; ++i) {
			mochis.Add(int.Parse(Console.ReadLine()));
		}

		Console.WriteLine(mochis.Distinct().Count());
	}
}


Measured memory_bytes: 28332
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)

var T string

func main() {
	sc.Split(bufio.ScanWords)
	fmt.Scanf("%s", &T)
	ans := ""
	for i := 0; i < len(T); i++ {
		if string(T[i]) == "?" {
			ans += "D"
		} else {
			ans += string(T[i])
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7848
#include <iostream>
#include <cmath>
#define MOD 1000000007
using namespace std;

long long N, A, B;
int X[100010];

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

    long long c = 0;
    for (int i = 0; i < N-1; i++) {
        if (A*(X[i+1]-X[i]) > B) {
            c += B;
        } else {
            c += A*(X[i+1]-X[i]);
        }
    }
    cout << c << endl;
}

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

int main(){
  vector<int> a{1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  int k;
  cin >> k;
  
  cout << a.at(k-1) << endl;
  
  return 0;
}


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

target = [[] for i in range(n)]

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

queue = [0]
isSearched = [False]*n
isSearched[0] = True
ans = [-1]*n
def bfs():
    while(queue):
        now = queue.pop(0)

        for t in target[now]:
            if(isSearched[t]):
                continue
            ans[t] = now
            queue.append(t)
            isSearched[t] = True
bfs()
print('Yes')
for i in range(n):
    if(i==0):
        continue
    print(ans[i]+1)


Measured memory_bytes: 34600
#include <iostream>
#include <cmath>
using namespace std;
 
#define MAXN 120
#define MAXW 100001
 
long long N,W;
long long w[MAXN], v[MAXN];
 
long long dp[MAXN][MAXW];
 
int main()  {
	cin >> N >> W;
  	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
    }
  	for (int i = w[0]; i <= W; i++) {
      dp[0][i] = v[0];
    }
  	for (int i = 1; i < N; i++) {
      for (int j = 0; j <= W; j++) {
        if (w[i] > j) {
          dp[i][j] = dp[i-1][j];
        } else {
			dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        }
      }
    }
  cout << dp[N-1][W] << endl;
}

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

signed main() {
  int n; cin >> n;
  int button[n];
  for(int i = 0; i < n; i++) cin >> button[i];

  int cnt = 0, now = 0;
  while(true) {
    if(now == 1) {
      cout << cnt << endl;
      break;
    } else if(n <= cnt) {
      cout << -1 << endl;
      break;
    }
    cnt++;
    now = button[now] - 1;
  }

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll S,W;
	cin>>S>>W;
	if(S>W) cout<<"safe\n";
	else cout<<"unsafe\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define CS ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main()
{
    CS
    char a,b;cin>>a>>b;
    if(a=='H'){
        cout<<b;
    }else{
        if(b=='H')cout<<"D";
        else cout<<"H";
    }
    return 0;
}


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

typedef long long LL;

const int N=400,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,a[N+9],b[N+9],sa,sb;

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	scanf("%d%d",&a[i],&b[i]);
	sa+=a[i];sb+=b[i];
  }
}

int inv[N+9],fac[N+9],ifac[N+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int lim=max(sa,sb),i=2;i<=lim;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int dp[N+9][N+9],ans;

void Get_dp(){
  dp[0][0]=mod-1;
  for (int i=1;i<=n;++i)
	for (int j=sa;j>=a[i];--j)
	  for (int k=sb;k>=0;--k){
		int now=1;
		for (int t=0;t<b[i]&&t<=k;++t){
		  ssub(dp[j][k],mul(dp[j-a[i]][k-t],now));
		  smul(now,mul(inv[t+1],a[i]));
		}
	  }
  for (int i=1;i<=sa;++i){
	int now=1;
	for (int j=0;j<=sb;++j){
	  smul(now,inv[i]);
	  sadd(ans,mul(dp[i][j],mul(now,fac[j])));
	}
  }
}

void work(){
  Get_inv();
  Get_dp();
}

void outo(){
  printf("%d\n",mul(ans,sa));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4428
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int term(State& begin);
int expression(State& begin) {
	int now_value = 0;
	if (*begin == '(') {
		begin++;
		int d1 = expression(begin);
		int d2;
		if (*begin == '+') {
			begin++;
			d2 = expression(begin);
			now_value = max(d1, d2);
		}
		else if(*begin == '*'){
			begin++;
			d2 = expression(begin);
			now_value = min(d1, d2);
		}
		begin++;
	}
	else {
		now_value = term(begin);
	}
	return now_value;
}
int term(State& begin) {
	int now_value = 0;
	if (*begin == '-') {
		begin++;
		now_value = 2 - expression(begin);
	}
	else if (*begin >= '0' && *begin <= '9') {
		now_value = *begin - '0';
		begin++;
	}
	return now_value;
}
int main() {
#define int long long
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) return 0;
		int grid[31][31];
		int dp[4][31][31] = {};
		int visited[4][31][31] = {};
		REP(i, h) {
			REP(q, w) {
				cin >> grid[i][q];
				REP(j, 4) {
					dp[j][i][q] = LONG_INF;
				}
			}
		}
		int costings[4];
		REP(i, 4) {
			cin >> costings[i];
		}
		dp[0][0][0] = 0;
		priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int>>, greater<tuple<int, int, int, int>>> next;
		next.push(make_tuple(0, 0, 0, 0));
		int xe[4] = { 0,1,0,-1 };
		int ye[4] = { 1,0,-1,0 };
		while (next.empty() == false) {
			tuple<int, int, int, int> now = next.top();
			next.pop();
			if (visited[get<1>(now)][get<2>(now)][get<3>(now)] == 1) continue;
			visited[get<1>(now)][get<2>(now)][get<3>(now)] = 0;
			REP(j, 4) {
				int cost = get<0>(now);
				if (grid[get<2>(now)][get<3>(now)] != j) {
					cost += costings[j];
				}
				int direction = get<1>(now) + j;
				direction %= 4;
				int next_x = get<2>(now) + xe[direction];
				int next_y = get<3>(now) + ye[direction];
				if (next_x >= 0 && next_x < h && next_y >= 0 && next_y < w) {
					if (dp[direction][next_x][next_y] > cost) {
						dp[direction][next_x][next_y] = cost;
						next.push(make_tuple(cost, direction, next_x, next_y));
					}
				}
			}
		}
		cout << min({ dp[0][h - 1][w - 1],dp[1][h - 1][w - 1] ,dp[2][h - 1][w - 1] ,dp[3][h - 1][w - 1] }) << endl;
	}
}


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

int main() {
    string s;
    cin >> s;
    bool ans = false;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ans = true;
    if (ans) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[10],t[10];
    int c=0;
	scanf("%s%s",s,t);
	if(s[0]==t[0]) {++c;}
	if(s[1]==t[1]) {++c;}
	if(s[2]==t[2]) {++c;}
	 printf("%d\n",c);
	 return 0;
}

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

int main() {
  int n, count = 0;
  cin >> n;
  vector<int> vec1(n, 0);
  vector<int> vec2(n, 0);
  for(int i = 0; i < n; i++){
    cin >> vec1.at(i);
    vec2.at(i) = i + 1;
    if(vec1.at(i) != vec2.at(i)) count++;
  }
  if(count == 2|| count == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

# 左から順にみていき、左隣のaが多いなら、自分の飴を減らす
count = 0
for i in range(1, n):
    if a[i - 1] + a[i] > x:
        # print("hit:{}".format(i))
        if a[i - 1] <= x:
            count += a[i - 1] + a[i] - x
            a[i] -= a[i - 1] + a[i] - x
        else:
            count += a[i]
            a[i] = 0
            count += a[i-1] - x
            a[i-1] = x
    # print(a)
print(count)

Measured memory_bytes: 14548
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// https://atcoder.jp/contests/abc128/submissions/5650221
fn main() {
    input! {
        n: usize,
        k: usize,
        vs: [i32; n],
    }
    let mut vsr = vs.clone();
    vsr.reverse();
    let mut res = 0;

    // 左と右から何個もらうか
    for kt in 0..k + 1 {
        for l in 0..kt + 1 {
            let mut have = Vec::new();
            let mut ret = 0;
            // 左からもらう
            for i in 0..min(l, n) {
                have.push(vs[i]);
                ret += vs[i];
            }

            // 右からもらう 普通にlから全部もらうまたは、kt内でもらえるだけもらう
            for i in min(n, max(l, n-min(n, kt-l)))..n {
                have.push(vs[i]);
                ret += vs[i];
            }
            have.sort();

            // 負の価値の宝石を手放す kt内で手放せるだけ手放す、または全て手放す
            for i in 0..min(have.len(), k-kt) {
                if have[i] < 0 {
                    ret += have[i] * -1;
                }
            }
            res = max(ret, res);
        }
    }
    println!("{}", res);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    mint ans = 0;
    combination  comb(m);
    rep(i, n+1) {
        mint res = comb(n, i);
        res *= comb.fact[m-i];
        res *= comb.ifact[m-n];
        if (i%2==1) ans -= res;
        else ans += res;
        //debug(ans);
    }

    mint x = comb.fact[m];
    x *= comb.ifact[m-n];
    ans *= x;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10900
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    s = set(S() for _ in range(n))

    return len(s)


print(main())





Measured memory_bytes: 32872
H, W, K = map(int, input().strip().split())
cake = [list(input().strip()) for _ in range(H)]
ans = [[0] * W for _ in range(H)]

cake_count_row = [0] * H
for y in range(H):
    count = 0
    for x in range(W):
        if cake[y][x] == '#':
            count += 1
    cake_count_row[y] = count

count = 1
for y in range(H):
    first = True
    if cake_count_row[y] == 0:
        continue
    for x in range(W):
        if cake[y][x] == '#':
            if first:
                first = False
            else:
                count += 1
        ans[y][x] = count
    count += 1

for y in range(1, H):
    if cake_count_row[y] == 0:
        for x in range(W):
            ans[y][x] = ans[y-1][x]

for y in range(H-1)[::-1]:
    if cake_count_row[y] == 0:
        for x in range(W):
            ans[y][x] = ans[y+1][x]

for i in range(H):
    print(" ".join(list(map(str, ans[i]))))

Measured memory_bytes: 7924
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

ll dp[1004][1004];
char a[1004][1004];


int main()
{
    run;
    ll h,w;
    cin>>h>>w;
    fr(i,0,h)
    {
        fr(j,0,w)
        {
            cin>>a[i][j];
        }
    }
    dp[0][0]=1;
    fr(i,1,w)
    {
        if(a[0][i]=='.')
        {
            dp[0][i]=1;
        }else{
        break;}
    }
    fr(i,1,h)
    {
        if(a[i][0]=='.')
        {
            dp[i][0]=1;
        }else
        break;
    }
    fr(i,1,h)
    {
        fr(j,1,w)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0;
                continue;
            }
            if(a[i-1][j]=='.')
            {
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=MOD;
            }
            if(a[i][j-1]=='.')
            {
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=MOD;
            }
        }
    }
    cout<<dp[h-1][w-1];










}


Measured memory_bytes: 9088
/*=================================
# Created time: 2017-04-05 11:23
# Filename: c.cpp
# Description: 
=================================*/
#include <bits/stdc++.h> 
 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define pii pair<int, int> 
#define ls(a,b) (((a)+(b)) << 1) 
#define rs(a,b) (((a)+(b)) >> 1) 
#define fin(a) freopen(a,"r",stdin); 
#define fout(a) freopen(a,"w",stdout); 
#define FORP(i,a,b) for(int i=(a);i<=(b);i++) 
#define FORM(i,a,b) for(int i=(a);i>=(b);i--) 
 
#define maxn 100005 
#define maxm 100005 
#define MOD 1000000007 
#define INF 1070000000 
using namespace std; 
typedef long long ll; 
typedef unsigned long long ull; 
 
template<class T> inline   
void read(T& num){   
    num = 0; bool f = 1;char ch = getchar();   
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}   
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}   
    num = f ? num: -num;   
}  
template<class T> inline 
void write(T x,char ch){ 
	int s[100]; 
	if (x==0) {putchar('0'); putchar(ch); return;} 
	if (x<0) {putchar('-'); x=-x;} int num=0; 
	while (x){ s[num++]=(x%10); x=x/10;} 
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch); 
} 
/*==================split line==================*/ 
const double pi = acos(-1); 
const double eps = 1e-8; 
int a[maxn];
int main(){ 
	ll n; read(n); n++;
	memset(a, 0x7f, sizeof(a));
	int head = 1, tail = 100, top = INF;
	while (n > 1){
		if (n & 1){
			a[head++] = top--; n --;
		}
		else {
			a[tail--] = top--; n >>= 1; 
		}
	}
	write((INF - top) * 2,'\n');
	FORP(i, 1, 100) if (a[i] <= INF) write(a[i] - top,' ');
	FORP(i, top + 1, INF) write(i - top,' '); puts("");

}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
    return 0;
}


Measured memory_bytes: 256
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const N = parseInt(inputList[0].split(" ")[0]);
    const A = inputList[1].split(" ").map(ele => parseInt(ele));
    const Max = 1000001;

    let count = new Array(Max).fill(0);

    for (let i = 0; i < N; i++) {
        if (count[A[i]] != 0) {
            count[A[i]] = 2;
            continue;
        }

        for (let j = A[i]; j < Max; j += A[i]) {
            count[j]++;
        }
    }

    let result = 0;
    for (let i = 0; i < N; i++) {
        if (count[A[i]] == 1) {
            result++;
        }
    }

    console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 53048
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int h, w, k; cin >> h >> w >> k;
    vector<vector<int>> mz(h,vector<int>(w));
    rep(i,h){
        rep(j,w){
            char c; cin >> c;
            if (c == '#') mz[i][j] = 1;
            else mz[i][j] = 0;
        }
    }
    int ans = 0;
    int lp = 0;
    rep(i,1<<(h+w)){
        int cnt = 0;
        auto g = mz;
        //cout << "!" << endl;
        rep(j,h){
            if (i>>j&1){
                rep(l,w) g[j][l] = 0;
            }
        }
        rep(j,w){
            if (i>>(h+j)&1){
                rep(l,h) g[l][j] = 0;
            }
        }
        rep(j,h) rep(l,w) if (g[j][l] == 1) cnt++;
        if (cnt == k) ans++;
        //cout << "#" << endl;
        //cout << lp << endl; lp++;
    }
    //cout << "!!" << endl;
    cout << ans << endl;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))

kMod = 10**9+7

mem = [0, 0, 0]
cnt = 1

for a in A:
   if a not in mem:
       cnt = 0
       break
   cnt *= mem.count(a)
   cnt %= kMod
   mem[mem.index(a)] = a+1
print(cnt)

Measured memory_bytes: 20776
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int main(){
    double a,b;cin >> a >> b;
    cout << setprecision(10) << fixed << a/b << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
    long long int ans = 0;
    int mod = 1000000007;
    for (long long int i = k;i<=n+1;i++){
        long long int mini = (i*(i-1))/2;
        long long int maxi = n*i-((i-1)*i)/2;
        long long int cur = maxi-mini+1;
        ans+=cur;
    }
    ans = ans%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

ll mypow(ll X, ll n) {  // 繰り返し２乗法　計算量log(n)
    if(n == 0) return 1ll;
    ll Y = mypow(X, n/2);
    if(n % 2 == 1) return X * Y % MOD * Y % MOD;
    else return Y * Y % MOD;
}

int main() {
    int n; cin >> n;
    vector<ll> A;
    rp(i, 0, n) {
        ll a; cin >> a; A.emplace_back(a);
    }
    sort(A.begin(), A.end());
    ll res = 0;
    ll b = mypow(2ll, n-1);
    rp(i, 0, n) {
        ll c = mypow(2ll, n-2) * (n - i -1) % MOD;
        c += b;
        c %= MOD;
        c = c * A[i] % MOD;
        c = c * b * 2 % MOD;
        res = (res + c) % MOD;
    }
    cout << res << endl;
    return 0;
}


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

int main(){
    int h, w, a[500*500], ansn = 0;
    vector<int> aa, ab, ac, ad;

    cin >> h >> w;
    for(int i=0; i<h; ++i){
        for(int k=0; k<w; ++k){
            if(i&0b1) cin >> a[(i + 1)*w-1 - k];
            else cin >> a[i*w + k];
        }
    }

    for(int i=0; i<h*w-1; ++i){
        if(a[i]&0b1){
            aa.emplace_back(i/w+1);
            
            if((i/w)&0b1) ab.emplace_back(w - (i - (i/w)*w));
            else ab.emplace_back(i - (i/w)*w + 1);
            
            if((i+1)%w == 0) { 
                ac.emplace_back(i/w+1+1);

                if((i/w)&0b1) ad.emplace_back(1);
                else ad.emplace_back(w);
            }
            else { 
                ac.emplace_back(i/w+1);
                
                if((i/w)&0b1) ad.emplace_back(w - (i - (i/w)*w) - 1);
                else ad.emplace_back(i - (i/w)*w + 1 + 1);
            }

            --a[i];++a[i+1];
            ++ansn;
        }
    }

    cout << ansn << endl;
    for(int i=0; i<ansn; ++i)
        cout << aa[i] << " " << ab[i] << " " << ac[i] << " " << ad[i] << endl;
}

Measured memory_bytes: 5220
N = int(input())
S = input()
 
oE = S.count("E")
Wo = 0

L = []
for i in range(N):
    if i == 0:
        if S[i] == "E":
            oE -= 1
    else:
        if S[i-1] == "W":
            Wo += 1
        if S[i] == "E":
            oE -= 1
    L.append(Wo + oE)
    if Wo + oE == 0:
        break
print(min(L))

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  long k;
  cin >> s >> k;
  int i,j;
  int kk = 100 ;
  if(k<100) kk=k;
  for(i=0;i<kk;i++){
    j=i;
    if(s[i]!='1')break;
  }
  cout << (int)(s[j]-'0');
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int k, x;
  readf("%s %s\n", &k, &x);

  if (k * 500 >= x) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s[n];
    for(int i = 0;i<n;i++)
    {
        cin >> s[i];
    }
    int m;
    cin >> m;
    string t[m];
    for(int i = 0;i<m;i++)
    {
        cin >> t[i];
    }
    int cnt,ans = 0;
    for(int i = 0;i<n;i++)
    {
        cnt = 0;
        for(int j = 0;j < n;j++)
        {
            if(s[i] == s[j])
            {
                cnt++;
            }
        }
        for(int j = 0;j<m;j++)
        {
            if(s[i] == t[j])
            {
                cnt--;
            }

        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}


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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

int main(){
    int n,m,s;
    cin >> n >> m;

    int a[n],b[n],c[m],d[m];
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    rep(i,m){
        cin >> c[i] >> d[i];
    }

    rep(i,n){
        int ans(0);
        s = getmd(a[i],b[i],c[0],d[0]);
        rep(j,m){
            if(s>getmd(a[i],b[i],c[j],d[j])){
                s = getmd(a[i],b[i],c[j],d[j]);
                ans = j;
            }
        }
        cout << ans+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 384