akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#define M_PI 3.1415926535897932384626433832795

int main() {
	int n;
	int k;
	cin >> n >> k;
	vector<int>h(n);
	rep(i, n) {
		cin >> h[i];
	}
	int count(0);
	rep(i, n) {
		if (h[i] >= k) {
			++count;
		}
	}
	cout << count;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n,m;
    cin>>n>>m;
    set<ll> st;
    vector<ll> p(n);
    for(ll i=0;i<n;i++){
	cin>>p[i];
    }
    ll res = 1;

    vector<ll> dp(n,1);
    for(ll i=1;i<n;i++) if( p[i-1] < p[i] ){
	dp[i] += dp[i-1];
    }
    bool flag = false;
    for(ll i=0;i<m;i++)st.insert(p[i]);
    for(ll i=1;i<=n-m;i++){
	auto s = st.begin();
	auto t = st.end();
	t--;
	ll mini = *s;
	ll maxi = *t;
	if( (p[i-1]==mini && p[i+m-1] > maxi) || dp[i+m-1] >= m  ){
	    //cout<<p[i-1]<<' '<<p[i+m-1]<<endl;
	}else{
	    res ++;
	}
	if( dp[i + m-1] >= m ) flag =  true;
	st.erase( p[i-1] );
	st.insert( p[i-1+m] );
    }
    if( flag && dp[m-1] <m  ) res ++;
    cout<<res<<endl;

    return 0;
}


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

int main(){
  int N,x;cin>>N>>x;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int d=0,num=1;
  for(int i=1;i<N+1;i++){
    d=d+a[i-1];
    if(d<=x){
      num++;
    }
  }

  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=1005;
int mp[MAXN][MAXN],n,m,A,B;
int main()
{
	n=read();m=read();A=read();B=read();
	for(int i=1;i<=n-B;i++)for(int j=1;j<=A;j++)mp[i][j]=1;
//	for(int i=1;i<=n-B;i++)for(int j=A+1;j<=m;j++)mp[i][j]=0;
	for(int i=n-B+1;i<=n;i++)for(int j=A+1;j<=m;j++)mp[i][j]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)putchar(mp[i][j]+'0');
		puts("");
	}
}


Measured memory_bytes: 5120
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    int a = gi();
    int b = gi();
    int k = gi();
    for (int i = 100; i > 0; i--)
        if (a%i == 0 && b%i == 0) {
            k--;
            if (!k) {
                printf("%d\n", i);
                break;
            }
        }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,r;
  scanf("%d%d",&a,&b);
  if(a+b>=a-b)if(a+b>=a*b)r=a+b;
  if(a-b>=a+b)if(a-b>=a*b)r=a-b;
  if(a*b>=a+b)if(a*b>=a-b)r=a*b;
  printf("%d",r);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    int A[N+1];
    int B[N+1];
    int C[N+1];

    for (int i=1;i<=N;i++){
        cin >> A[i];
    }
    for (int i=1;i<=N;i++){
        cin >> B[i];
    }
    for (int i=1;i<=N-1;i++){
        cin >> C[i];
    }
    int sum=B[A[1]];
    int befor = A[1];

    for (int i=2;i<=N;i++){
        sum += B[A[i]];
        
        if (A[i] - befor == 1){
            
            sum += C[A[i]-1];
        }
        befor = A[i];
        
    }
    cout << sum;

}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

VVI adj;
VB visited;
// 0 : black 1 : white  -1 : uncoloured
VI colour;
int n;

void dfs(int here, int col)
{
	colour[here] = col;
	visited[here] = true;
	for(auto there : adj[here])
		if((colour[there] == -1 || colour[there] == col) 
		&& !visited[there])
			dfs(there, col);
}

const int INF = (int)1e9;
void bfs(int start, VI& parent, VI& dist)
{
	parent = VI(n, -1);
	dist = VI(n, INF);
	queue<int> q;

	dist[start] = 0;
	parent[start] = start;
	q.push(start);

	while(q.empty() == false)
	{
		int here = q.front();
		q.pop();

		for(int there : adj[here])
		{
			if(parent[there] == -1)
			{
				parent[there] = here;
				dist[there] = dist[here] + 1;
				q.push(there);
			}
		}
	}
}

bool FennecWins()
{
	VI parent, dist;
	bfs(0, parent, dist);

	int dest = n - 1;
	VI order(1, dest);
	while(parent[dest] != dest)
	{
		dest = parent[dest];
		order.emplace_back(dest);
	} 

	reverse(ALL(order));

	colour.assign(n, -1);
	colour[0] = 0, colour[n - 1] = 1;
	for(int i = 0, j = sz(order) - 1; i <= j; ++i, --j)
	{
		colour[order[i]] = 0;
		if(colour[order[j]] == -1)
			colour[order[j]] = 1;
	}

	visited = VB(n, false);
	dfs(0, 0);
	visited = VB(n, false);
	dfs(n - 1, 1);

	int fennec = 0, snuke = 0;
	for(int col : colour)
	{
		fennec += col == 0;
		snuke += col == 1;
	}

	assert(snuke + fennec == n);
	return snuke < fennec;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	adj.resize(n);
	REP(i, 0, n - 1) {
		int u, v;
		cin >> u >> v;

		--u; --v;
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}

	if(FennecWins() == true)
		 cout << "Fennec" << endl;
	else
		 cout << "Snuke" << endl;

	return 0;
}

Measured memory_bytes: 9720
n,q=[int(x) for x in input().rstrip().split()]
ab=[[]for j in range(n)]

for i in range(n-1):
  a,b=[int(x) for x in input().rstrip().split()]
  ab[a-1].append(b-1)
  ab[b-1].append(a-1)
cnt=[0]*(n)


for i in range(q):
  p,x=[int(x) for x in input().rstrip().split()]
  cnt[p-1]+=x

done=[False]*n
stack=[0]
done[0]=True
while(stack):
  q=stack.pop()
  for i in ab[q]:
    if done[i]==False:
      stack.append(i)
      done[i]=True
      cnt[i]+=cnt[q]

print(*cnt)
    



  



Measured memory_bytes: 55824
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var wa = IntArray(n){0};
    val ac = BooleanArray(n);
    repeat(m) {
        val l = readLine()!!.split(" ")
        val p = l[0].toInt()-1
        val isAc = l[1] == "AC";
        if(!isAc && !ac[p]) wa[p]++
        else if(isAc) ac[p] = true
    }
    println(""+ac.count { it } +" "+ wa.mapIndexed { i, x -> if(ac[i]) x else 0 }.sum())
}

Measured memory_bytes: 55328
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
#define tc int t;scanf("%d",&t);while (t--0)
#define int long long
typedef vector<int> vll;
typedef vector<vll> vvll;
const int N=2e5+5;

const int MOD=1e9+7;

int power(int x, int p) 
{
    int res = 1;
    while (p) 
   {
        if (p % 2) 
	{
            res = (res * x) % MOD;
            --p;
        }
        else {
            x = (x * x) % MOD;
            p /= 2;
        }
    }
    return res;
}
int invmod(int x) {return power(x,MOD-2);}
int dp[N];
int a[N];
int n,k;

void go(int s,int pre,int p)
{
	if(s>n)
		return;
	dp[s]=min(dp[s],pre+abs(a[p]-a[s]));
	for(int i=1;i<=k;i++)
	{
		go(s+i,dp[s],s);
	}
}
int32_t main()
{
	
	
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	for(int i=0;i<=n+5;i++)
	{
		dp[i]=LLONG_MAX;
	}
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=2;j++)
		{
			if(i+j<=n)
			{
				dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
			}
		}
	}
	cout<<dp[n]<<endl;


}

	
	


	




	


Measured memory_bytes: 1792
pos = 0
s = ""
def read():
    global pos
    global s

    result = ""
    ruiseki = 0
    while pos < len(s):
        if s[pos] == '+':
            ruiseki += 1
        elif s[pos] == '-':
            ruiseki -= 1
        elif s[pos] == '[':
            pos += 1
            result += read()
            pos -= 1
        elif s[pos] == ']':
            pos += 1
            return result[::-1]
        elif s[pos] == '?':
            result += 'A'
            ruiseki = 0
        else:
            order = ord(s[pos]) + ruiseki
            while order < 65:
                order += 26
            while order > 90:
                order -= 26
            result += chr(order)
            ruiseki = 0

        pos += 1

    return result


while True:
    pos = 0
    s = input()
    if s == ".":
        break

    print(read())



Measured memory_bytes: 5568
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    
    for (int i = 0; i < S.length(); i++) {
      if ((S.charAt(i) == 'R' && (i+1) % 2 == 0)
      || (S.charAt(i) == 'L' && (i+1) % 2 != 0)
      ) {
        System.out.println("No");
        return;
      } else {
        continue;
      }
    }
    
    System.out.println("Yes");
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <queue>
#include <cstring>

using namespace std;

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

class Node{
public:
	int floor, h, w, flag;
	Node(int floor, int h, int w, int flag) : floor(floor), h(h), w(w), flag(flag) {}
};

int bitCount(int t){
	int res = 0;
	for(int i=t;i;i&=(i-1)) res++;
	return res;
}

int main(){
	int W, H, S;
	string mp[50];
	int mask[50][50];
	int floor[50][50];
	static int cost[2][50][50][1024];
	while(cin >> W >> H && W){
		memset(mask, 0, sizeof(mask));
		memset(floor, 0, sizeof(floor));

		for(int h=0;h<H;h++) cin >> mp[h];
		cin >> S;
		for(int i=0;i<S;i++){
			for(int h=0;h<H;h++){
				string str; cin >> str;
				for(int w=0;w<W;w++){
					if(str[w] == '*') mask[h][w] |= 1<<i;
				}
			}
		}

		queue<Node> qu;
		memset(cost, -1, sizeof(cost));

		for(int h=0;h<H;h++){
			for(int w=0;w<W;w++){
				if(mp[h][w]=='^' || isupper(mp[h][w]))
					floor[h][w] = 1;
				if(mp[h][w]=='%'){
					qu.push(Node(0, h, w, 0));
					cost[0][h][w][0] = 0;
				}
			}
		}

		int res = -1;

		while(!qu.empty()){
			Node nd = qu.front(); qu.pop();
			int fl = nd.floor, h = nd.h, w = nd.w, flag = nd.flag;
			if(mp[h][w]=='&'){
				res = cost[fl][h][w][flag];
				break;
			}
			if(mp[h][w]=='|'){
				if(cost[1-fl][h][w][flag] == -1){
					cost[1-fl][h][w][flag] = cost[fl][h][w][flag]+1;
					qu.push(Node(1-fl, h, w, flag));
				}
			}
			if(isalpha(mp[h][w])){
				int s = isupper(mp[h][w]) ? mp[h][w]-'A' : mp[h][w]-'a';
				int nflag = flag^(1<<s);
				int nfl = (floor[h][w]+bitCount(mask[h][w]&nflag))%2;
				if(cost[nfl][h][w][nflag] == -1){
					cost[nfl][h][w][nflag] = cost[fl][h][w][flag]+1;
					qu.push(Node(nfl, h, w, nflag));
				}
			}

			for(int i=0;i<4;i++){
				int nh = h+dx[i], nw = w+dy[i];
				if(mp[nh][nw]=='#') continue;
				if(mp[nh][nw]!='|' && fl != (floor[nh][nw]+bitCount(mask[nh][nw]&flag))%2) continue;

				if(cost[fl][nh][nw][flag] == -1){
					cost[fl][nh][nw][flag] = cost[fl][h][w][flag]+1;
					qu.push(Node(fl, nh, nw, flag));
				}
			}
		}
		cout << res << endl;
	}
}

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

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
    fast();
    ll n,k;
    cin>>n>>k;
    ll cnt=0;
    while(n){
    	n=n/k;
    	cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    -500<=a,b>=500;
    if(a<b){
     printf("a < b\n");
    }else if(a>b){
     printf("a > b\n");
    }else if(a==b){
     printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 1008
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
p = LIST()
c = LIST()

for i in range(n):
    p[i] -= 1

ans = -inf
for i in range(n):
    visit = [inf]*n
    reg_score = [-inf]*n

    now = i
    count = 0
    score = 0
    while visit[now] == inf:
        visit[now] = count
        reg_score[now] = score
        count += 1
        now = p[now]
        score += c[now]

    x = visit[now]
    y = count - visit[now]
    X = reg_score[now]
    Y = score - reg_score[now]

    for j in range(n):
        if visit[j] == inf:
            continue
        if j != i and k >= visit[j]:
            tmp0 = reg_score[j]
            if ( k - x ) % y >= visit[j]:
                tmp1 = (k - x)//y * Y + reg_score[j]
            else:
                tmp1 = ((k - x)//y - 1) * Y + reg_score[j]
            ans = max(ans, tmp0, tmp1)
        elif (k-x)//y>0:
            tmp0 = Y + reg_score[j]
            if ( k - x ) % y >= visit[j]:
                tmp1 = (k - x)//y * Y + reg_score[j]
            else:
                tmp1 = ((k - x)//y - 1) * Y + reg_score[j]
            ans = max(ans, tmp0, tmp1)

print(ans)

Measured memory_bytes: 103532
#include <bits/stdc++.h>
 
using namespace std;
 
constexpr int LIMIT = 7368791;
 
bool used[LIMIT+1];
 
int main()
{
    int m, n;
    while (cin >> m >> n, m) {
        int cnt = 0;
        memset(used, 0, sizeof(used));
        for (int i = m; cnt < n; i++) {
            if (!used[i]) {
                cnt++;
                for (int j = i; j <= LIMIT; j += i) {
                    used[j] = 1;
                }
            }
        }
        for (int i = m; ; i++) {
            if (!used[i]) {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 10120
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int[] ints = new int[6];

		for (int i = 0; i < 6; i++) {
			ints[i] = Integer.parseInt(sc.next());
		}

		for (int i = 1; i <= 4; i++) {
			int count = 0;
			for (int j = 0; j < 6; j++) {
				if (ints[j] == i) count++;
			}

			if (count == 3) {
				System.out.println("NO");
				sc.close();
				return;
			}
		}

		System.out.println("YES");

		sc.close();
	}

}


Measured memory_bytes: 23764
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int take[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, minn = 99999999;
int n, m;
int A, B, C, maxlen;

struct MyStruct
{
	bool a = false, b = false, c = false;
	int list[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	int mnp = 0;
};

int func(int cnt, int a, int b, int c) {

	if (cnt == n) {
		if (a == 0 || b == 0 || c == 0) {
			return 99999999;
		}
		
		return abs(a - A) + abs(b - B) + abs(c - C) - 30;
	}

	int ret0 = func(cnt + 1, a, b, c);
	int ret1 = func(cnt + 1, a + take[cnt], b, c) + 10;
	int ret2 = func(cnt + 1, a, b + take[cnt], c) + 10;
	int ret3 = func(cnt + 1, a, b, c + take[cnt]) + 10;

	return min({ret0, ret1, ret2, ret3});
}

signed main() {

	MyStruct st;

	cin >> n >> A >> B >> C;


	for (int i = 0; i < n; i++) {
		cin >> take[i];
		//cin >> st.list[i];
	}

	//func(st);
	cout << func(0, 0, 0, 0) << endl;



	return 0;
}

Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    S = [list(input().rstrip()) for _ in range(N)]
    ans = 0
    for B in range(N):
        for i in range(N):
            ni = (i + B) % N
            for j in range(N):
                nj = (j + B) % N
                if S[i][nj] != S[j][ni]:
                    break
            else:
                continue
            break
        else:
            ans += 1
    print(ans * N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44552
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int k; readV(k);
  int x; readV(x);
  int y; readV(y);

  writeln(n <= k ? n*x : k*x+(n-k)*y);
}


Measured memory_bytes: 256
/*
   _  __  U _____ u  _  __    
  |"|/ /  \| ___"|/ |"|/ /    
  | ' /    |  _|"   | ' /     
U/| . \\u  | |___ U/| . \\u   
  |_|\_\   |_____|  |_|\_\    
,-,>> \\,-.<<   >>,-,>> \\,-. 
 \.)   (_/(__) (__)\.)   (_/  
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define zhfs main
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 1; i <= n; i++)
int zhfs()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int a, b;
	cin >> a >> b;
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	if (a == b)
	{
		cout << "Draw" << endl;
	}
	else if (a > b)
	{
		cout << "Alice" << endl;
	}
	else
	{
		cout << "Bob" << endl;
	}
}



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

# 移動ベクトル
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

def dfs(h, w):
    seen[h][w] = True
    
    # 次の探索位置を取得
    for dir in range(8):
        nh, nw = h + dx[dir], w + dy[dir]
        if nh < 0 or nh >= H or nw < 0 or nw >= W: continue
        if field[nh][nw] == 0: continue
        if seen[nh][nw] == True: continue
        dfs(nh, nw)
        
while True:
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    
    field = [[int(i) for i in input().split()] for j in range(H)]

    seen = [[False for i in range(W)] for j in range(H)]

    count = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w] == False and field[h][w] == 1:
                dfs(h, w)
                count += 1

    print(count)


Measured memory_bytes: 7984
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

struct Var;
struct Add;
struct LT;

int p = 3;

vector<string> command;

struct Var{
    int pos;
    Int val;
    Var(int pos=-1, Int val = 0):pos(pos), val(val){
        if(this->pos == -1)this->pos = p++;
    }
    void operator=(Add);
    void operator=(LT);
 };

struct Add{
    Var x, y;
    Add(Var x, Var y):x(x),y(y){}
};

void Var::operator=(Add add){
    command.push_back(
        "+ " + to_string(add.x.pos) + " " + to_string(add.y.pos) + " "  + to_string(pos)
    );
    val = add.x.val + add.y.val;
}

Add operator+(Var x, Var y){
    return Add(x,y);
}

struct LT{
    Var x, y;
    LT(Var x, Var y):x(x),y(y){}
};

void Var::operator=(LT lt){
    command.push_back(
        "< " + to_string(lt.x.pos) + " " + to_string(lt.y.pos) + " "  + to_string(pos)
    );
    if(lt.x.val < lt.y.val)val = 1;
    else val = 0;
}



LT operator<(Var x, Var y){
    return LT(x,y);
}

void from_binary(vector<Var> &vars, Var &target){
    target = target < target;
    for(int i = int(vars.size()) - 1;i >= 0;i--){        
        target = target + target;
        target = target + vars[i];
    }
}


Var zero;
Var one;

void into_binary(Var &source, vector<Var> &bin){
    int n = bin.size();
    Var source1;
    source1 = source + one;
    Var tmp;
    for(int i = n-1;i >= 0;i--){
        bin[i] = zero < one;
        from_binary(bin, tmp);
        bin[i] = tmp < source1;
    }
}

int main(){
    int _a=0, _b=0;
//    cin >> _a >> _b;
    Var a(0, _a), b(1, _b);
    Var ans(2);
    Var x;
    one = zero < a;
    zero = zero < b;
    one = one + zero;
    zero = zero < zero;
    one = zero < one;
    p = 5;
    vector<Var> binaries(63);
    binaries[0] = zero < one;
    for(int i = 1;i < 63;i++){
        binaries[i] = binaries[i-1] + binaries[i-1];
    }
    vector<Var> binA(31);
    vector<Var> binB(31);
    vector<Var> binC(63);
    into_binary(a, binA);
    into_binary(b, binB);
    for(int i = 0;i <= 30;i++){
        for(int j = 0;j <= 30;j++){
            x = binA[i] + binB[j];
            x = one < x;
            binC[i + j] = binC[i + j] + x;
        }
    }
    from_binary(binC, ans);    
    cout << command.size() << endl;
    for(auto c:command)cout << c << endl;
//    cout << ans.val << endl;
    return 0;
}

Measured memory_bytes: 3300
# 
import sys

from sys import stdin
input = lambda: stdin.readline().rstrip()


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

a_idx = 0
b_idx = -1
ans = 0
k = 0
for i in range(len(A)):
    if k + A[i] < K:
        k = k + A[i]
        a_idx = i + 1
        ans = i
    else :
        k = k + A[i]
        a_idx = i + 1
        ans = i
        break

now = ans + 1

if a_idx == len(A):
    A.append(0)
    a_idx = a_idx + 1
    now = now + 1

try:
    for i in reversed(range(a_idx)):
        # Aを一冊どかす
        k = k - A[i]
        now = now - 1

        # Bが何冊引けるか
        b_idx_tmp = b_idx + 1
        tmp = k + B[b_idx_tmp]
        while tmp <= K:
            b_idx_tmp = b_idx_tmp + 1
            tmp = tmp + B[b_idx_tmp]

        # 最後に足されたBは足しちゃいけなかったのでマイナスする
        # スタート時と引いたあとのidxの差が新たに追加された冊数
        k = tmp - B[b_idx_tmp]
        drawed = (b_idx_tmp-1) - b_idx
        now = now + drawed
        b_idx = b_idx_tmp - 1
        ans = max(now, ans)
#        print("-------")
#        print("a_idx = " + str(i))
#        print("b_idx = " + str(b_idx))
#        print("now = " + str(now))
#        print("k = " + str(k))
#        print("b_idx_tmp = " + str(b_idx_tmp))
#        print("drawed = " + str(drawed))

except IndexError:
    # 引けなくなっちゃった場合なので、計算だけする
    # Bだけパターンは考慮しなくていい（B全て+Aを足してもKに達していないパターンなので）
    # k = tmp - B[b_idx_tmp] 足せなかったので引かなくていい
    drawed = (b_idx_tmp-1) - b_idx
    now = now + drawed
    b_idx = b_idx_tmp-1
    ans = max(now, ans)
 
print(ans)

Measured memory_bytes: 39756
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	printf("%d\n", (n - 1) / 2);
}


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

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/

ll gd(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}




int main(void){
    const ll M = 1000000007;
    ll n,k;
    bool x = true;
    string ans;
    ll c[3][3];
    ll a[2][3];
    ll b[3][2];
    for(ll i = 0; i < 3; i++)for(ll j = 0; j < 3; j++)cin >> c[i][j];

    for(ll i = 0; i < 3; i++)for(ll j = 0; j < 2; j++)b[i][j] = c[i][j+1]-c[i][j];
    
    for(ll i = 0; i < 2; i++)for(ll j = 0; j < 3; j++)a[i][j] = c[i+1][j]-c[i][j];
    
    for(ll i = 0; i < 2; i++){
    if(a[i][0] == a[i][1] && a[i][1] == a[i][2] && x == true){
        x = true;
    }
    else
    {
        x = false;
    }
    }
    
    for(ll i = 0; i < 2; i++){
    if(b[0][i] == b[1][i] && b[1][i] == b[2][i] && x == true){
        x = true;
    }
    else
    {
        x = false;
    }
    }
    
    if(x)ans = "Yes";
    else ans = "No";
    
    cout << ans << endl;
   
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
ll a[40001000];
//ll number[20],used[20];
int main()
{
  string a,b,c,d,s,t,e,f,g;
  cin>> s;
  a = "SAT";
  b="SUN";
  c="MON";
  d="TUE";
  e="WED";
  f="THU";
  g="FRI";
  if(a==s)
    cout << "1" << endl;
  if(b==s)
    cout << "7" << endl;
  if(c==s)
    cout << "6" << endl;
    if(d==s)
    cout << "5" << endl;
    if(e==s)
    cout << "4" << endl;
    if(f==s)
    cout << "3" << endl;
    if(g==s)
    cout << "2" << endl;
  //cout << a << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N; cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; ++i){
    cin >> data.at(i);
  }
  
  sort(data.begin(), data.end());
  
  if(data.at(N-1) == 0){
    cout << "Yes" << endl;
    return 0;
  }

  if(N%3 != 0){
    cout << "No" << endl;
    return 0;
  }
  
  bool flag = true;
  
  if(data.at(0) == 0){
    if(data.at(N/3 - 1) == 0 && data.at(N/3) == data.at(N-1)){
      cout << "Yes" << endl;
      return 0;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  
  long long a = data.at(0);
  long long b = -1;
  long long c = -1;
  
  for(int i = 0; i < N; ++i){
    if(data.at(i) != a && b == -1) b = data.at(i);
    else if(data.at(i) != a && data.at(i) != b && c == -1) c = data.at(i);
  }
  
  long long d = a ^ b;
  
  if(c == -1){
    flag = false;
  }else if(data.at(N/3 - 1) != a || data.at(N*2/3 - 1) != data.at(N/3) || data.at(N - 1) != data.at(N*2/3)){
    flag = false;
  }else if(d != c) flag = false;
    
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#define FOR(i,n) for(i = 0; i < n; i++)

int main(void){
    char M;
    int RankS[13], RankH[13], RankC[13], RankD[13];
    int R;
    int n, i, j;
    FOR(i, 13){
        RankS[i] = i + 1;
        RankH[i] = i + 1;
        RankC[i] = i + 1;
        RankD[i] = i + 1;
    }
    scanf("%d", &n);
    FOR(i,n){
        scanf(" %c %d", &M, &R);
        switch (M){
        case 'S':
            RankS[R - 1] = 0;
            break;
        case 'H':
            RankH[R - 1] = 0;
            break;
        case 'C':
            RankC[R - 1] = 0;
            break;
        case 'D':
            RankD[R - 1] = 0;
            break;
        }
    }

    FOR(i, 13){
        if (RankS[i] != 0)printf("S %d\n", RankS[i]);
    }FOR(i, 13){
        if (RankH[i] != 0)printf("H %d\n", RankH[i]);
    }FOR(i, 13){
        if (RankC[i] != 0)printf("C %d\n", RankC[i]);
    }FOR(i, 13){
        if (RankD[i] != 0)printf("D %d\n", RankD[i]);
    }
    return 0;
}

Measured memory_bytes: 596
N = gets.chomp.to_i
p = gets.chomp.split(" ").map(&:to_i)

def makeOrder()
  ary = []
  ary.fill(0, N) {|i| i+1}
end

class Array
  def diff(ary)
    retAry = []
    self.each_index{ |i|
      if self[i] != ary[i]
        retAry.push(self[i])
      end
    }
    retAry
  end
end

diffAry = p.diff(makeOrder())

if diffAry.empty?
  puts "YES"
elsif diffAry.length == 2 && p.index(diffAry[0])+1 == diffAry[1]
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 1788
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_SIZE_MAX		100										// 最大サイズ

// 内部変数
static int siH, siW;											// 高さ・幅
static int siX, siY;											// 現在位置
static int si2Mass[D_SIZE_MAX + 5][D_SIZE_MAX + 5];				// マス目

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 色セット
int
fSetColor(
	int piColor					// <I> 色
)
{
	// セット
	si2Mass[siY][siX] = piColor;

	// 次回位置
	if (siY % 2 == 0) {
		if (siX < siW - 1) {
			siX++;
		}
		else {
			siY++;
		}
	}
	else {
		if (siX > 0) {
			siX--;
		}
		else {
			siY++;
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// データ初期化
	siX = 0;													// 現在位置X
	siY = 0;													// 現在位置Y

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 高さ・幅取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &siH, &siW);

	// 色種類数取得
	int liCCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liCCnt);

	// 各色取得
	for (i = 0; i < liCCnt; i++) {
		int liColor;
#ifdef D_TEST
		fscanf(szpFpT, "%d", &liColor);
#else
		fscanf(stdin, "%d", &liColor);
#endif

		// 色セット
		for (j = 0; j < liColor; j++) {
			fSetColor(i + 1);
		}
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// 結果表示
	for (i = 0; i < siH; i++) {
		sprintf(lc1Out, "%d", si2Mass[i][0]);
		for (j = 1; j < siW; j++) {
			sprintf(lc1Buf, " %d", si2Mass[i][j]);
			strcat(lc1Out, lc1Buf);
		}
		strcat(lc1Out, "\n");
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
		if (strcmp(lc1Buf, lc1Out)) {
			siRes = -1;
		}
#else
		printf("%s", lc1Out);
#endif
	}

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

ans = 0
for i in range(n-2):
  if p[i] < p[i+1] and p[i+1] < p[i+2]:
    ans += 1
  if p[i] > p[i+1] and p[i+1] > p[i+2]:
    ans += 1
    
print(ans)

Measured memory_bytes: 3060
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n,a,b,c = inp
abc = [a,b,c]
ans = []
st = "ABC"
h = {"AB" => [0,1],"BC"=>[1,2],"AC"=>[2,0]}
ss=[]
cs=[]
me = nil
n.times do |i|
  ss << gets.chomp
  if(me != ss[i])
    me = ss
    cs << ss[i]
  end
end
csi = 0
csize =cs.size
cs << cs[-1]
me = nil
n.times do |i|
  s= ss[i]
  if(s == cs[csi])
    csi = small(csi+1,csize-1)
  end
  cd = h[s]
  if(abc[cd[0]]==abc[cd[1]] and abc[cd[0]] == 1 and i != n-1)
    unless(h[ss[i+1]].include?(cd[0]))
      abc[cd[0]] -= 1
      abc[cd[1]] += 1
      ans << st[cd[1]]
    else
      abc[cd[0]] += 1
      abc[cd[1]] -= 1
      ans << st[cd[0]]
    end
  elsif(abc[cd[0]]>=abc[cd[1]])
    abc[cd[0]] -= 1
    abc[cd[1]] += 1
    ans << st[cd[1]]
  else
    abc[cd[0]] += 1
    abc[cd[1]] -= 1
    ans << st[cd[0]]
  end
  unless abc.all?{|u|u>=0}
    puts "No"
    exit
  end
end
puts "Yes"
puts ans

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

int main()
{
   int n,k,i,a[100],j,t,sum;
   while(cin>>n>>k)
   {
       sum=0;
       memset(a,0,sizeof(a));
       for(i=0;i<n;i++)
        cin>>a[i];
       for(i=0;i<n;i++)
            for(j=0;j<n-i-1;j++)
                if(a[j]>a[j+1])
                {
                        t=a[j];
                        a[j]=a[j+1];
                        a[j+1]=t;
                }
        for(i=n-k;i<n;i++)
        {
            sum+=a[i];
        }

        cout<<sum<<endl;
   }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int N;
  cin >> N;
  int n = N;
  int goukei = 0;
  for(int i = 0; i < 9; i++){
    goukei += N % 10;
    N = N / 10;
  }
  if(n % goukei == 0){
    cout <<"Yes"<< endl; 
  }
  else{
    cout <<"No"<< endl;
  }
}

Measured memory_bytes: 3620
<?php


$input=explode(' ',trim(fgets(STDIN))) ;
$m = $input[0];
$d = $input[1];
$counter = 0 ;

for($i=1;$i<$m+1;$i++){
 for($j=22;$j<$d+1;$j++){
   $d_2 = intval($j/10) ;
   $d_1 = $j-$d_2*10 ;
   if($d_1>1&&$i == $d_1*$d_2){
   $counter++ ;
   
   }
 }
}

echo $counter ;


Measured memory_bytes: 3828
fun main(args: Array<String>){
	val n = readLine()!!.toInt()
	var array = readLine()!!.split(" ")
	val a = Array(array.size){
		array[it].toInt()
	}
	array = readLine()!!.split(" ")
	val b = Array(array.size){
		array[it].toInt()
	}
	array = readLine()!!.split(" ")
	val c = Array(array.size){
		array[it].toInt()
	}
	
	var result = 0
	for(i in 0 until n)
		result += b[a[i].toInt()-1]
	for(i in 1 until a.size)
		if( a[i] == a[i-1]+1 )
			result += c[a[i-1]-1]
	
	println(result)
}


Measured memory_bytes: 36128
#include <bits/stdc++.h>
using namespace std;
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTG(c) sort((c).begin(),(c).end(),greater<auto>())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int main(){
  int  si;
  LL ans=0, cnt=1, cntz=0, n, f=0, l=0;
  string s;
  cin >> s;
  si=s.size();
  s+='!';
  cin >> n;
  bool r=false, zero=false, last=false;
  vector <LL> v;
  REP(i, si){
    if(s[i]==s[i+1]){
      cnt++;
    }else{
      v.PB(cnt);
      cnt=1;
    }
    if(s[0]==s[1]) zero=true;
    if(s[si-2]==s[si-1]) last=true;
  }
  if(zero) f=v[0];
  LL ls=v.size();
  if(last) l=v[ls-1];
  if(ls==1) ans=(si*n)/2;
  else if(s[0]!=s[si-1]){
    REP(i, ls){
      ans+=(v[i]/2)*n;
    }
  }else{
    REP(i, ls) ans+=(v[i]/2)*n;
    ans-=(n-1)*(l/2+f/2-(f+l)/2);
  }
  cout << ans << endl;
  //cout << cnt << endl;
  //cout << cntz << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int h,w,i,j,p=1,q=1;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0 && w==0){
      break;
 }
    for(i=1;i<=h;i++){ 
      if(i%2==0){
	for(j=1;j<=w;j++){
	  if(j%2==0){
	    printf("#");
	  }else{
	    printf(".");
	    }
	}
      }	else {
	for(j=1;j<=w;j++){
	  if(j%2==0){
	    printf(".");
	  }else{
	    printf("#");
	  }
	}
      }
      printf("\n");
    }
    printf("\n"); 
  }
  return 0;
}

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

struct UnionFind
{
    vector<int> p;//親が誰か
    UnionFind(int n)
    {p.resize(n,-1);}//全ての要素について、自分を親にする（初期化）
    int find(int x)
    {
     if(p[x]==-1) return x;
     //else return find(p[x]);
     else return p[x]=find(p[x]);//パス圧縮(一度findしたものは、自分の親を集合の代表にする)
    }
    void unite(int x,int y)
    {x=find(x);
     y=find(y);
     if(x==y)return; //すでに代表が同じ（＝同じ集合）なら何もしない
     p[x]=y;

    }
    
};


int main() {
    int n,q;
    cin>>n>>q;
    UnionFind uf(n);//ufは、変数名のようなもの（UnionFind型のデータ構造 "uf"を宣言している）
    int p,a,b;
    rep(i,q)
    {cin>>p>>a>>b;
    if(p==0)uf.unite(a,b);
    if(p==1){
        if(uf.find(a)==uf.find(b))cout<<1<<endl;
        else cout<<0<<endl;     
     }
    }



return 0;
}


Measured memory_bytes: 3204
import java.util.*;

public class Main {
        
    public static void main(String[] args){
        
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[][] ju = new boolean[n+1][n+1];
        
        for(int i=0;i<n+1;i++){
            Arrays.fill(ju[i],false);
        }
        
        ArrayList<ArrayList<Integer>> gr = new ArrayList<ArrayList<Integer>>();
        
        for(int i=0;i<2;i++){
            gr.add(new ArrayList<Integer>());
        }
        
        for(int i=0;i<n;i++){
            int u = sc.nextInt();
            int k = sc.nextInt();
            for(int j=0;j<k;j++){
                int v = sc.nextInt();
                ju[u][v] = true;
            }
        }
         
        int[] d = new int[n+1];
        Arrays.fill(d,-1);
        d[1] = 0;
         
        for(int i=0;i<n;i++){
            for(int k=1;k<=n;k++){
                if(d[k]==i){
                    for(int j=1;j<=n;j++){
                        if(ju[k][j] && d[j]==-1){
                            d[j] = d[k] + 1;
                        }
                    }
                }
            }
        }
         
        for(int i=1;i<=n;i++){
            System.out.println(i+" "+d[i]);
        }
    }
}

Measured memory_bytes: 28348
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 1e+10

int main(){
  long double x[4], y[4];
  int n;
  cin >> n;
  while( n-- ){
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3];
    long double left, right;
      left  = (y[1] - y[0]) * (x[3] - x[2]);
      right = (y[3] - y[2]) * (x[1] - x[0]);

    if ( left == right ) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 3164
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N,M = map(int,input().split())
    cake = [tuple(map(int,input().split())) for _ in range(N)]
    
    ans = 0
    for bit in range(1<<3):
        op = [-1] * 3
        for i in range(3):
            if (bit>>i)&1:
                op[i] = 1
        cake.sort(key = lambda x:x[0]*op[0] + x[1]*op[1] + x[2]*op[2],reverse=True)
        ans = max(ans,sum(op[0]*c[0] + op[1]*c[1] + op[2]*c[2] for c in cake[:M]))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68616
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | y >= 0     = "delicious"
        | abs y <= x = "safe"
        | otherwise  = "dangerous"
 where
  [x, a, b] = fmap read (words s) :: [Int]
  y         = a - b

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
N,W = map(int,input().split(" "))
INF =  1e11
v = [INF]*100010
v[0] = 0
for i in range(N):
  weight,value = map(int,input().split(" "))
  for j in range(100001,0,-1):
    if j < value:
      break
    v[j] = min(v[j],v[j-value]+weight)

ans = 0
for i in range(100001,0,-1):
  if v[i] <= W:
    ans = i
    break
print(ans)


Measured memory_bytes: 77308
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scanln(&N)
	data := make([]int, N)
	min := math.MaxInt64
	for i := 0; i < N; i++ {
		var n int
		fmt.Scan(&n)
		data[i] = n
		if min > n {
			min = n
		}
	}

	for min > 1 {
		next := min
		for i, n := range data {
			d := n % min
			if min != n && d > 0 {
				data[i] = d
				if d < next {
					next = d
				}
			}
		}
		if min == next {
			break
		}
		min = next
	}

	fmt.Println(min)
}


Measured memory_bytes: 5504
using System;
using System.Globalization;

class Program {
  static void Main(string[] args) {
    string s = Console.ReadLine();
    int n = int.Parse(s);
    ulong[] t = new ulong[n];
    for (int i=0; i<n; i++) {
      string tmp = Console.ReadLine();
        t[i] = (ulong)Int64.Parse(tmp);
    }

    ulong max = 1;
    for (int i=0; i<n; i++) {
      max = Euc(max, t[i]);
    }
    Console.WriteLine(max);
  }

  static ulong Euc(ulong a, ulong b) {
    if (a < b) {
      ulong tmp = b;
      b = a;
      a = tmp;
    }

    ulong pa = a;
    ulong pb = b;

    ulong r = a % b;
    while(r != 0) {
      a = b;
      b = r;
      r = a % b;
    }

    return (pa / b) * pb;
  }
}



Measured memory_bytes: 13140
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();
    int G = sc.nextInt();
    int[] p = new int[D];
    int[] c = new int[D];
    for (int i =0; i<D; i++) {
      p[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    int min =1001; int count =0; int ans =0;
    int a = 4;
    for (int i =0; i<Math.pow(2,D); i++) {
      String bit = String.format("%" + D + "s", Integer.toBinaryString(i)).replace(' ', '0');
      int N = bit.length();
      for (int j=0; j<N; j++) {
        if (bit.charAt(j) == '1' ) {
          count += p[j] * (j + 1) * 100 + c[j];
          ans += p[j];
        }
      }
      if (count<G) {
        for (int j=N-1; j>=0; j--) {
          if (bit.charAt(j) == '0' ) {
            int l = p[j];
            while (count < G && l > 0) {
              count += (j + 1) * 100;
              ans++;
              l--;
            }
          }
        }
      }
      if (count >= G) {
        min = Math.min(ans,min);
      }
      count =0;
      ans =0;
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 43876
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    for (int i = 1; i <= 3; i++) {
      if (A == i || B == i) continue;
      System.out.println(i);
      return;
    }
  }
}


Measured memory_bytes: 23764