akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int K = reader.nextInt();
		int ans = 0;
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();

		for (int i = 0; i < N; i++) {
			int A = reader.nextInt();
			int value = 1;
			if (map.containsKey(A)) {
				value += map.get(A);
			}
			map.put(A, value);
		}
		int arr[] = new int[map.size()];
		int count = 0;
		for (Entry<Integer, Integer> entry : map.entrySet()) {
			arr[count] = entry.getValue();
			count++;
		}
		Arrays.sort(arr);

		for (int i = 0; i < map.size() - K; i++) {
			ans += arr[i];
		}

		System.out.print(ans);
		reader.close();
	}
}





Measured memory_bytes: 100420
#include <iostream>

using namespace std;

int c[5];

int main(void) {

	int a[4], b[4];

	for (int i = 1; i <= 3; i++) {
		cin >> a[i] >> b[i];
	}

	for (int i =1; i <= 3; i++) {
		c[a[i]]++; c[b[i]]++;
	}

	int sign = 1;

	for (int i = 1; i <= 4; i++) {
		if (c[i] >= 3) { sign = 0; }
	}

	if (sign > 0) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }

	//system("pause");
	return 0;
}

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

int main() {
  long a,b,c,d;
  cin >> a >> b >> c >> d;
  if(labs(a-b)<=d&&labs(b-c)<=d) cout << "Yes" << endl;
  else if(labs(a-c)<=d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=5010;
char str[maxn];
vector<string> dic;
int main(){
	int k;
	scanf("%s%d",str,&k);
	int len=strlen(str);
	for(int i=0;i<len;i++){
		string s;
		for(int j=i;j<i+10 && j<len;j++){
			s+=str[j];
			dic.push_back(s);
		}
	}
	sort(dic.begin(),dic.end());
	dic.erase(unique(dic.begin(),dic.end()),dic.end());
	puts(dic[k-1].c_str());
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,A,B;
    cin>>N>>A>>B;
  	if(N*A>B)
      cout<<B;
  	if(N*A<B)
      cout<<N*A;
  	if(N*A==B)
      cout<<N*A;
  	return 0;
}

Measured memory_bytes: 256
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        m: usize,
        edges: [(usize1,usize1);m],
        s: usize1,
        t: usize1
    }

    let mut adj_list = vec![vec![]; n * 3];
    for &e in &edges {
        let from_base = e.0 * 3;
        let to_base = e.1 * 3;
        adj_list[from_base + 0].push(to_base + 1);
        adj_list[from_base + 1].push(to_base + 2);
        adj_list[from_base + 2].push(to_base + 0);
    }

    let mut visited = vec![false; n * 3];
    let mut walk_count = 0;

    let mut heap = BinaryHeap::new();
    heap.push((0, s * 3));

    while !heap.is_empty() {
        let node = heap.pop().unwrap();
        if visited[node.1] {
            continue;
        }
        visited[node.1] = true;
        if node.1 == t * 3 {
            walk_count = node.0 - 1;
            break;
        }

        for &i in &adj_list[node.1] {
            heap.push((node.0 - 1, i));
        }

        if walk_count < 0 {
            break;
        }
    }

    if walk_count == 0 {
        println!("{}", -1);
    } else {
        println!("{}", -walk_count / 3);
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 27004
#include<iostream>
#include <string>
#include<stack>
#include<cstdlib>

using namespace std;
int main() {

	stack<int> st;
	string str;
	int a, b;
	while (cin>>str){
		if (str == "+") {
			a = st.top(); st.pop();
			b = st.top(); st.pop();
			st.push(a + b);
		}
		else if (str == "-") {
			a = st.top(); st.pop();
			b = st.top(); st.pop();
			st.push(b - a);
		}
		else if (str == "*") {
			a = st.top(); st.pop();
			b = st.top(); st.pop();
			st.push(a*b);
		}
		else {
			st.push(atoi(str.c_str()));
		}
	}
	cout << st.top() << endl;
	return 0;
}


Measured memory_bytes: 3208
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
ans = [0]*N
ac = [0]*N
for _ in range(M):
    p, s = input().split()
    p = int(p)
    if s=='AC':
        ac[p-1] = 1
    else:
        if ac[p-1]!=1:
            ans[p-1] += 1

wa = 0
for i in range(N):
    if ac[i]==1:
        wa += ans[i]

print(sum(ac), wa)

Measured memory_bytes: 75472
n,k,q,*a=map(int,open(0).read().split())
s=sorted
m=1e9
for b in a:
 i=[i for i,t in enumerate(a)if t<b];l=s(sum([s(a[i+1:j])[::-1][k-1:]for i,j in zip([-1]+i,i+[n])],[]))[q-1:]
 if l:m=min(m,l[0]-b)
print(m)

Measured memory_bytes: 113756
import math

N, K = map(int, input().split())

k = []
n = N
tmp = K
i = 0
while tmp >= 2:
    k.append(tmp)
    tmp = tmp / 2
k.append(tmp)
k.append(1)
        
ans = 0
for i in range(len(k)):
    if n >= k[i]:
        ans += math.floor(n + 1 - k[i]) / (2 ** i)
        n -= math.floor(n + 1 - k[i])

ans = ans / N
print("{}".format(ans))  

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num1, num2;

        while(true) {
            num1 = Integer.parseInt(scan.next());
            num2 = Integer.parseInt(scan.next());

            if (num1 == 0 && num2 == 0) break;

            if (num1 < num2) {
                System.out.println(num1 + " " + num2);
            } else {
                System.out.println(num2 + " " + num1);
            }
        }
    }
}



Measured memory_bytes: 35196
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int N;
int A[214514];

int solve(int f){
    int sum=0;
   REP(i,N){
       sum+=abs(A[i]-f);
   }
   return sum;
}

signed main(void){
   cin >> N;
   REP(i,N){
       cin >> A[i];
       A[i]-=(i+1);
   }
   sort(A,A+N);
   
   
   //めぐる式(？)三分探索
   int ok=A[N-1],ng=A[0],mid1=ng+1,mid2=ok-1;
   while(abs(ok-ng)>2){
       mid1=(ng+ng+ok)/3;
       mid2=(ng+ok+ok)/3;
       
       //最大値の時は>、最小値の時は<
       if(solve(mid1)<solve(mid2)){
           ok=mid2;
       }else{
           ng=mid1;
       } 
   }
   //おわり
   
   cout << min(min(solve(ok),solve(ng)),min(solve(mid1),solve(mid2))) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
5
1 2
2 3
3 4
3 5
)");
#define cin input
#endif

vector<int> visit(const unordered_map<int, unordered_set<int>>& e, int v, int l)
{
	vector<int> r;
	for (int i : e.at(v))
		if (i != l)
		{
			const auto p = visit(e, i, v);
			if (r.size() < p.size())
				r = p;
		}
	r.push_back(v);
	return r;
}

void calc(const unordered_map<int, unordered_set<int>>& e, int v, int l, vector<int>& r, int d)
{
	r[d] = max(r[d], (int)e.at(v).size() - 1);
	for (int i : e.at(v))
		if (i != l)
			calc(e, i, v, r, d + 1);
}

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

	unordered_map<int, unordered_set<int>> e;
	REP (i, n - 1)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		e[a].insert(b);
		e[b].insert(a);
	}

	const auto p1 = visit(e, 0, -1);
	const auto p2 = visit(e, p1.front(), -1);

	const int d = p2.size();

	const int c1 = p2[p2.size() / 2];
	const int c2 = d % 2 ? c1 : p2[p2.size() / 2 - 1];

	ll mn = 1;

	vector<int> r((d + 1) / 2, 1);
	calc(e, c1, c2, r, 0);
	if (c1 != c2)
		calc(e, c2, c1, r, 0);
	if (c1 == c2)
		++r.front();
	for (int i : r)
		mn *= i;
/*	cout << "_";
	for (auto i : r)
	cout << i << "_";
	cout << mn << endl;*/
	
	if (c1 == c2)
		for (int i : e[c1])
		{
			vector<int> r2((d + 1) / 2, 1);
			calc(e, c1, i, r2, 0);
			calc(e, i, c1, r2, 0);
			ll c = 1;
			for (int i : r2)
				c *= i;
			c *= 2;
			mn = min(mn, c);

/*			cout << "_";
			for (auto i : r2)
			cout << i << "_";
			cout << c << endl;*/
		}
	else
		mn *= 2;

	cout << (d + 1) / 2 << " " << mn << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    bool ok = true;
    FOR(i, 0, n)
    {
        int x;
        cin >> x;
        if (x % 2 == 0)
        {
            ok &= (x % 3 == 0) || (x % 5 == 0);
        }
    }
    if (ok)
        cout << "APPROVED\n";
    else
        cout << "DENIED\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

  public static long maxkoyaku(long a, long b) {
    long r;
    if (a > b) {
      r = a;
      a = b;
      b = r;
    }
    while (a % b != 0) {
      r = a % b;
      a = b;
      b = r;
    }
    return b;
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    long[] a = new long[n];
    for (int i = 0; i < n; i++) {
      a[i] = scanner.nextLong();
    }
    long r = maxkoyaku(a[0], a[1]);
    for (int i = 2; i < n; i++) {
      r = maxkoyaku(a[i], r);
    }
    System.out.println(r);
  }

}


Measured memory_bytes: 62580
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

cnta = 0
cntb = 0
k = sum(b)-sum(a)
for i in range(n):
    d = abs(a[i]-b[i])
    if a[i] > b[i]:
        cntb += d
    else:
        cnta += (d+1)//2
        cntb += d%2

if k < 0 or cntb > cnta or k != 2*cnta - cntb:
    ans = "No"
else:
    ans = "Yes"
    
print(ans)

Measured memory_bytes: 4596
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *ABC = map(int, read().split())
    G = [[INF] * N for _ in range(N)]
    edge = [0] * M
    for i, (a, b, c) in enumerate(zip(*[iter(ABC)] * 3)):
        edge[i] = (a - 1, b - 1, c)
        G[a - 1][b - 1] = G[b - 1][a - 1] = c
    for i in range(N):
        G[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if G[i][j] > G[i][k] + G[k][j]:
                    G[i][j] = G[i][k] + G[k][j]

    ans = 0
    for a, b, c in edge:
        if c > G[a][b]:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9296
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main(){
    int i, j, n;
    scanf("%d",&n);
    char** w = (char**)malloc(sizeof(char*)*n);
    for(i=0;i<n;i++){
        w[i] = (char*)malloc(sizeof(char)*11);
        scanf("%s",w[i]);
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(strcmp(w[i],w[j])==0){
                printf("No\n");
                return 0;
            };
        }
    }
    for(i=0;i<n-1;i++){
        char a = w[i][strlen(w[i])-1];
        char b = w[i+1][0];
        if(a!=b){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


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

const int mod = 1e9 + 7;
vector<int> mem;

int Pow(int a, int b) {
    if (b < 0) return 0;
    if (b == 0) return 1;
    if (mem[b]) return mem[b];

    return mem[b] = 3 * Pow(a, b - 1) % mod;
}
signed main() {
    string S;
    cin >> S;

    const int n = S.size();
    mem.resize(n + 1);
    Pow(3, n);

    vector<int> a(n), c(n), l(n), r(n);
    for (int i = 0; i < n; i++) {
        a[i] = a[i - !!i] + (S[i] == 'A');
        l[i] = l[i - !!i] + (S[i] == '?');

        int idx = n - i - 1;
        c[idx] = c[idx + !!i] + (S[idx] == 'C');
        r[idx] = r[idx + !!i] + (S[idx] == '?');
    }

    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if (S[i] != 'B' && S[i] != '?') continue;
        ans += a[i - 1] * c[i + 1] * Pow(3, l[i - 1] + r[i + 1]) % mod; // ABC
        ans += a[i - 1] * r[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 1) % mod; // AB?
        ans += l[i - 1] * c[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 1) % mod; // ?BC
        ans += l[i - 1] * r[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 2) % mod; // ?B?
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 300;
const int maxm = 10000;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n;
int A[maxn],b[maxn];
int c[maxn],d[maxn];
int a[305][305];
int vis[maxn];
int mode[maxn];
int find(int x)
{
    for(int i = 1;i<=n+n;i++)
    {
        if(a[x][i]&&!vis[i])
        {
            vis[i] = 1;
            if(!mode[i]||find(mode[i]))
            {
                mode[i] = x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i = 1;i<=n;i++) cin>>A[i]>>b[i];
    for(int i = 1;i<=n;i++) cin>>c[i]>>d[i];
    int ans = 0;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            if(A[i]<c[j]&&b[i]<d[j])a[i][j+n] = 1;
        }
    }
    for(int i = 1;i<=n;i++)
    {
        memset(vis,0,sizeof(vis));
        if(find(i)) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

class BST:
    def __init__(self):
        self.root = None
    def insert(self, key):
        x = self.root
        y = None
        z = Node(key)
        while x != None:
            y = x
            x = x.left if z.key < x.key else x.right
        if y == None: self.root = z
        else:
            if z.key < y.key: y.left = z
            else: y.right = z
    def print_tree(self):
        def inorder(node):
            return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
        def preorder(node):
            return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
        print(inorder(self.root))
        print(preorder(self.root))

tree = BST()
input()
for e in sys.stdin:
    if e[0] == 'i': tree.insert(int(e[7:]))
    else: tree.print_tree()


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

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

    vector<vector<int>> c(3,vector<int>(3));
    
    rep(i,3){
        rep(j,3) cin >> c[i][j];
    }
    
    bool flag = true;
    rep(i,2){ //i要素のチェック
        if(c[1][i] - c[0][i] != c[1][i+1] - c[0][i+1]){
            flag = false;
            break;
        }
        
        if(c[i][1] - c[i][0] != c[i+1][1] - c[i+1][0]){
            flag = false;
            break;
        }
        if(c[2][i] - c[1][i] != c[2][i+1] - c[1][i+1]){
            flag = false;
            break;
        }
        
        if(c[i][2] - c[i][1] != c[i+1][2] - c[i+1][1]){
            flag = false;
            break;
        }
    }
    
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;

  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid]) return 1;
    if (key > A[mid]) left = mid + 1;
    else if (key < A[mid]) right = mid;
  }
  return 0;
}

int main() {
  int i, q, k, sum = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &k);
    if (binarySearch(k)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 2124
from itertools import accumulate
from math import gcd
N = int(input())
*A, = map(int, input().split())

L = list(accumulate(A, gcd))
R = list(accumulate(A[::-1], gcd))[::-1]

ans = max(gcd(l, r) for l, r in zip([0]+L[:-1], R[1:]+[0]))
print(ans)


Measured memory_bytes: 23412
h = int(input())

a = list(map(int, input().strip().split()))

cnt=0
for i in a:
    if(i%2==0):
        if(i%3==0 or i%5==0):
            cnt=cnt+0
        else:
            cnt=+1
if(cnt>0):
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

class Dice{
public:
	vector<int> dice;
	Dice(){
		dice.resize(6);
		rep(i,6) dice[i] = (i+1);
	}
	void left(){
		int to[] = {1,3,5,2,4,6};
		vector<int> tmp = dice;
		rep(i,6)tmp[i] = dice[to[i]-1];
		dice = tmp;
	}
	void west(){
		int to[] = {3,2,6,1,5,4};
		vector<int> tmp = dice;
		rep(i,6)tmp[i] = dice[to[i]-1];
		dice = tmp;
	}
	void north(){
		int to[] = {2,6,3,4,1,5};
		vector<int> tmp = dice;
		rep(i,6)tmp[i] = dice[to[i]-1];
		dice = tmp;
	}
};

int main(){
	int n;
	while(cin >> n,n){
		int ans = 0;
		Dice d;
		rep(i,n){
			string str;
			cin >> str;
			switch(str[0]){
			case 'N':
				d.north();
				break;
			case 'E':
				rep(j,3)d.west();
				break;
			case 'W':
				d.west();
				break;
			case 'S':
				rep(j,3)d.north();
				break;
			case 'R':
				d.left();
				break;
			case 'L':
				rep(j,3)d.left();
				break;
			}
			ans += d.dice[0];
		}
		cout << ans+1 << endl;
	}
}

Measured memory_bytes: 0
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int pass = 0;
        int bc = 0;
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        String s = scan.next();

        String sa[] = s.split("");



        for(int i = 0; i < n; i++) {
            if ("a".equals(sa[i])) {
                if(pass < a+b){
                    System.out.println("Yes");
                    pass++;
                }else{
                    System.out.println("No");
                }
            } else if ("b".equals(sa[i])) {
                bc++;
                if(pass < a+b){
                    if(bc <= b) {
                        System.out.println("Yes");
                        pass++;
                    }else {
                        System.out.println("No");
                    }
                }else{
                    System.out.println("No");
                }
            } else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 33960
B = input()
lenB = len(B)

cntB = 0
checkB = [0]*lenB
indB = []
for i, b in enumerate(B):
    if b == 'B':
        cntB += 1
        indB.append(i)

dif = 0
i = 0
for j in range(lenB-cntB, lenB):
    dif += j - indB[i]
    i += 1

print(dif)


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

ll N;
ll A[100010], B[100010];

int main(){
    
    cin >> N;
    vector<P>vec(N);
    for(int i=0;i < N; i++){
        cin >> A[i] >> B[i];
        vec[i].first = A[i] + B[i];
        vec[i].second = i;
    }
    sort(vec.begin(), vec.end());
    ll Ta = 0, Ao = 0;
    for(int i=N-1, j=1;i>=0;i--){
        if(j)Ta+=A[vec[i].second];
        else Ao+=B[vec[i].second];
        j = (j+1)%2;
    }
    
    cout << Ta - Ao << endl;

    return 0;
}

Measured memory_bytes: 3456
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b >= c ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 888
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    int n;
    vector<int> a;
    int inp;
    cin >> n;
    REP(i, n) {
        cin >> inp;
        a.push_back(inp);
    }
    sort(a.begin(), a.end(), greater<int>());

    int a_tot = 0;
    int b_tot = 0;
    REP(i, n) {
        if (i % 2 == 0) {
            a_tot += a[i];
        } else {
            b_tot += a[i];
        }
    }
    cout << a_tot - b_tot << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
h, w, k = map(int, input().split())

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

ans = 0

for p in range(h):
    h_combs = list(combinations(list(range(h)), p))
    for q in range(w):
        w_combs = list(combinations(list(range(w)), q))
        for h_comb in h_combs:
            for w_comb in w_combs:
                cnt = 0
                for i in range(h):
                    for j in range(w):
                        if i not in h_comb and j not in w_comb and C[i][j] == '#':
                            cnt += 1
                if cnt == k:
                    ans += 1
print(ans)


Measured memory_bytes: 9204
N = gets.to_i

primes = Array.new(5){Array.new}
il = (2..55555).to_a
while !il.empty?
  t = il.shift
  il.select!{|n| n % t != 0}
  mod = t % 5
  primes[mod].push(t)
end

puts primes[1][0..(N - 1)].join(' ')

Measured memory_bytes: 2556
#n=int(input())
a,b,c,x,y=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(m)]
ans=a*x+b*y
for z in range(0,max(x,y)+1):
    ans=min(ans,2*z*c+max(x-z,0)*a+max(y-z,0)*b)

print(ans)




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

typedef long long int ll; 
#define MOD 1000000007
#define ON 200000
#define rep(i,n) fp(i,0,n)  
#define fp(i,a,b) for(ll i=(a);i<(b);++i)
#define fn(i,a,b) for(ll i=(a);i>(b);i--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define FF first
#define SS second
typedef pair<ll, ll> pll; 
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rll(t) long long int t;cin>>t
#define MK make_pair
#define PB push_back
#define PO pop_back
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
///// This part below is only for debug, not used /////
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
///// END /////



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  rll(n);
  rll(x);
  rll(y);
  vll v(n,0);
  
  for(ll i=1;i<=n;i++){
  	for(ll j=i+1;j<=n;j++){
  		ll m = j-i;

  		m = min(m,abs(i-x)+1+abs(y-j));

  		v[m]++;

  	}
  }
  for(int i=1;i<n;i++){
  	cout << v[i] << endl;
  }
  return 0;
  
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b;
    cin>>a>>b;
    vector<int>x;
    for(int i=1;i<=100;i++)if(a%i==0&&b%i==0)x.pb(i);
    int k;cin>>k;
    cout<<x[x.size()-k]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int n;
	int c;
	
	while (scanf("%d", &n) != EOF){
		n %= 39;
		
		for (i = 0; i < n; i++){
		}
		if (i == 0){
			i = 39;
		}
		
		if (i < 10){
			printf("3C0%d\n", i);
		}
		else {
			printf("3C%d\n", i);
		}
	}
	
	return (0);
}

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

int main() {
  char ch1,ch2;
  string str1 = "abcdefghijklmnopqrstuvwxyz";
  cin >> ch1;
  //cout << ch1 << endl;

  int count = 0;
  
  for (int i = 0; i < str1.size(); i++) {
    if (str1.at(i) != ch1) {
      //cout << i << endl;
      count++;
    } else {
      break;
    }
  }
  count = count + 1;
  //cout << count << endl;
  ch2 = str1.at(count);
  cout << ch2 << endl;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

int main() {
  int n; cin>>n;
  string s;
  int a,b,c,d;
  a=b=c=d=0;
  rep(i,n) {
    cin>>s;
    if(s=="AC") a++;
    else if(s=="WA") b++;
    else if(s=="TLE") c++;
    else d++;
  }
  printf("AC x %d\n",a);
  printf("WA x %d\n",b);
  printf("TLE x %d\n",c);
  printf("RE x %d\n",d);
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define all(v) v.begin(), v.end()
#define rep(i, from, to) for (ll i = from; i < ll(to); ++i)

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

    ll n;
    cin>>n;
    vi a(n);
    ll s = 0;
    rep(i,0,n) {
        cin >> a[i];
        s += a[i];
    }
    if (n == 1) {
        cout << s << endl;
        return 0;
    }
    bitset<4000001> vb;
    vb[0] = 1;
    rep(i,0,n) {
        vb = vb | (vb << a[i]);
        //cout << vb << endl;
    }
    ll mx = 0;
    rep(i,0,s/2+1) {
        if (vb[i] != 0) mx = i;
    }
    cout << (s - mx) << endl;


    return 0;
}


Measured memory_bytes: 2304
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int n;
int v[17];
int dfs(int pos,int sum){
    if(pos==17){
        if(sum==n)return 1;
        else return 0;
    }
    int res=0;
    for(int i=0;sum+v[pos]*i<=n;i++)res+=dfs(pos+1,sum+v[pos]*i);
    return res;
}
int main(){
    for(int i=0;i<17;i++)v[i]=(i+1)*(i+1);
    while(cin>>n,n)cout<<dfs(0,0)<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

vector<P> vs;
int solve(int a, int b, int c){
	if(a == b or b == c or a == c)return 0;
	vector<P> v;
	v.pb(vs[a]);v.pb(vs[b]);v.pb(vs[c]);
	int ans = 0;
	rep(i,2){
		rep(j,2){
			rep(k,2){
				if(v[0].fi == v[1].fi and v[0].se == v[2].fi and v[1].se == v[2].se)ans = 1;
				swap(v[2].fi, v[2].se);
			}
			swap(v[1].fi, v[1].se);
		}
		swap(v[0].fi, v[0].se);
	}
	return ans;
}

signed main(){
	rep(i,6){
		int x, y;
		scanf("%lld%lld", &x, &y);
		if(x > y)swap(x, y);
		vs.push_back(P(x, y));
	}
	int ans = 1, res = 0;
	sort(all(vs));
	rep(i,6)if(i%2 == 0)if(vs[i] != vs[i+1])ans = 0;
	rep(i,3)vs.erase(vs.begin()+i+1);
	rep(i,3)rep(j,3)rep(k,3)res += solve(i, j, k);
	if(ans and res)printf("yes\n");
	else printf("no\n");
	
	//printf("%lld\n", ans);
	//rep(i,vs.size())printf("%lld %lld\n", vs[i].fi, vs[i].se);
	return 0;
}








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

#define reint register int
#define coint const int

using namespace std;

coint SIZE = 100000 + 5;

string li[SIZE];
map<string, int> mp;

int main(void) {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (reint i = 1; i <= n; ++i) cin >> li[i];
    for (reint i = 1; i <= n; ++i) sort(li[i].begin(), li[i].end());
    long long ans = 0;
    for (reint i = 1; i <= n; ++i)
        ans += mp[li[i]], ++mp[li[i]];
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 16640
K = int(input())
S = input()

MAX = 2020202
MOD = 10**9 + 7

fac = [0]*MAX
facinv = [0]*MAX
inv = [0]*MAX


def modinv(a, mod):
    b = mod
    x, u = 1, 0
    while b:
        q = a//b
        a, b = b, a-q*b
        x, u = u, x-q*u
    x %= mod
    return x


def mod_nCr_init(n, mod):
    fac[0] = fac[1] = 1
    facinv[0] = facinv[1] = 1
    inv[1] = 1
    for i in range(2, n):
        fac[i] = fac[i-1] * i % mod
        inv[i] = -inv[mod % i] * (mod // i) % mod
        facinv[i] = facinv[i-1] * inv[i] % mod


def mod_nCr(n, r, mod):
    if n < r or n < 0 or r < 0:
        return 0
    return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod


mod_nCr_init(MAX, MOD)

ns = len(S)
ans = 0
for i in range(K+1):
    x = pow(26, i, MOD)
    x *= pow(25, K-i, MOD)
    x %= MOD
    x *= mod_nCr(ns+K-i-1, ns-1, MOD)
    ans += x
    ans %= MOD

print(ans)


Measured memory_bytes: 133720
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2048
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let a: usize = scn.read();
        let b: usize = scn.read();
        let n: usize = scn.read();
        let k = (n + 1) / b;
        let x = if k == 0 { n } else { b - 1 };
        println!("{}", a * x / b + a * (x / b));
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2196
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	inputList = input[0].split(" ").map(str => parseInt(str, 10));
	a = inputList[0];
	b = inputList[1];
	result = b % a == 0 ? a + b : b - a;
	console.log(result);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define INF 1 << 31
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

struct edge {ll from,to,cost;};

int n,m;
edge es[2000];
ll d[1001];
ll sum = 0;
ll ans = 0;

int main(){
  scanf("%d %d",&n,&m);
  REP(i,m){
    ll a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    es[i] = {a,b,-c};
  }
  REP(i,1001){
    d[i] = LLONG_MAX;
  }
  d[1] = 0;
  REP(i,n-1){
    REP(j,m){
      edge e = es[j];
      if(d[e.from] == LLONG_MAX) continue;
      if(d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
      }
    }
  }
  ans = -d[n];
  bool negative[1001] = {false};
  REP(i,n){
    REP(j,m){
      edge e = es[j];
      if(d[e.from] == LLONG_MAX) continue;
      if(d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        negative[e.from] = true;
      }
      negative[e.to] |= negative[e.from];
    }
  }
  if(negative[n]){
    printf("inf\n");
  }else{
    printf("%lld\n",ans);
  }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var a, b, c string
  fmt.Scan(&a, &b, &c)
  var res string
  if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
    res = "YES"
  } else {
    res = "NO"  
  }
  fmt.Println(res)
}


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

int main()
{
    int n, m; cin >> n >> m;
    int arr[m];
    for (int i = 0; i < m; i++) {
        cin >> arr[i];
        n -= arr[i];
        if (n < 0) {
            cout << -1;
            return 0;
        }
    }
    cout << n;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s; cin >> s;
    if(s.back() == 's'){
        s += "es";
    }
    else{
        s += 's';
    }
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
//#define int long long
using namespace std;

struct team{
    int id, univ, ac, pen;
    //team(int id, int univ, int ac, int pen):id(id), univ(univ), ac(ac), pen(pen){}
};

bool cmp(team d1, team d2){
    if(d1.ac != d2.ac){
        return d1.ac > d2.ac;    
    }else if(d1.pen != d2.pen){
        return d1.pen < d2.pen;
    }else{
        return d1.id < d2.id;
    }
}

signed main(){
    int n;
    while(cin >> n, n){
        vector<team> d(n);
        rep(i, 0, n){
            cin >> d[i].id >> d[i].univ >> d[i].ac >> d[i].pen;
        }
        sort(all(d), cmp);
        /*rep(i, 0, d.size()){
            cout << ' ' << d[i].id << endl;
        }*/
        map<int, int> mp;
        set<int> st;
        int cnt = 0;
        vector<int> ans;
        rep(i, 0, n){
            if(cnt >= 10) break;
            if(mp[d[i].univ] <= 2 && !st.count(d[i].id)){
                ans. push_back(d[i].id);
                st.insert(d[i].id);
                mp[d[i].univ]++;
                cnt++;
            }
        }
        rep(i, 0, n){
            if(cnt >= 20) break;
            if(mp[d[i].univ] <= 1 && !st.count(d[i].id)){
                ans. push_back(d[i].id);
                st.insert(d[i].id);
                mp[d[i].univ]++;
                cnt++;
            }
        }
        rep(i, 0, n){
            if(cnt >= 26) break;
            if(mp[d[i].univ] == 0 && !st.count(d[i].id)){
                ans. push_back(d[i].id);
                st.insert(d[i].id);
                mp[d[i].univ]++;
                cnt++;
            }
        }
        rep(i, 0, cnt){
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 10*10
#define EPS 1e-9

//----***パーツ***----
#define fr first
#define se second

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

signed main(){
  int N,K;cin>>N>>K;
  vector<int> v_l(K);
  REP(i,0,K)cin>>v_l[i];
  for (int i = N;; i++) {
    bool flg=true;
    int tmp=i;
    while(tmp){
      int m=tmp%10;
      each(v,v_l){
        //debug(v)
        if(m==v){
          flg=false;
        }
      }
      tmp/=10;
    }
    if(flg){
      print(i)
      return 0;
    }
  }
}


Measured memory_bytes: 256
a,b,k=map(int,input().split())
if b-a+1<=2*k:
    for i in range(a,b+1):
        print(i)
else:
    for i in range(a,a+k):
        print(i)
    for j in range(b-k+1,b+1):
        print(j)  

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

int main() {
	long long int m,i,k,n,flag=0,a,b;
	string s,t,temp;
	cin>>n>>a>>b;
	k=n/(a+b);
	n=k*a+min(n%(a+b),a);
	cout<<n;


	return 0;
}


Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  300005
ll n,k,dp[N],ans=1;
vi a[N];
void dfs(ll node,ll p){
	ll rem=k-1;
	if(p!=-1)rem--;
	for(auto i:a[node]){
		if(i!=p){
			dfs(i,node);
			ans=(ans*rem)%hell;
		//	cout<<i<<" "<<rem<<"\n";
			rem--;
		}
	}
}
int main()
{
	ios
	ll i,j,x,y;
	cin>>n>>k;
	for(i=1;i<n;i++){
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	ans=k;
	dfs(1,-1);
	cout<<ans;
	return 0;
}




Measured memory_bytes: 16256