akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto u = s[1] - 1;
    auto v = s[2] - 1;
    auto G = new int[][](N);
    foreach (i; 0..N-1) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    auto d = new int[](N);
    auto b = new bool[](N);
    auto dd = new int[](N);

    void dfs3(int n, int p, int v) {
        dd[n] = v;
        foreach (m; G[n]) if (m != p) {
            dfs3(m, n, v+1);
        }
    }

    bool dfs2(int n, int p) {
        if (n == u) return b[n] = true;
        foreach (m; G[n]) if (p != m) {
            if (dfs2(m, n)) return b[n] = true;
        }
        return false;
    }

    int dfs(int n, int p) {
        foreach (m; G[n]) if (m != p) {
            if (p == -1 && !b[m] ) continue;
            d[n] = max(d[n], dfs(m, n) + 1);
        }
        return d[n];
    }

    dfs3(v, -1, 0);
    dfs2(v, -1);
    dfs(v, -1);

    int dist = dd[u] / 2 - (1 - dd[u] % 2);
    int ans = 0;

    foreach (i; 0..N) if (b[i] && dd[u] - dd[i] <= dist) {
        int turn = (dd[u] - dd[i]);
        int hoge = (dd[i] - turn) % 2;
        int val = d[i] + dd[u] - dd[i];
        val = hoge ? val :  val + 1;
        ans = max(ans, val);
    }

    ans.writeln;
}

Measured memory_bytes: 18300
using System.Collections.Generic;
using System;

public class Jugyo
{
    public int from { get; set; }
    public int to { get; set; }
    public int teach { get; set; }
    public int stud { get; set; }
}
public class FromTo
{
    public int from { get; set; }
    public int to { get; set; }
}
public class hello
{
    public static void Main()
    {
        var jugyos = new List<Jugyo>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n1 = int.Parse(line[0]);
        var f = new FromTo();
        for (int i = 0; i < n1; i++)
        {
            GetFromTo(f, line[i + 1]);
            jugyos.Add(new Jugyo { from = f.from, to = f.to });
        }
        GetCount(jugyos, "T");
        GetCount(jugyos, "S");
        var ans = 0;
        foreach (var x in jugyos)
            ans += Math.Min(x.teach, x.stud);
        Console.WriteLine(ans);
    }
    public static void GetCount(List<Jugyo> j, string TorS)
    {
        var f = new FromTo();
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n1 = int.Parse(line[0]);
            for (int k = 0; k < n1; k++)
            {
                GetFromTo(f, line[k + 1]);
                foreach (var x in j)
                {
                    if (TorS == "T" && f.from <= x.from && f.to >= x.to ) x.teach++;
                    if (TorS == "S" && f.from <= x.from && f.to >= x.to) x.stud++;
                }
            }
        }
    }
    public static void GetFromTo(FromTo f, string s)
    {
        string[] s2 = s.Split(':', '-');
        f.from = int.Parse(s2[0]) * 60 + int.Parse(s2[1]);
        f.to = int.Parse(s2[2]) * 60 + int.Parse(s2[3]);
    }
}

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


Measured memory_bytes: 35608
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  //freopen("gout.txt", "w", stdout);
#endif
}

void solve()
{
  
    map<string,int>mp;
    mp["SUN"]=7;
    mp["MON"]=1;
    mp["TUE"]=2;
    mp["WED"]=3;
    mp["THU"]=4;
    mp["FRI"]=5;
    mp["SAT"]=6; 
    
    string s;
    cin >> s;

    int k = mp["SUN"] -  mp[s];
    if(k==0) cout<<"7";
    else cout<<k;
}
 
 
int32_t main()
{
  pr_init();
  fastio;
   
  
  solve();
   
}
 


Measured memory_bytes: 3624
// http://tsutaj.hatenablog.com/entry/2017/01/25/161050
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;


struct KnapWithLimitations{
	ll N,W;
	vector<ll> v,w,m,dp;
	KnapWithLimitations(ll n,ll ww){
		N=n;W=ww;
		v.resize(N);
		w.resize(N);
		m.resize(N);
		dp.resize(W+1,0);
	}
	ll maxvalue(){
		FOR(i,0,N){
			for(ll k=0;m[i]>0;k++){
				ll key = min(m[i],(ll)(1<<k));
				m[i] -= key;
				for(ll j=W;j>=key*w[i];j--){
					dp[j] = max(dp[j],dp[j-key*w[i]]+key*v[i]);
				}
			}
		}
		ll ans = 0;
		FOR(i,0,W+1)ans=max(ans,dp[i]);
		return ans;
	}
};



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,w;
	cin >> n >> w;
	KnapWithLimitations KL(n,w);
	FOR(i,0,n){
		cin >> KL.v[i] >> KL.w[i] >> KL.m[i];
	}
	cout << KL.maxvalue() << endl;
}



Measured memory_bytes: 3324
package main

import "fmt"

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max3(a, b, c int) int {
	return max(max(a, b), c)
}

func main() {
	var (
		a, b, c int
		ch      byte
	)
	fmt.Scanln(&a, &b, &c)
	m := max3(a, b, c)
	switch m {
	case a:
		ch = 'A'
	case b:
		ch = 'B'
	case c:
		ch = 'C'
	}
	fmt.Printf("%c\n", ch)
}


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

typedef long long LL;

const int N=200000;

int n,m,a[N+9];
int cnt[N+9];

bool Get_a(){
  for (int i=1;i<=n;++i) cnt[i]=0;
  for (int i=1;i<=n;++i){
	int l=max(i-a[i],1),r=min(i+a[i],n);
	++cnt[l];--cnt[r+1];
  }
  for (int i=1;i<=n;++i) a[i]=cnt[i]+=cnt[i-1];
  for (int i=1;i<=n;++i)
	if (a[i]<n) return 0;
  return 1;
}

int main(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
  for (int i=1;i<=m;++i)
	if (Get_a()) break;
  for (int i=1;i<=n;++i)
	printf("%d ",a[i]);
  puts("");
  return 0;
}

Measured memory_bytes: 5248
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int k = 1;
    int max = 1;

    for (int i = 1; i < x; i++) {
      for (int j = 2; j < x; j++) {
        k = (int)Math.pow(i,j);
        if (k <= x) {
          max = Math.max(max,k);
        }
      }
    }

    System.out.println(max);

  }

}


Measured memory_bytes: 21844
N,Q=map(int,(input()).split())
S=input()
Count=[0]
count=0
for i in range(1,N):
  if S[i-1:i+1]=="AC":
    count+=1
    Count.append(count)
  else:
    Count.append(count)
for i in range(Q):
  l,r=map(int,input().split())
  print(Count[r-1]-Count[l-1])

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

def main():
    """Function."""
    n, a, b = map(int, input().split())

    maxim = min(a, b)
    minim = a + b - n

    if minim > 0:
        print(maxim, minim)
    else:
        print(maxim, 0)


if __name__ == "__main__":
    main()


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

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

int bfs(const vector<string> &v, int x, int y) {
    int res = 0;
    int H = v.size(), W = v[0].size();
    queue<pair<int, int>> q;
    q.push({x, y});
    vector<vector<int>> dist(H, vector<int>(W, -1));
    dist[x][y] = 0;

    while(!q.empty()) {
        int X = q.front().first, Y = q.front().second;
        int nowDist = dist[X][Y];
        res = max(res, nowDist);
        q.pop();

        for(int i = 0; i < 4; ++i) {
            int nx = X + dx[i], ny = Y + dy[i];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(v[nx][ny] == '#') continue;
            if(dist[nx][ny] == -1) {
                dist[nx][ny] = nowDist + 1;
                q.push({nx, ny});
            } 
        }
    }
    return res;
}

int main() { 
    int h, w, ans = 0;
    cin >> h >> w;
    vector<string> v(h);
    for(int i = 0; i < h; ++i) {
        cin >> v[i];
    }
    
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(v[i][j] == '#') continue;
            ans = max(ans, bfs(v, i, j));
        } 
    }
    
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        while(true){
        int result = a % b;
        if(result == 0){
            System.out.println(b);
            break;
        }else{
            a = b;
            b = result;
        }
        }
    }
}


Measured memory_bytes: 26408
import sys
stdin = sys.stdin
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,stdin.readline().split()))
    mod = 10**9+7
    ans = 0
    for i in range(61):
        bits = 0
        for x in A:
            if (x>>i)&1:
                bits += 1
        ans += ((bits*(N-bits))* 2**i) %mod
    ans %= mod
    print(ans)
main()

Measured memory_bytes: 50856
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Measured memory_bytes: 36088
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int k=scan.nextInt();
		int Q=scan.nextInt();
		int A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=0;
		}
		for(int i=0;i<Q;i++) {
			A[scan.nextInt()-1]+=1;
		}
		scan.close();

		for(int i=0;i<n;i++) {
			if(k-Q+A[i]>=1)System.out.println("Yes");
			else System.out.println("No");
		}
	}
}

Measured memory_bytes: 59860
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define Y first
#define X second
#define INF 1 << 30

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

int main(){
  while(scanf("%d%d", &t, &n) && t+n){
    int board[300][300] = {};
    rep(i, 300) rep(j, 300) board[i][j] = INF;
    int x, y;
    rep(i, n){
      scanf("%d%d", &x, &y); 
      board[y+100][x+100] = -1;
    }

    scanf("%d%d", &x, &y); 
    board[y+100][x+100] = 0;
    //    printf("%d %d\n", y+100, x+100);
    queue<pair<int,int> >q;
    q.push(make_pair(y+100, x+100));
    for(int k = 1; k <= t; k++){
      //      printf("%d\n", k);
      int qsize = (int)q.size();
      rep(i, qsize){
	pair<int, int>p = q.front(); q.pop();
	//	printf("%d %d\n", p.Y, p.X);
	rep(j, 6){
	  int nx = p.X + dx[j], ny = p.Y + dy[j];
	  //	  printf("%d %d\n", ny, nx);
	  if(board[ny][nx] <= k) continue;
	  board[ny][nx] = k;
	  q.push(make_pair(ny, nx));
	}
      }

      /*      REP(i, 90, 110){
	REP(j, 90, 110) printf(board[i][j] != INF?"%2d":" N", board[i][j]);
	puts("");
	} */
    }
    int res = 0;
    rep(i, 300) rep(j, 300) if(board[i][j] >= 0 && board[i][j] < INF) res++;



    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1568
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string S;

int main(void){
	
	cin >> S;
	cout << S.front() << (int)S.size() - 2 << S.back() << endl;
	
    return 0;
}

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

/**
 * 選択ソート
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=ja">ALDS1_2_C</a>
 */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String a[] = new String[n];
		String b[] = new String[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.next();
		}

		System.arraycopy(a, 0, b, 0, a.length);

		bubbleSort(a, n);
		System.out.println(Arrays.toString(a).replace("[", "").replace("]", "").replace(",", ""));
		System.out.println("Stable");

		selectionSort(b, n);
		System.out.println(Arrays.toString(b).replace("[", "").replace("]", "").replace(",", ""));
		if (Arrays.equals(a, b)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}

		sc.close();
	}

	private static void bubbleSort(String[] a, int n) {
		boolean flg = true;
		while (flg) {
			flg = false;
			for (int i = n - 1; 0 < i; i--) {
				if (a[i].charAt(1) < a[i - 1].charAt(1)) {
					String tmp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = tmp;
					flg = true;
				}
			}
		}
	}

	private static void selectionSort(String[] a, int n) {
		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i; j < n; j++) {
				if (a[j].charAt(1) < a[minj].charAt(1)) {
					minj = j;
				}
			}
			String tmp = a[minj];
			a[minj] = a[i];
			a[i] = tmp;
		}
	}

}



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

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

	int n,m,c;
	vector <int> b;
	int res = 0;

	cin >> n >> m >> c;

	for(int i=0;i<m;i++)
	{
		int t;
		cin >> t;
		b.push_back(t);
	}

	for(int i=0;i<n;i++)
	{
		int cnt = 0;
		for(int j=0;j<m;j++)
		{
			int t;
			cin >> t;
			cnt += t*b[j];
		}
		cnt += c;
		if(cnt>0)
		{
			res++;
		}
	}

	cout << res << '\n';

	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    if(n==m){cout<< "Yes" <<endl;}
    else {cout<< "No" <<endl;}
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
 
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);
 
    public static void main(String[] args) {
        int n = scanner.nextInt(), a[] = new int[n], sum = 0;
        for (int i = 0; i < n; i++)
            sum += a[i] = scanner.nextInt();
        if (sum % 10 == 0)
            sum -= Arrays.stream(a)
                    .filter(i -> i % 10 != 0)
                    .min()
                    .orElse(0);
        System.out.println(sum % 10 == 0 ? 0 : sum);
    }
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const long double EPS = 1e-10;

vector<ll> d(1001, LLONG_MAX);

bool bellman_ford(int start, int n, vector<edge> edges){
    d[start] = 0LL;
    bool updated, goal;
    rep(2*n){
        updated = false;
        goal = false;
        for(edge e: edges){
            if(d[e.from] != LLONG_MAX && d[e.from] + e.cost < d[e.to]){
                d[e.to] = d[e.from] + e.cost;
                updated = true;
                if(e.to == n-1) goal = true;
            }
        }
        if(i > n && goal) return false;
        if(!updated) return true;
    }
    return true;
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<edge> edges(m);
    int from,to; ll cost;
    rep(m){
        cin >> from >> to >> cost;
        edges[i].from = from-1;
        edges[i].to = to-1;
        edges[i].cost = -cost;
    }
    if(bellman_ford(0, n, edges)){
        cout << -d[n-1] << endl;
    }else{
        cout << "inf" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
//

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()


int main (){
    int N, A, B, tuka=0, Btuka=0;
    string S;
    cin >> N >> A >> B >> S;

    rep(i,0,N){
        if(S[i]=='a'&&tuka<A+B){
            cout << "Yes" << endl;
            tuka++;
        }else if(S[i]=='b'&&tuka<A+B&&Btuka<B){
            cout << "Yes" << endl;
            tuka++; Btuka++;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

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

int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0)
            break;
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N,K;cin>>N>>K;
  ll R,S,P;cin>>R>>S>>P;
  string s;cin>>s;

  //勝てる数を手ごとに保存
  vector<ll> v(3);

  rep(i,K){
    ll prev = 3;
    //iはそれぞれの先頭
    for(int j = 0; i+j<N; j+=K){
      //cout<<i+j<<endl;
      //jはkことばし
        if(s[i+j] == 'r'){
          //paper win
          if(prev != 0){
            v[2]++;
            prev = 0;
          }
          else prev = 3;
        }
        else if(s[i+j] == 's'){
          //rock win
          if(prev != 1){
            v[0]++;
            prev = 1;
          }
          else prev = 3;
        }
        else{
          //scissors win
          if(prev != 2){
            v[1]++;
            prev = 2;
          }
          else prev = 3;
        }
    }
  }
  ll ans = 0;
  //rep(i,3)cout<<v[i]<<endl;
  ans += v[0]*R + v[1]*S + v[2]*P;
  cout<<ans<<endl;

}


Measured memory_bytes: 512
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

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


    int a[3][3],q,count=0,k=0,b;
    unordered_map<int,int> mp;
    for(int i=0; i<3; i++){
    	for(int j=0; j<3; j++){
    		cin>>a[i][j];
    	}
    }
    cin>>q;
    while(q--){
    	cin>>b;
    	mp.insert(make_pair(b,1));
    }
    for(int i=0; i<3; i++){
    	for(int j=0; j<3; j++){
    		if(mp.find(a[i][j])!=mp.end()){
    			count++;
    		}
    		if(mp.find(a[j][i])!=mp.end()){
    			k++;
    		}
    	}		
    	if(count==3||k==3){
    		cout<<"Yes"<<endl;
    		return 0;
    	}
    	count=0,k=0;
    }
    k=0;
    for(int i=0; i<3; i++){
    	if(mp.find(a[i][i])!=mp.end()){
    		k++;
    	}
    }
    if(k==3){
    	cout<<"Yes"<<endl;
    }else if(mp.find(a[0][2])!=mp.end() && mp.find(a[1][1])!=mp.end() && mp.find(a[2][0])!=mp.end()){

        cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }
    return 0;
  }

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

#define int long long
#define w cout
#define e '\n'
#define sz(x) (int)x.size()
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.first >> p.second; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 + 10 , mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a , b; cin >> a >> b;
	int gcd = __gcd(a, b);
	int lcm = (a*b) / gcd;
	cout << lcm;
}
	
		
        


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll BIG_MOD = ll(1e9)+7;
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = BIG_MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= BIG_MOD;
	if (u < 0) { u += BIG_MOD; }
	return u;
}
// 順列
ll permutation(ll n, ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % BIG_MOD; }
	return result;
}
// 組み合わせ
ll combination(ll n, ll m) {
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++) { div = (div * i) % BIG_MOD; }
	return (p * modinv(div)) % BIG_MOD;
}

int main() {
	int N, M;
	cin >> N >> M;

	repeat(i, M) {
		int n = 0;
		cin >> n;
		N -= n;
	}
	if (N < 0) N = -1;

	cout << N << endl;
  return 0;
}


Measured memory_bytes: 3604
package main

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

func main() {
	N := ReadInt()
	m := make(map[string]int)
	for i := 0; i < N; i++ {
		s := ReadString()
		m[s]++
	}
	fmt.Printf("AC x %d\n", m["AC"])
	fmt.Printf("WA x %d\n", m["WA"])
	fmt.Printf("TLE x %d\n", m["TLE"])
	fmt.Printf("RE x %d\n", m["RE"])
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

#define ll long long 
 
using namespace std ;
 
ll z , ans , o ;

ll mod = 1e9 + 7 ;
ll N = 1e5 + 7 ;


int main( ){

	int n , k ;

	cin >> n  >> k ;

	bool a[n] ;

	for( int i = 0 ; i < n ; i ++ ){

		a[i] = false ;

	}

	for( int i = 0 ; i < k ; i ++ ){

		int d ;

		cin >> d ;

		for( int i = 0 ; i < d ; i ++ ){

			int h ;

			cin >> h ;

			a[h-1] = true ;

		}

	}


	for( int i = 0 ; i < n ; i ++ ){

		if( a[i] == false ){

			ans ++ ;

		}

	}

	cout << ans ;

}	



Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MAX_N = 1e+5 + 1;

vector<P> sushi, genre_sushi, add_sushi;

int main() {
    int N, K;
    ll t, d;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> t >> d;
        sushi.push_back(P(d, t));
    }
    ll sum = 0, genre = 0;
    sort(sushi.begin(), sushi.end());
    reverse(sushi.begin(), sushi.end());
    map<int, int> k_genre_cnt;
    for (int i = 0; i < K; i++) {
        sum += sushi[i].first;
        if (k_genre_cnt[sushi[i].second] == 0) genre++;
        k_genre_cnt[sushi[i].second]++;
    }
    ll ans = sum + genre * genre;
    // K+1個目以降の寿司
    for (int i = K; i < sushi.size(); i++) {
        genre_sushi.push_back(sushi[i]);
    }
    map<int, bool> is_unique;  // K+1以降の寿司でK個までの寿司以外の種類の寿司を見つけるためのmap
    for (int i = 0; i < K; i++) {
        is_unique[sushi[i].second] = true;
    }
    for (int i = 0; i < genre_sushi.size(); i++) {
        if (!is_unique[genre_sushi[i].second]) {
            is_unique[genre_sushi[i].second] = true;
            add_sushi.push_back(genre_sushi[i]);
        }
    }
    vector<int> sub_idx;
    for (int i = K - 1; i >= 0; i--) {
        k_genre_cnt[sushi[i].second]--;
        if (k_genre_cnt[sushi[i].second] != 0) {
            sub_idx.push_back(i);
        }
    }
    int max_num = min((int)sub_idx.size(), (int)add_sushi.size());
    ll sub_sum = sum, sub_genre = genre;
    for (int i = 0; i < max_num; i++) {
        sub_sum += add_sushi[i].first - sushi[sub_idx[i]].first;
        sub_genre++;
        ans = max(ans, sub_sum + sub_genre * sub_genre);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10480
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  ll N, K;
  cin >> N >> K;
  ll res = 0;
  if (K==0) {
    cout << N*N << endl;
    return 0;
  }
  for (int b=K+1; b<=N; b++) {
    res += (b-K)*(N/b);
    if (N%b>=K) res += N%b-K+1;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 210
#define INF 1e9
const int diff = 105;
 
struct State{
    int n,x,y,t;
    bool operator < (const State &s)const{
	return n > s.n;
    }
};
 
int sx,sy,gx,gy,lx,ly;
bool can[MAX][MAX];
int dist[MAX][MAX][6];
const int dx[7] = {0,1,1,0,-1,-1,0};
const int dy[2][7] = {{1,0,-1,-1,-1,0,0},
                      {1,1,0,-1,0,1,0}};
 
inline bool inField(int x,int y){
    x -= diff; y -= diff;
    return -lx <= x && x <= lx && -ly <= y && y <= ly;
}
 
int dijkstra(){
    priority_queue<State> Q;
    Q.push((State){0,sx,sy,0});
    for(int i = 0 ; i < MAX ; i++){
	for(int j = 0 ; j < MAX ; j++){
	    for(int k = 0 ; k < 6 ; k++){
		dist[i][j][k] = INF;
	    }
	}
    }
    dist[sy][sx][0] = 0;
 
    while(!Q.empty()){
	State s = Q.top(); Q.pop();
	int x = s.x, y = s.y, t = s.t;
	if(dist[y][x][t] < s.n) continue;
	if(x == gx && y == gy) return dist[gy][gx][t];
	int xx = x-diff,yy = y-diff;
	int ndir = abs(xx*yy*t)%6, nt = (t+1)%6;
	for(int i = 0 ; i < 7 ; i++){
	    int nx = x + dx[i], ny = y + dy[abs(xx)%2][i];
	    if(!inField(nx,ny) || !can[ny][nx]) continue;
	    if(i == ndir){
		if(dist[y][x][t] < dist[ny][nx][nt]){
		    dist[ny][nx][nt] = dist[y][x][t];
		    Q.push((State){dist[ny][nx][nt],nx,ny,nt});
		}
	    }else{
		if(dist[y][x][t]+1 < dist[ny][nx][nt]){
		    dist[ny][nx][nt] = dist[y][x][t]+1;
		    Q.push((State){dist[ny][nx][nt],nx,ny,nt});
		}
	    }
	}
    }
    return -1;
}
 
int main(){
    int N,x,y;
    for(int i = 0 ; i < MAX ; i++){
	for(int j = 0 ; j < MAX ; j++){
	    can[i][j] = true;
	}
    }
    cin >> sx >> sy >> gx >> gy >> N;
    sx += diff; sy += diff; gx += diff; gy += diff;
    for(int i = 0 ; i < N ; i++){
	cin >> x >> y;
	x += diff; y += diff;
	can[y][x] = false;
    }
    cin >> lx >> ly;
    cout << dijkstra() << endl;
    return 0;
}

Measured memory_bytes: 4324
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bitset>
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;
const int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    int a[200010] = {};
    for(int i = 2;i <= n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 4440
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
m=n%10 
if m==2 or m==4 or m==5 or m==7 or m==9:
    print("hon") 
elif m==0 or m==1 or m==6 or m==8:
    print("pon")
else:
    print("bon")
    
    
            
            
            
    
    
    
    
        
        
    
    
        
            
    
    
    
    
    
    
            
            
            
    

    

Measured memory_bytes: 62068
N = list(map(int, input()))
N.insert(0, 0)
count = 0
for i in range(len(N)-1, -1, -1):
    if N[i] <= 4 or (N[i] == 5 and N[i-1] <= 4):
        count += N[i]
    else:
        count += 10 - N[i]
        N[i-1] = N[i-1] + 1
print(count)

Measured memory_bytes: 14564
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char h[] = new char[4];
    for(int i=0;i<4;i++){
      h[i] = S.charAt(i);
    }
    String answer = "No";
    Arrays.sort(h);
    if(h[0]==h[1]&&h[1]!=h[2]&&h[2]==h[3]){
      answer = "Yes";
    }
    System.out.println(answer);
    
  }
  
  //最大公約数・最小公倍数（セットで使う）
static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
static int lcm (int a, int b) {return a*b/gcd(a,b);}


//素数判定
static boolean isPrime (int n) {
	if (n==2) return true;
	if (n<2 || n%2==0) return false;
	double d = Math.sqrt(n);
	for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
	return true;
}


//倍数判定（10進数以外のときに有用）
static boolean isMultiple (String s, int base, int m) {
	int temp = 0;
	for (int i=0; i<s.length(); i++) {
		temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
	}
	if (temp==0) {return true;}
	return false;
}


//階乗
static long factorial (int i) {
	if (i==1) {return 1;}
	else {return i*factorial(i-1);}
}


//進数変換
static String toNbase (String sm, int m, int n) {
	return Long.toString(Long.parseLong(sm,m),n);
}
  
}

Measured memory_bytes: 21588
n,m = map(int, input().split())
a = [int(input()) for i in range(m)]

# print(a)

mod = 10**9 + 7

d = [0]*(n+1)
# print(len(d))
# print(d)
d[0] = 1
d[1] = 1
for i in a:
    d[i] = -1

# print(d)


for i in range(2,n+1):
    if d[i]==0 and d[i-1]==-1 and d[i-2]==-1:
        print(0)
        exit()
    elif d[i]==0 and d[i-1]==-1 and d[i-2]!=-1:
        d[i] = d[i-2]
    elif d[i]==0 and d[i-1]!=-1 and d[i-2]==-1:
        d[i] = d[i-1]
    elif d[i]==0 and d[i-1]!=-1 and d[i-2]!=-1:
        d[i] = d[i-1] + d[i-2]
# print(d)
print(d[n]%mod)

Measured memory_bytes: 460020
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(void){
    long long x,k,d,ans;
    cin >> x >> k >> d;
    x = abs(x);
    if(x/d>k){
        cout << x-k*d << endl;
    }else{
        k-=x/d;
        x-=x/d*d;
        if(k%2==0){
            cout << x << endl;
        }else{
            cout << d-x << endl;
        }
    }

	return 0;
}

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

mod = 998244353

fac = [1, 1]
ifac = [1, 1]
inverse = [0, 1]

for i in range(2, n):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    ifac.append((ifac[-1] * inverse[-1]) % mod)

ans = 0
for i in range(n-k-1, n):
    j = min(i, n-i-1)
    com = fac[n-1] * ifac[j] * ifac[n-j-1] % mod
    res = m
    e = m - 1
    while i > 0:
        if i & 1:
            res = res * e % mod
        e = e * e % mod
        i >>= 1
    res = res * com % mod
    ans = (ans + res) % mod

print(ans)

Measured memory_bytes: 113388
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N, K = getNM()
S = input()

flag = S[0]
sta = 1
lista = []
# 14 2
# 11101010110011なら
# ２回まで0の箇所を消すことができる

# 00010を['0', 1, 3], ['1', 4, 4], ['0', 5, 5]という風に整頓する
for i in range(1, N):
    if flag != S[i]:
        # flag(0か1か), sta(どこから続いているか), i(最終的にどこまで続いたか)
        lista.append([flag, sta, i])
        flag = S[i]
        sta = i + 1
lista.append([flag, sta, N])
ans = 0
np = len(lista)
for i in range(np):
    if lista[i][0] == '0':
        index = min(i + 2 * K - 1, np - 1)
        opt = lista[index][2] - lista[i][1] + 1
        ans = max(ans, opt)
    else:
        index = min(i + 2 * K, np - 1)
        opt = lista[index][2] - lista[i][1] + 1
        ans = max(ans, opt)
print(ans)

Measured memory_bytes: 62300
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <string>
#include <set>

using namespace std;
typedef long long ll;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,k; cin >> n >> k;
    if(2*k >= n){
        cout << "0\n";
    }
    else cout << (n-2*k) << "\n";
}

Measured memory_bytes: 256
N,K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0

for i in range(N+1): # 左端から取り出す回数
    for j in range(N+1-i): # 右端から取り出す回数
        L = V[:i]
        if j == 0:
            R = []
        else:
            R = V[-j:]
        LR = L + R
        if len(LR) > K:
            continue
        num_drop = min(len(LR), K-i-j)
        LR.sort()
        total = sum(LR)
        idx = 0
        while idx < num_drop:
            if LR[idx] < 0:
                total -= LR[idx]
                idx += 1
            else:
                break
        ans = max(ans, total)


print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include<string>
#include <cmath>
#include <iostream>

using namespace std;

int main(){
	int a,b,i,k,n;
	int count=0;
	int p[51],q[51];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&p[i]);
	}
	a=0;
	for(i=1;i<=n-1;i++){
		if((p[i]-p[i+1])>0){
			q[i]=1;
			if(a==0){a=i;
			}else{b=i;}
			count++;
		}else{q[i]=0;}
	}
	if(count==0){cout<<"YES"<<endl;
	}else if(count>=3){cout<<"NO"<<endl;
	}else if(count==1){
		k=p[a];
		p[a]=p[a+1];
		p[a+1]=k;
		count=0;
		for(i=1;i<=n-1;i++){
			if((p[i]-p[i+1])>0){
				q[i]=1;
				count++;
			}else{q[i]=0;}
		}
		if(count==0){cout<<"YES"<<endl;
		}else{cout<<"NO"<<endl;}
	}else{
		k=p[a];
		p[a]=p[b+1];
		p[b+1]=k;
		count=0;
		for(i=1;i<=n-1;i++){
			if((p[i]-p[i+1])>0){
				q[i]=1;
				count++;
			}else{q[i]=0;}
		}
		if(count==0){cout<<"YES"<<endl;
		}else{cout<<"NO"<<endl;}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int vmax=100000;
int par[vmax*2],siz[vmax*2];
void init(int x){
    for(int i=0;i<x;i++){
        par[i]=i;
        siz[i]=1;
    }
}
int root(int x){
    if(par[x]==x){
        return x;
    }
    return par[x]=root(par[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y){
        return ;
    }
    par[y]=x;
    siz[x]+=siz[y];
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    init(vmax*2);
    vector<ll> a(vmax*2),b(vmax*2),x(n),y(n);
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
        x[i]--,y[i]--;
        unite(x[i],y[i]+vmax);
    }
    for(int i=0;i<2*vmax;i++){
        if(i<vmax){
            a[root(i)]++;
        }
        else{
            b[root(i)]++;
        }
    }
    ll ans=0;
    for(int i=0;i<2*vmax;i++){
        ans+=a[i]*b[i];
    }
    cout << ans-n << endl;
}

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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var h = vals[0];
        var w = vals[1];
        var sum = h / 2 * w;
        if (h % 2 == 1)
        {
            sum += (w + 1) / 2;
        }

        if (h == 1 || w == 1)
        {
            sum = 1;
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

int main() {
	int x;
	cin >> x;
	if (x == 7 || x == 5 || x == 3) cout << "YES"<<endl;
	else cout << "NO"<<endl;
}

Measured memory_bytes: 256
line = input()

digits = '0123456789'
chars = list(map(lambda x:digits.find(x), line))

def isMM(part):
    num = part[0] * 10 + part[1]
    if 0 < num and num < 13:
        return True

def test(chars):
    if -1 in chars:
        return 3
    partA = chars[0:2]
    partB = chars[2:4]
    
    resultA = isMM(partA)
    resultB = isMM(partB)
    
    if resultA is True:
        if resultB is True:
            return 2
        else:
            return 1
    else:
        if resultB is True:
            return 0
        else:
            return 3
    
    
result = test(chars)
if result == 0:
    print("YYMM")
elif result == 1:
    print("MMYY")
elif result == 2:
    print("AMBIGUOUS")
elif result == 3:
    print("NA")


Measured memory_bytes: 38384
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int t=scn.nextInt();
        int a=scn.nextInt();
        int[] place=new int[n];
        for(int i=0;i<n;i++){
            place[i]=scn.nextInt();
        }
        double dif=Math.abs(t-0.006*place[0]-a);
        int answer =0;
        for(int i=1;i<n;i++){
            if(Math.abs(t-0.006*place[i]-a)<dif){
                dif =Math.abs(t-0.006*place[i]-a);
                answer = i;
            }
        }
        System.out.println(answer+1);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));



int main(){	
	string S;
	long long N;
	long long P;
	scanf("%lld",&N);
	scanf("%lld",&P);
	cin >> S;
	
	vector<ll> ten(N+1);
	ten[0] = 1;
	repn(i, N) ten[i] = ten[i-1]*10%P;
	vector<ll> u(N+1);
	map<ll, ll> m;
	rrep(i, N) {
		u[i] = (u[i+1]+((S[i]-'0')*ten[N-1-i])%P)%P;
		m[u[i]]++;
	}
	m[0]++;
	ll res = 0;
	if (P == 2) {
		rep(i, N) {
			if ((S[i]-'0')%2 == 0) res += i+1;
		}
	} else if (P == 5) {
		rep(i, N) {
			if ((S[i]-'0')%5 == 0) res += i+1;
		}
	} else {
		for (auto x : m) {
			// cout << x.first << " " << x.second << endl;
			res += x.second*(x.second-1)/2;
		}
	}
	cout << res << endl;

	return 0;
}



Measured memory_bytes: 4228
n = int(input())

if n < 105:
	print(0)
elif n == 105 or n == 106:
	print(1)
else:
	if n % 2 == 0:
		length = int(n / 2) - 1
	else:
		length = int(n / 2)
	array = []
	answer = 1
	for i in range(53,length+1):
		number = i * 2 + 1
		for x in range(1,n+1):
			if number % x == 0:
				array.append(x)
		if len(array) == 8:
			answer += 1
		array.clear()
	print(answer)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  rep(i, M) cin >> p[i] >> S[i];
  
  vector<bool> AC(N, false);
  vector<int> penalty(N, 0);
  rep(i, M) {
    if (!AC[p[i] - 1]) {
      if (S[i] == "WA") ++penalty[p[i] - 1];
      else AC[p[i] - 1] = true;
    }
  }
  
  int correctAnswers = 0;
  int penaltys = 0;
  rep(i, N) {
    if (AC[i]) {
      ++correctAnswers;
      penaltys += penalty[i];
    }
  }
  cout << correctAnswers << " " << penaltys << endl;
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
using P = pair<int, int>;

vector<int> A, ans;
int N;
vector<vector<int>> G;

void dfs(vector<int> &dp, int v, int par = -1) {
    int id = lower_bound(ALL(dp), A[v]) - dp.begin();
    int tmp = dp[id];
    dp[id] = A[v];
    ans[v] = lower_bound(ALL(dp), INF) - dp.begin();
    for (auto u : G[v]) {
        if (u != par) {
            dfs(dp, u, v);
        }
    }
    dp[id] = tmp;
}

int main() {
    cin >> N;
    A.resize(N);
    ans.resize(N);
    G.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    vector<int> dp(N + 5, INF);
    dfs(dp, 0);
    for (auto a : ans) {
        cout << a << "\n";
    }
}


Measured memory_bytes: 30824
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, A, B) = read!(usize, i64, i64);
    let X = read![[i64]];

    let mut total = 0;
    for i in 0..N - 1 {
        let d = X[i + 1] - X[i];
        total += min(d * A, B);
    }

    println!("{}", total)
}


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

using namespace std;

int H, W;
string s[100];
bool a[100], b[100];
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> s[i];
  }
  
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '#') {
        a[i] = true;
        b[j] = true;
      }
    }
  }
  
  for (int i = 0; i < H; ++i) {
    if (!a[i]) continue;
    for (int j = 0; j < W; ++j) {
      if (!b[j]) continue;
      cout << s[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long sum = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong() - (long)(i + 1);
      sum += a[i];
    }
    long t = sum / n;
    long ans = Long.MAX_VALUE;
    Arrays.sort(a);
    long t1 = a[n / 2];
    long t2 = 0; 
long t3 = 0; 
    if(((n / 2) + 1) < n) t2 = a[(n / 2) + 1];
    if(((n / 2) - 1) >= 0) t3 = a[(n / 2) - 1];
    long s1 = 0;
    long s2 = 0;
    long s3 = 0;
    for(int i = 0; i < n; i++) {
      s1 += Math.abs(a[i] - t1);
    }
    ans = Math.min(ans, s1);
    for(int i = 0; i < n; i++) {
      s2 += Math.abs(a[i] - t2);
    }
    ans = Math.min(ans, s2);
    for(int i = 0; i < n; i++) {
      s3 += Math.abs(a[i] - t3);
    }
    ans = Math.min(ans, s3);
    System.out.println(ans);
  }
}

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

int main(void){
    long n;
    cin >> n;
    vector<long> v(n);
    for(long i=0; i<n; i++){
        cin >> v[i];
    }
    for(long i=0; i<n; i++){
        if(v[i]%2==1){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 1024