akhauriyash/Code-Regression huggingface dataset:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  works = []
  for i in range(n):
    t, limit = input_list()
    works.append((t, limit))
  sw = sorted(works, key=lambda x: x[1])
  total = 0
  for t, limit in sw:
    total += t
    if total > limit:
      print('No')
      exit(0)
  print('Yes')
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Measured memory_bytes: 35464
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

string ans[4] = {"AC", "WA", "TLE","RE"}; 

int main(){
	fastio;
	int n; cin>>n;
	map<string, int> ver;
	For(i,0,n){
		string s; cin>>s;
		ver[s]++;
	}
	For(i,0,4) cout << ans[i] << " x " << ver[ans[i]] << endl;
	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	string s; cin>>s;
	ll Ccnt=0,CAPcnt=0;
	if(s[0]!='A') cout<<"WA";
	else{
		rep1(i,s.sz-1){
			if(s[i]-'a'<0) CAPcnt++;
			if(i>=2 && i<=s.sz-2 && s[i]=='C'){
				Ccnt++;
			}
		}
		if(Ccnt==1 && CAPcnt==1) cout<<"AC";
		else cout<<"WA";
	}	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

struct UFT{    //O(loga(n))
    int n;
    vi d, r;
    UFT(int n) : n(n), d(n, -1), r(n, 0){};
    int root(int i){
        if(d[i] < 0) return i;
        return d[i] = root(d[i]);
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return false;

        if(r[x] < r[y]) swap(x, y);
        else if(r[x] == r[y]) r[x]++;
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    int size(int i){
        return -d[root(i)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vi a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }
    vl ans(m);
    ll x = (ll)n * (n-1) / 2;
    UFT uf(n);
    repr(i, m) {
        ans[i] = x;
        if(uf.same(a[i], b[i])) continue;
        ll p = uf.size(a[i]);
        ll q = uf.size(b[i]);
        uf.unite(a[i], b[i]);
        ll r = p + q;
        x += p*(p-1)/2;
        x += q*(q-1)/2;
        x -= r*(r-1)/2;
    }
    rep(i, m) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

ll n;
ll ans;
string s,t;
signed main(){
	acc_io;
	ans=0;
	cin>>s>>t;
	sort(all(s));
	sort(all(t));
	reverse(all(t));
//	DBG(s,t,0,0);
	if(s<t) s="Yes";
	else    s="No";
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100005];
int main()
{	int N,K,Q,m;
	cin>>N>>K>>Q;
	for(int i=0;i<Q;i++)
	{
		cin>>m;
		a[m]++;
	}
	for(int i=1;i<=N;i++)
	{
		if(Q-a[i]>=K)
		{
			cout<<"No"<<endl;
		}
			
		else
		{
			cout<<"Yes"<<endl;
		}
			
	}
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,x;
    cin>>n>>x;
    int a[n];
    for(int i = 0;i<n;i++) cin>>a[i];
    
    int curSum = 0;
    int count = 0;
    for(int i = 0;i<n;i++) {
        
        curSum += a[i];
        if(curSum <= x) count++;
    }
    cout<<count+1;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>

using namespace std;

const double PI = 3.14159265358979;

struct Node {
	int key;
	Node* parent = 0;
	Node* left = 0, * right = 0;
};

void preorder(Node* const root) {

	if (root) {
		printf(" %d", root->key);
		preorder(root->left);
		preorder(root->right);
	}
}

void inorder(Node* const root) {

	if (root) {
		inorder(root->left);
		printf(" %d", root->key);
		inorder(root->right);
	}
}


void insert_key(Node *root, int key) {

	Node* comer = new Node;
	comer->key = key;
	comer->left = 0;
	comer->right = 0;

	Node* temp = root;
	Node* par = 0;
	while (temp) {
		par = temp;
		if (key < temp->key)
			temp = temp->left;
		else
			temp = temp->right;
	}
	if (key < par->key) 
		par->left = comer;
	else 
		par->right = comer;
	comer->parent = par;
}

Node* find_key(Node* const root, int key) {
	
	Node* temp = root;
	while (temp) {
		if (temp->key == key) 
			return temp;

		if (key < temp->key)
			temp = temp->left;
		else
			temp = temp->right;
	}
	return 0;
}

Node* get_successor(Node * const root) {

	Node* res;
	if (root->right) {
		Node* temp = root->right;
		while (temp->left) {
			temp = temp->left;
		}
		return temp;
	}
	else {
		Node* x = root;
		Node* par = root->parent;
		while (par && par->right == x) {
			x = par;
			par = par->parent;
		}
		return par;
	}
}

void delete_key(Node* root, int key) {

	Node* tar = find_key(root, key);
	Node* dead;
	if (!tar) return;
	if (tar->left && tar->right) {
		dead = get_successor(tar);
	}
	else {
		dead = tar;
	}
	
	Node* deadson;
	if (dead->left) {
		deadson = dead->left;
	}
	else {
		deadson = dead->right;
	}

	if (deadson) {
		deadson->parent = dead->parent;
	}
	
	if (dead->parent) {
		if (dead == dead->parent->left) {
			dead->parent->left = deadson;
		}
		else {
			dead->parent->right = deadson;
		}
	}
	else {
		deadson = root;
	}

	if (dead != tar)
		tar->key = dead->key;

	delete dead;
}

void display_tree(Node* const root) {

	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
}

int main() {

	int n;  cin >> n;
	Node* root = 0;

	string cmd;
	int key;
	for (int i = 0; i < n; i++)	{
		cin >> cmd;
		if (cmd[0] == 'i') {
			cin >> key;
			if (!root) {
				root = new Node;
				root->key = key;
				root->left = root->right = 0;
			} else
				insert_key(root, key);
		} 
		else if (cmd[0] == 'p') {
			display_tree(root);
		}
		else if (cmd[0] == 'f') {
			cin >> key;
			Node* res = find_key(root, key);
			if (res) cout << "yes\n";
			else cout << "no\n";
		}
		else if (cmd[0] == 'd') {
			cin >> key;
			delete_key(root, key);
		}
	}

	return 0;
}



Measured memory_bytes: 22012
S = gets.chomp
T = gets.chomp

map1 = {}
map2 = {}
S.each_char.with_index do |s, i|
  t = T[i]
  if map1.has_key?(s) || map2.has_key?(t)
    unless map1[s] == t && map2[t] == s
      puts 'No'
      exit
    end
  else
    map1[s] = t
    map2[t] = s
  end
end

puts 'Yes'

Measured memory_bytes: 2620
import scala.io.{StdIn => in}
import java.lang.{Character => char}

object Main extends App {
  val s = in.readLine.map(char.getNumericValue)

  val (res0, res1, _) = s./:(0,0,0) { case ((acc0, acc1, i), c) => 
    if(c == i) (acc0, acc1+1, i^1) else (acc0+1, acc1, i^1)
  }

  val ans = res0 min res1
  println(ans)
}

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

int main () {
  int n;cin>>n;
  vector<int> list(n);
  for (int i=0;i<n;i++) {
    cin >> list.at(i);
  }
  map<int,int> check;
  int temp=1;
  int count=0;
  int flag=0;
  while(1) {
    count++;
    temp=list.at(temp-1);
    if(temp==2) {
      cout << count << endl;
      break;
    }
    else if(check.count(temp)) {
      cout << "-1" << endl;
      break;
    }
    else {
      check[temp]=1;
    }
  }
}

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

int n, m, a, b; vector<int>x[100009]; bool used[100009];

int main() {
	cin >> n >> m; int s = 1, t = 1;
	for (int i = 1; i <= m; i++) {
		cin >> a >> b; s = a; t = b;
		x[a].push_back(b);
		x[b].push_back(a);
	}
	used[s] = true; used[t] = true;

	vector<int>V1, V2;
	int cx = s;
	while (true) {
		int nex = -1; V1.push_back(cx);
		for (int i = 0; i < x[cx].size(); i++) { if (used[x[cx][i]] == false) nex = x[cx][i]; }
		if (nex == -1) break;
		cx = nex; used[cx] = true;
	}
	cx = t;
	while (true) {
		int nex = -1; V2.push_back(cx);
		for (int i = 0; i < x[cx].size(); i++) { if (used[x[cx][i]] == false) nex = x[cx][i]; }
		if (nex == -1) break;
		cx = nex; used[cx] = true;
	}
	vector<int>V; for (int i = V2.size() - 1; i >= 0; i--) V.push_back(V2[i]);
	for (int i = 0; i < V1.size(); i++) V.push_back(V1[i]);

	cout << V.size() << endl;
	for (int i = 0; i < V.size(); i++) { if (i)cout << " "; cout << V[i]; }cout << endl;
	return 0;
}

Measured memory_bytes: 7160
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[2][201], p[101];
	int flag = 0, i, plen, slen;
	scanf("%s %s", s[0], p);
	strcpy(s[1], s[0]);
	strcat(s[1], s[0]);
	slen = strlen(s[0]);
	plen = strlen(p);
	for (i = 0; i < slen; i++)
	{
		if (strncmp(&s[1][i], p, plen) == 0)
			flag = 1;
	}
	if (flag)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 548
package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	k := make([]int, M)
	s := make([][]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&k[i])
		s[i] = make([]int, k[i])
		for j := 0; j < k[i]; j++ {
			fmt.Scan(&s[i][j])
			s[i][j]--
		}
	}
	p := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&p[i])
	}

	ans := 0
	for t := 0; t < 1<<uint(N); t++ {
		flag := true
		for i := 0; i < M; i++ {
			sum := 0
			for j := 0; j < k[i]; j++ {
				if t >> uint(s[i][j]) & 1 != 0 {
					sum++
				}
			}
			if sum % 2 != p[i] {
				flag = false
				break
			}
		}
		if flag {
			ans++
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 512
import sys

def sieve(n):
    if n < 2:
        is_prime = [False for _ in range(n+1)]
        return is_prime

    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False

    return is_prime


def main():
    input = sys.stdin.readline
    Q = int(input())
    is_prime = sieve(10**5)
    A = [0 for _ in range(10**5 + 1)]
    for i in range(3, 10**5 + 1):
        if is_prime[i] and is_prime[(i+1)//2]:
            A[i] = A[i-1] + 1
        else:
            A[i] = A[i-1]

    for _ in range(Q):
        l, r = map(int, input().split())
        print(A[r] - A[l-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 5460
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int partition(vector<int>& a, int p, int r);

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

    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int pivot = partition(a, 0, n - 1);
    cout << a[0];
    for (int i = 1; i < n; ++i) {
        if (i == pivot)
            cout << " [" << a[i] << "]";
        else
            cout << ' ' << a[i];
    }
    cout << '\n';
}

int partition(vector<int>& a, int p, int r)
{
    int pivot = a[r];
    int div = p - 1;

    for (int i = p; i < r; ++i) {
        if (a[i] <= pivot) {
            ++div;
            swap(a[i], a[div]);
        }
    }
    ++div;
    swap(a[div], a[r]);

    return div;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  cout<<n*n<<endl;
}

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

int main()
{
	int64_t N;
	scanf("%lld", &N);
	int64_t ten_pow{1};
	while (ten_pow * 10 <= N) ten_pow *= 10;
	int64_t ans_num{ten_pow - 1};
	while (ans_num + ten_pow <= N) ans_num += ten_pow;
	int64_t ans{};
	for (; ans_num > 0; ans_num /= 10)
		ans += ans_num % 10;
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){

    string s;
    string t;
    cin >> s >> t;

    int cnt = s.length();
    int j = 0;
    bool f = false;
    int i = 0;
    for(int i = 0;i < s.length();i++){
        j = 0;
        int p = i;
        while(s[p] == t[j]){
            j++;
            p++;
            if(p == s.length()) p = 0;//終端まできたら最初の戻る
            if(j == t.length()-1){
                f = true;
                break;
            }

        }

    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
typedef long long ll;
int main()
{
	int N, X;
	scanf("%d%d", &N, &X);
	int flour[N];
	int total = 0, cnt = N;
	for (int i = 0; i < N; i++) {
		scanf("%d\n", &flour[i]);
		total += flour[i];
	}
	if (X - total == 0) {
		printf("%d\n", cnt);
		return 0;
	}
	
	int d_cnt = (X - total) / flour[0];
	for (int i = 1; i < N; i++) {
		int tmp = (X - total) / flour[i];
		if (d_cnt < tmp) d_cnt = tmp;
	}
	printf("%d\n", cnt + d_cnt);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdint>

int const MAXH=1000, MAXW=1000;
uint64_t const MOD = 1000000007;

int H, W;

char map[MAXH][MAXW];

uint64_t dp[MAXH][MAXW];

int main() {
  std::cin >> H >> W;
  for(int h = 0; h < H; ++h) {
    for(int w = 0; w < W; ++w) {
      char c;
      std::cin >> c;
      map[h][w] = c;
    }
  }

  int v = 1;
  for(int w = 0; w < W; ++w) {
    if(map[0][w] == '#') v = 0;
    dp[0][w] = v;
  }
  v = 1;
  for(int h = 0; h < H; ++h) {
    if(map[h][0] == '#') v = 0;
    dp[h][0] = v;
  }
  for(int h = 1; h < H; ++h) {
    for(int w = 1; w < W; ++w) {
      if(map[h][w] == '#') dp[h][w] = 0;
      else {
        dp[h][w] = (dp[h][w-1] + dp[h-1][w])%MOD;
      }
    }
  }
  std::cout << dp[H-1][W-1] << std::endl;
  return 0;
}


Measured memory_bytes: 9088
import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val n = sc.nextInt()
        if (n > 500_000) {
            throw Exception("Illegal input")
        }
        val tree = TreeII()
        for (i in 0 until n) {
            val instruction = sc.next()!!
            if (instruction == "insert") {
                val key = sc.nextInt()
                tree.insert(NodeII(key = key))
            }
            if (instruction == "find") {
                val key = sc.nextInt()
                if (tree.find(key, tree.root)) {
                    println("yes")
                } else {
                    println("no")
                }
            }
            if (instruction == "print") {
                tree.printInorder(tree.root)
                println()
                tree.printPreorder(tree.root)
                println()
            }
        }
    } catch (e: Exception) {
        println(e)
    }
}

class TreeII {
    var root: NodeII? = null

    fun insert(newNode: NodeII) {
        var parentNode: NodeII? = null
        var currentNode: NodeII? = root
        while (currentNode != null) {
            parentNode = currentNode
            if (newNode.key < currentNode.key) {
                currentNode = currentNode.left
            } else {
                currentNode = currentNode.right
            }
        }

        newNode.parent = parentNode
        if (newNode.parent == null) {
            root = newNode
        } else if (newNode.key < parentNode!!.key) {
            parentNode.left = newNode
        } else {
            parentNode.right = newNode
        }
    }

    fun find(key: Int, node: NodeII?): Boolean {
        if (node == null) return false
        if (node.key == key) {
            return true
        }
        if (key < node.key) {
            return find(key, node.left)
        }
        if (key > node.key) {
            return find(key, node.right)
        }
        return false
    }

    fun printPreorder(node: NodeII?) {
        if (node == null) return
        print(" ${node.key}")
        printPreorder(node.left)
        printPreorder(node.right)
    }

    fun printInorder(node: NodeII?) {
        if (node == null) return
        printInorder(node.left)
        print(" ${node.key}")
        printInorder(node.right)
    }
}

class NodeII(
        var parent: NodeII? = null,
        var left: NodeII? = null,
        var right: NodeII? = null,
        var key: Int
)


Measured memory_bytes: 196376
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;
 
int main() {
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for (int i = 1; i * i <= m; ++i) {
        if (m % i == 0) {
            if (m / i >= n) {
                ans = max(ans, i);
            }
            if (i >= n) {
                ans = max(ans, m / i);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, M, cost[110][110], a[1010], b[1010], c[1010];
bool ans[1010];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(i == j)continue;
            cost[i][j] = INF;
        }
    }
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i] >> c[i];
        cost[a[i]][b[i]] = c[i];
        cost[b[i]][a[i]] = c[i];
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
            }
        }
    }
    for(int i = 0; i < M; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                if(cost[j][k] >= cost[j][a[i]] + c[i] + cost[b[i]][k]){
                    ans[i] = true;
                }
            }
        }
    }
    int res = 0;
    for(int i = 0; i < M; i++){
        if(!ans[i]){
            res++;
        }
    }
    cout << res << endl;

    return 0;
}
/*


*/


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

#define INF 999999999999

int main(){
  int n;
  cin>>n;
  int f[n][5][2];
  for(int i=0;i<n;i++){
    for(int j=0;j<5;j++){
      for(int k=0;k<2;k++){
        cin>>f[i][j][k];
      }
    }
  }
  ll p[n][11];
  for(int i=0;i<n;i++){
    for(int j=0;j<=10;j++){
      cin>>p[i][j];
    }
  }
  ll ans=-INF;
  for(ll i=1;i<(1ll<<10);i++){
    int c[n]={};
    for(int j=0;j<5;j++){
      for(int k=j;k<j+2;k++){
        if( (i>>(j+k)) & 1){
          for(int l=0;l<n;l++){
            if(f[l][j][k-j]) c[l]++;
          }
        }
      }
    }
    ll tmp=0;
    for(int j=0;j<n;j++){
      tmp+=p[j][c[j]];
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

bool prime[50001];
int cnt[1000001];
ll l,r;
ll now[1000001];

int main(void){
	memset(prime,true,sizeof(prime));
	prime[0]=false;
	prime[1]=false;
	vector<int> p;
	for(int i=2;i<=50000;i++){
		if(prime[i]){
			p.push_back(i);
			for(int j=i*2;j<=50000;j+=i){
				prime[j]=false;
			}
		}
	}
	vector<P> p2;
	for(int i=0;i<p.size();i++){
		ll v=p[i];
		ll tmp=v;
		while(v<=1000000000LL){
			p2.push_back(P(v,tmp));
			v*=tmp;
		}
	}
	scanf("%lld %lld",&l,&r);
	for(int i=0;i<(r-l+1LL);i++){
		now[i]=(ll)l+i;
	}
	for(int i=0;i<p2.size();i++){
		ll nv=p2[i].first;
		for(ll j=max(1LL,(l+nv-1LL)/nv)*nv;j<=r;j+=nv){
			cnt[j-l]++;
			now[j-l]/=p2[i].second;
		}
	}
	int ans=0;
	for(int i=0;i<(ll)(r-l+1LL);i++){
		if(now[i]!=1)cnt[i]++;
		if(prime[cnt[i]])ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main () {
  int N;
  cin >> N;
  multimap<string, int> city;
  vector<int> score(N);
  string S;
  int P;
  for(int i = 0; i < N; i++) {
    cin >> S >> P;
    city.insert(make_pair(S, i));
    score[i] = P;
  }

  auto itr = city.begin();
  string previouscity;
  map<int, int, greater<int>> restaurant;
  for (itr = city.begin(); itr != city.end(); itr++) {
    string thiscity = itr->first;
    if (thiscity != previouscity) {
      //if (restaurant.size() == 0) {
      //cout<<itr->second<<endl;
      //} else {
     	for (auto itr2 = restaurant.begin(); itr2 != restaurant.end(); ++itr2) {
     	  cout<<itr2->second +1<<endl;
     	}
	//}
      restaurant.clear();
      restaurant.insert(make_pair(score[itr->second], itr->second));
      previouscity = thiscity;
    } else {
      restaurant.insert(make_pair(score[itr->second], itr->second));
    }
  }
  for (auto itr2 = restaurant.begin(); itr2 != restaurant.end(); ++itr2) {
    cout<<itr2->second +1<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <math.h>

#define nl '\n'

using namespace std;

int n;
string s, t;

int main(){

    cin >> n >> s >> t;

    vector<char> v;

    for(int i = 0; i < n; i++){
        v.push_back(s[i]);
        v.push_back(t[i]);
    }

    for(int i = 0; i < 2*n; i++){
        cout << v[i];
    }






}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2) 
		cout << s[i];
	cout << endl;
	getchar(); getchar();
}

Measured memory_bytes: 512
//
//  main.cpp
//  B - Echo
//
//  Created by Hashizo on 2019/11/16.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	
	string ans = "Yes";				// "No"

	ll n;
	cin >> n;

	string s;
	cin >> s;

	if((n % 2) != 0) {
		cout << "No" << endl;
		return 0;
	}

	ll mid = n / 2;
	
	if (s.substr(0,mid).compare(s.substr(mid)) == 0){
		cout << ans << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int digsum(int x) {
    int ret = 0;
    while(x > 0) {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string yes = "Yes", no = "No";
    int x;
    cin >> x;
    if(x %digsum(x) == 0) {
        cout << yes << endl;
    }
    else cout << no << endl;
    return 0;
}

Measured memory_bytes: 256
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(n[K - 1])


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
using namespace std;
int w, h, n;
int x, y, a;
int x1, x2, y1, y2;
int main()
{
    cin >> w >> h >> n;
    x2 = w;
    y2 = h;
    for(int i = 0; i < n; i++){
        cin >> x >> y >> a;
        if(a == 1){
            x1 = max(x1, x);
        }else if(a == 2){
            x2 = min(x2, x);
        }else if(a == 3){
            y1 = max(y1, y);
        }else if(a == 4){
            y2 = min(y2, y);
        }
    }
    if(y1 >= y2 || x1 >= x2){
        cout << 0;
    }else{
        cout << (x2 - x1) * (y2 - y1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,weight;cin>>n>>weight;
    vector<ll> w(n),v(n);
    rep(i,n){cin>>w[i]>>v[i];}
    ll lim = 100005;
    vector<vector<ll> > dp(n,vector<ll>(lim,0));
    rep(i,n){
        rep(j,lim){dp.at(i).at(j)=weight+1;}
    }
    dp[0][0]=0;
    dp.at(0).at(v.at(0))=w.at(0);
    repr(i,1,n){
        rep(j,lim){
            dp.at(i).at(j)=dp.at(i-1).at(j);
        }
        repr(j,v.at(i),lim){
            dp.at(i).at(j) = min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
        }
    }
    ll res=lim-1;
    while(dp[n-1][res]>weight){res--;}
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 79488
N, K = map(int, input().split())
X = list(map(int, input().split()))

answer = 10 ** 18
for i in range(N - K + 1):
    left, right = i, i + K - 1
    al, ar = abs(X[left]), abs(X[right])
    if X[left] * X[right] >= 0:
        answer = min(answer, max(al, ar))
    else:
        answer = min(answer, al * 2 + ar, al + ar * 2)
        
print(answer)

Measured memory_bytes: 14536
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{
    int n;
    cin >> n;
    vector<tuple<int, int, int, int>> notices;
    for (int i = 0; i < n; i++) 
    {
        int b, f, r, p;
        cin >> b >> f >> r >> p;
        notices.push_back(make_tuple(b,f,r,p));
    }

    array<int, 10> room = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    array<array<int,10>,3> flour = {room, room, room};
    array<array<array<int,10>,3>,4> building = {flour, flour, flour};

    for (auto& var : notices) 
    {
        building[get<0>(var)-1][get<1>(var)-1][get<2>(var)-1] += get<3>(var);
    }

    //Junsang****for (auto ib : building) 
    //Junsang****{
    for (auto ib = building.begin(); ib != building.end(); ib++) 
    {

        for (auto ifl : *ib) 
        {
            for (auto ir : ifl) 
            {
                cout << " " << ir;
            }
            cout << endl;
        }
        if(ib+1!=building.end()) cout << "####################" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll a[N];
  for(int i=0;i<N;++i) cin>>a[i];
  for(int i=1;i<N;++i) {
    a[i] += a[i-1];
  }
  ll ans = big;
  for(int i=0;i<N-1;++i) {
    ans = min(ans, abs(a[i]-(a[N-1]-a[i])));
  }
  cout<<ans<<endl;
}



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

using ll = long long;

ll f(ll x) {
    ll res = 0;
    for(int i = 50; i >= 1; --i) {
        const ll b = (1LL << i);
        if(x & b) {
            res |= (((x & (b - 1)) + 1) % 2) << i;
        }
    }
    if(x & 1) {
        res |= (x >> 1) & 1;
    } else {
        res |= ((x >> 1) - 1) & 1;
    }
    return res;
}

int main() {
    ll a, b; cin >> a >> b;
    cout << (f(a - 1) ^ f(b)) << endl;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, l;
	cin >> n >> l;
	string s[n];
	for(int i = 0; i < n; i++) cin >> s[i];
	sort(s, s + n);
	for(int i = 0; i < n; i++) cout << s[i];
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<string.h>



void change(char *str){
  int len=strlen(str);
  int i;
  for(i=0;i<len;i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]-=32;
    }
  }
}

int main(){
  char t[10000];
  char key[10000];
  char eofstr[]={"END_OF_TEXT"};
  int ans=0;

  scanf("%s",key);
  change(key);

  while(1){
    scanf("%s",t);
    if(strcmp(t,eofstr)==0){
      break;
    }
    change(t);
    if(strcmp(t,key)==0){
      ans++;
    }
  }

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



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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) FOR(i,0,a)
#define RREP(i,a) RFOR(i,a,0)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) sort(ALL(a))

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int,int> PII;

long N;
long x;
VL a;
int main() {
    std::cin >> N >> x;
    a.resize(N);
    REP(i, N) {
        std::cin >> a[i];
    }

    long long res = 0;
    if(a[0] > x) {
        res = a[0] - x;
        a[0] = x;
    }
    REP(i, N-1) {
        long dx = a[i] + a[i+1] - x;
        if(dx > 0) {
            res += dx;
            long b = std::min(dx, a[i+1]);
            long c = std::max(0l, dx-b);
            a[i+1] -= b;
            a[i] -= c;
        }
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    R = 0
    G = 0
    B = 0
    ans = 1
    for i in range(N):
        a = A[i]
        count = 0
        if R==a:
            R+=1
            count+=1
            if G==a:
                count+=1
            if B==a:
                count+=1
        else:
            if G==a:
                G+=1
                count+=1
                if B==a:
                    count+=1
            else:
                if B==a:
                    B+=1
                    count+=1
                else:
                    print(0)
                    exit()
        ans*=count
        ans%=MOD
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 12552
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n;cin>>n;
    map<string,int>m;
    rep(i,n){
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<m.size()<<endl;
}

Measured memory_bytes: 19176
s = input()
a = int(s[:2])
b = int(s[2:])
if 1<= a <= 12 and 1<= b <= 12:
  print('AMBIGUOUS')
elif 1<=a<=12:
  if 0 <= b <= 99:
    print('MMYY')
elif 1 <= b<= 12:
  if 0 <= a <= 99:
    print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3060
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def min(a,b)
    return a>b ? b : a
end
N=gets.to_i
h=get_i
ans=0
loop do
  head=0
  N.times do|i|
      if h[i].zero? and i-head>0
          min=h[head..i-1].min
          ans+=min
          head.upto(i-1) do|j|
            h[j]-=min
          end
          head=i+1
      elsif h[i].zero?
          head=i+1
      end
  end 
  if head<N
      min=h[head..N-1].min
      ans+=min
      head.upto(N-1) do|j|
          h[j]-=min
      end
  end
  break if h.max.zero?
end
puts ans

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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if(s == t) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

Measured memory_bytes: 3624
from collections import deque
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append(str(input()))
que = deque()
dist = [[-1]*w for i in range(h)]

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            dist[i][j] = 0
            que.append((i, j))


dd = ((0, -1), (-1, 0), (0, 1), (1, 0))
ans = 0
d = 0
while que:
    y, x = que.popleft() #幅優先探索
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if 0 <= nx < w and 0 <= ny < h and dist[ny][nx] == -1:
            dist[ny][nx] = 0
            que.append((ny, nx))
            dist[ny][nx] = d + 1
print(d)

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

int main() {
  int A,B; cin >> A >> B;
  if(A!=1 && B!=1) cout << 1 << endl;
  if(A!=2 && B!=2) cout << 2 << endl;
  if(A!=3 && B!=3) cout << 3 << endl;
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean res = false;
		for(int i = 1; i < 10;i++) {
			for(int j = 1;j < 10;j++) {
				if(n == i*j) {
					res = true;
					break;
				}else {
				}
			}
		}
		if(res) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}


	}

}

Measured memory_bytes: 21972
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int a[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	sort(a,a + 5);
	for (int i = 4; i >= 0; i--)
	{
		cout << a[i];
		if (i != 0)
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}
}




Measured memory_bytes: 3096
n,x,m=map(int,input().split())
# 一定回数を経ると循環するので最後にかければよい
a_i = x
log = [x]
app=[-1]*m
app[x]=0
last = x
for i in range(1,n):
  a_i = (a_i**2)%m
  if app[a_i] > -1:
    last = a_i
    break
  app[a_i] = i
  log.append(a_i)

# ループの手前(or最後)まで足し合わせる
ans = sum(log[:min(n, app[last])])
if n > app[last]:
  # ループ中合計
  ans += sum(log[app[last]:]) * ((n-app[last]) // (len(log) - app[last]))
  # 末端合計
  ans += sum(log[app[last]:app[last] + (n-app[last]) % (len(log) - app[last])])
print(ans)

Measured memory_bytes: 13660
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  vector<Pi> X(N);
  rep(i, N){
    int x,l; cin >>x >>l;
    X[i] = {x+l, x-l};
  }
  sort(all(X));
  rep(i, N) swap(X[i].first, X[i].second);
  int pos = -1001001001;
  int res = 0;
  for (int i=0; i<N; i++){
    if (pos <= X[i].first){
      pos = X[i].second;
      res++;
    }
  }
  cout <<res <<endl;

}

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

int main(){
	ll h,w; cin >> h >> w;
	if(h == 1 || w == 1)cout << 1 << endl;
	else if(h * w %2 == 0)cout << h * w/2 << endl;
	else cout << (w * h + 1)/2 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll x,m,k;
    cin>>x>>m>>k;
    ll a[x+1],b[m];
    for (int i=0; i<x; i++)
        cin>>a[i];
    for (int i=0; i<m; i++)
        cin>>b[i];
    a[x]=0;
    ll sum=0,ans=0,cnt=0;
    int j=m-1;
    for (int i=1; i<m; i++)
        b[i]+=b[i-1];
    for (int i=0; i<=x; i++)
    {
        ll cur=sum;
        cnt=i;
        for (; j>=0; j--)
        {
            if (cur+b[j]<=k)
            {
                cnt+=j+1;
                break;
            }
        }
        ans=max(ans,cnt);
        sum+=a[i];
        if (sum>k)
            break;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1] += 32;
    cout << s << endl;
    return 0;
}


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

using namespace std;

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

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

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

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

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

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

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

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans=0, cnt=0;
    FOR(i, 1, n){
        cnt=0;
        string s1, s2, l1, l2;
        s1=s.substr(0, i);
        s2=s.substr(i);
        map<char, int> a1, a2;
        int k1=s1.size();
        int k2=s2.size();
        REP(j, k1){
            a1[s1[j]]++;
        }
        REP(j, k2){
            a2[s2[j]]++;
        }
        for(auto const& l1: a1){
            for(auto const& l2: a2){
                if(l1.first==l2.first) cnt++;
            }
        }
        ans=max(ans, cnt);
    }
    cout << ans << endl;
 
}

Measured memory_bytes: 256
using System;

namespace _1562
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool found = false;
            for (int i = 1; !found; i++)
            {
                int count = 0;
                for (int j = 1; j <= i; j++)
                {
                    if (i % j == 0) count++;
                }
                if (count == n)
                {
                    Console.WriteLine(i);
                    found = true;
                }
            }
        }
    }
}


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

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

using namespace std;

int main() {
  int cnt = 0;
  while(1){
    ++cnt;
    int n;
    cin>>n;
    if(!n)break;
    cout<<"Case "<<cnt<<":"<<endl;
    vector<int> st(2*n-1);
    st[0] = 1;
    REP(i,2*n-2) {
      int diff = min(i+1, 2*n-i-1);
      st[i+1] = st[i] + diff;
    }
    REP(i,n) {
      REP(j,n) {
        int k = i+j;
        int l = ((k % 2) == 0) ? min(n-i-1, j) : min(i, n-j-1);
        printf("%3d", st[k] + l);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 3212