akhauriyash/Code-Regression huggingface dataset:
package main

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

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

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

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

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

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

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

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

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

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

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)
	//Nは必ず偶数
	N = nextInt()
	if N == 1 {
		fmt.Println(1)
		return
	}

	students := make([]int, N)
	for i := 0; i < N; i++ {
		A := nextInt()
		students[A-1] = i + 1
	}

	buf := bufio.NewWriter(os.Stdout)
	buf.Write([]byte(fmt.Sprintf("%d", students[0])))
	for _, v := range students[1:] {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

int n, k;

signed main() {
	cin >> n >> k;
	for (int i = 0; ; i++) {
		if (i * (k - 1) + 1 >= n) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import Data.Maybe
import Data.Char
import Data.List
import Control.Monad

main = do
  [n,m] <- map read.words <$> getLine
  sc <- replicateM m $ pair.map read.words <$> getLine
  print $ solve n sc

solve n sc = fromMaybe (-1) $ find f $ can n where
  f n = all g sc where
    g (s,c) = digitToInt(sn !! (s-1)) == c
    sn = show n
  can 1 = [0..9]
  can 2 = [10..99]
  can 3 = [100..999]

pair (a:b:_) = (a,b)


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()

graph = [[] for _ in range(N)]
edges = []
 
for _ in range(N - 1):
  a, b = inputIL()
  edges.append((a-1, b-1))
  
for a, b in edges:
  graph[a].append(b)
  graph[b].append(a)
  
  
M = inputI()
m = inputILL(M)

prv = [None for i in range(N)]

prv[0] = -1

q = deque([0])

while q:
  u = q.popleft()
  for v in graph[u]:
    if prv[v] == None:
      prv[v] = u
      q.append(v)

to_root = []

for i in range(N):
  s = 0
  now = i
  while now!=0:
    s += pow(2,now)
    now = prv[now]
  to_root.append(s)

  
ans = 0
for k in range(pow(2,M)):
  J = []
  for i in range(M):
    if k>>i & 1:
      J.append(m[i])
  mask = 0
  for u,v in J:
    mask |= to_root[u-1]^to_root[v-1]
  ##########
  count = 0
  while mask:
    mask &= mask -1
    count += 1
  ##########
  c = 0
  while k:
    k &= k -1
    c += 1
  sign = 1
  if c%2 == 1:
    sign = -1
  ###########
  ans += sign * pow(2,N-1-count)

print(ans)

Measured memory_bytes: 69720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<string> S(N);
    rep(n,0,N) cin>>S.at(n);

    map<char,int> mp;
    for(auto c:S.at(0)) mp[c]++;

    for(auto s:S){
        map<char,int> _mp;
        for(auto c:s) _mp[c]++;
        for(auto m:mp){
            if(_mp.count(m.first)) mp[m.first]=min(m.second,_mp[m.first]);
            else mp[m.first]=0;
        }
    }

    string ans="";
    for(auto m:mp){
        rep(i,0,m.second) ans.push_back(m.first);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools

n = int(input())
x = [[0,0] for i in range(n)]
max = 1
for i in range(n) :
  x[i][0],x[i][1] = map(int,input().split())
  max = max*(i+1)

ans = 0
for t in itertools.permutations(x):
    for i in range(n-1) :
      ans += ((t[i][0]-t[i+1][0])**2+(t[i][1]-t[i+1][1])**2)**0.5

print(ans/max)

Measured memory_bytes: 3188
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>                                    
#include <deque>                                    
#include <queue>
#include <iomanip>
#include <ctime>
#include <random>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;

 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], suff[N], ans;

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   return a;
}

inline int mult (int a, int b) {
   return 1ll * a * b % mod;
}
 
inline void boost () {
   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
}

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = n; i >= 1; i --) suff[i] = add (suff[i + 1], a[i]);
   for (int i = 1; i <= n; i ++) {
      ans = add (ans, mult (a[i], suff[i + 1]));
   }
   cout << ans;
}               
 
signed main () {                                       
  // #ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                 


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

using namespace std;

int main() {
    int h, w, n;
#ifdef debug
    w = 1e9;
    n = 1e5;
    cout << w << " " << w << " " << n << endl;
    for (int i = 0; i < n; ++i) cout << i << " " << 2 << endl;
#endif
    scanf("%d %d %d", &h, &w, &n);
    map<pair<int, int>, int> m, visit;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        m[{a - 1, b - 1}] = 1;
        v.push_back({a - 1, b - 1});
    }
    int dir[] = {0, -1,  -2};
    vector<long long> res(10, 0);

    
    for (auto e: v) {
        for (int i = 0; i < 3; ++i)
            for (int j = 0; j < 3; ++j) {
                int x = e.first  - i;
                int y = e.second - j;
                if (x < 0 || y < 0 || x + 2 >= h || y + 2 >= w || visit.find({x, y}) != visit.end()) continue;
                visit[{x, y}] = 1;
                int travel[] = {0, 1, 2};
                int black = 0;
                for (int ii = 0; ii < 3; ++ii)
                    for (int jj = 0; jj < 3; ++jj) m[{x + travel[ii], y + travel[jj]}] ? black++ : 1 + 1;
                res[black]++;
            }
    }
    res[0] = 1LL * (h - 2) * (w - 2);
    for (int i = 1; i < 10; ++i) res[0] -= res[i];

    for (int i = 0; i < 10; ++i) printf("%lld\n", res[i]);



    return 0;
}


Measured memory_bytes: 213492
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<vector<int>> g(n + 1);
	for(int i = 1, a, b; i < n; i++){
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<int> color(n + 1, -1);
	queue<int> Q;
	Q.push(1);
	color[1] = 1;
	while(!Q.empty()){
		int u = Q.front();Q.pop();
		for(auto &v : g[u]){
			if(color[v] == -1){
				color[v] = 1 - color[u];
				Q.push(v);
			}
		}
	}
	
	vector<int> p(n + 1);
	vector<bool> used(n + 1);
	
	int white = 0, black = 0;
	for(int i = 1; i <= n; i++){
		if(color[i] == 1)
			white++;
		else
			black++;
	}
	
	if(white > black){
		swap(white, black);
		for(int i = 1; i <= n; i++)
			color[i] = 1 - color[i];
	}
	
	int k = n / 3;
	
	if(white <= k){
		int x = 3;
		for(int i = 1; i <= n; i++){
			if(color[i] == 1){
				p[i] = x;
				used[x] = true;
				x += 3;
			}
		}
		
		x = 1;
		for(int i = 1; i <= n; i++){
			if(color[i] == 0){
				while(used[x]){
					x++;
				}
				used[x] = true;
				p[i] = x;
			}
		}
	}
	else{
		int x = 1;
		for(int i = 1; i <= n && x <= n; i++){
			if(color[i] == 1){
				p[i] = x;
				used[x] = true;
				x += 3;
			}
		}
		
		x = 2;
		for(int i = 1; i <= n && x <= n; i++){
			if(color[i] == 0){
				p[i] = x;
				used[x] = true;
				x += 3;
			}
		}
		
		x = 1;
		for(int i = 1; i <= n; i++){
			if(p[i] == 0){
				while(used[x]){
					x++;
				}
				used[x] = true;
				p[i] = x;
			}
		}
	}
	
	for(int i = 1; i <= n; i++)
		cout << p[i] << " \n"[i == n];

	return 0;
}


Measured memory_bytes: 15344
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;

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

    int x[N];
    for (int i=0;i<N;i++){
        cin >> x[i];
    }
    int total = x[N-1] - x[0] + T;

    int xx = x[0];
    for(int i=1; i<N;i++){
        int yy = x[i];
        total -= max(yy - xx - T , 0);
        xx = yy;
    }

    cout << total << endl;

    return 0;
}


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

int main(void){
	char s[131072];
	int k,i,m;
	scanf("%s",s);
	scanf("%d",&k);
	m = strlen(s);
	for(i=0;i<m-1;i++){
		if((123 - s[i]) <= k && s[i] != 'a'){
			k-=(123 - s[i]);
			s[i] = 'a';
		}
	}
	s[m-1] = (((s[m-1]-97)+k%26)%26)+97;
	printf("%s\n",s);
	return 0;
}


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

struct UnionFind {
	//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
	//そうでなければ親のid
	vector<int> r;

	UnionFind(int N) {
		r = vector<int>(N, -1);
	}

	int root(int x) {
		if (r[x] < 0) return x;
		return r[x] = root(r[x]);
	}

	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);
		r[x] += r[y];
		r[y] = x;
		return true;
	}

	int size(int x) {
		return -r[root(x)];
	}
};


int main() {
	int N, M;
	cin >> N >> M;
	
	//友達集合を作る
	UnionFind UF(N);
	for (int i = 0; i < M; i++)
	{
		int A, B;
		cin >> A >> B;
		A -= 1; B -= 1;
		UF.unite(A, B);
	}

	//最大の友達集合を求める
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans = max(ans, UF.size(i));
	}

	cout << ans << endl;
}



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

int mygcd(int a, int b){
    int r;
    if(a < b){
        swap(a,b);
    }
    while(b > 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main(){
    int k;
    cin >> k;
    long long int sum = 0; 
    for(int i = 1; i < k+1; i++){
        for(int j = 1; j < k+1; j++){
            for(int p = 1; p < k+1; p++){
                sum += mygcd(i,mygcd(j,p));
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
import math
a,b = map(int,input().split())
c = math.ceil(a/0.08)
d = math.ceil(b/0.1)
c = max(c,d)
e = math.floor(c*0.08)
f = math.floor(c*0.1)
if a == e and b == f:
  print(c)
else: print(-1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int k;
int vis[N];

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

  scanf("%d", &k);
  int cur = 0;
  for(int i = 1 ; ; ++i){
    cur = (cur*10)+7;
    cur %= k;
    if(vis[cur])
      return puts("-1") , 0;
    if(cur == 0)
      return printf("%d\n" , i) , 0;
    vis[cur] = 1;
  }


  return 0;
}


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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
//using P = pair<ll, ll>;
const ll M = 1000000007;
ll F[200][10];
ll P[200][11];
signed main() {
    ll n;
    cin>>n;
    REP(i,n)REP(j,10)cin>>F[i][j];
    REP(i,n)REP(j,11)cin>>P[i][j];
    ll ans=-INF;
    for(ll s=1;s<(1LL<<10);s++){
        ll sum=0;
        REP(i,n){
            ll cnt=0;
            REP(b,10){
                ll o=((s>>b)&1);
                if(o==1&&F[i][b]){
                    cnt+=1;
                }
            }
            sum+=P[i][cnt];
        }
        chmax(ans,sum);
    }
    cout<<ans<<endl;
}


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

int main(){
    int a,b;
    string s,t,u;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(s == u){
        a--;
    } else if(t == u) {
        b--;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  ll mony = 1000;
  rep(i, 0, n - 1) {
    if (a[i] < a[i + 1]) {
      ll stock = mony / a[i];
      mony %= a[i];
      mony += stock * a[i + 1];
    }
  }

  cout << mony << endl;
}


Measured memory_bytes: 3520
#include <stdio.h>

int main()
{
  int a,b;
  int i,p = -1;

  scanf("%d%d",&a,&b);

  for(i=1; i<1010; i++)
    {
      if(i * 8 / 100 == a && i / 10 == b){
        p = i;
        break;
      }
    }
    printf("%d",p);
  return 0;
}


Measured memory_bytes: 1708
n,k = map(int, input().split())
d = sorted([int(input()) for _ in range(n)],reverse=True)
ret = 9999999999
#print(d)
for i in range(n-k+1):
    #print(i,i+k-1)
    ret = min(ret,d[i]-d[i+k-1])
print(ret)


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N,Q;
    cin >> N >> Q;

    vector<tuple<i64,i64,i64>> xst(N);
    rep(i,0,N){
        i64 S,T,X;
        cin >> S >> T >> X;
        xst[i] = make_tuple(X,S,T);
    }
    
    sort(begin(xst),end(xst));
    
    set<pair<i64,i64>> d;
    rep(i,0,Q){
        i64 D;
        cin >> D;
        d.insert(make_pair(D,i));
    }
    
    vector<i64> ans(Q,-1);
    for(auto& tup:xst){
        i64 s,t,x;
        tie(x,s,t) = tup;
        pair<i64,i64> lb=make_pair(s-x,-inf64),ub=make_pair(t-x,-inf64);
        auto lb_it=d.lower_bound(lb),ub_it=d.lower_bound(ub);
        for(auto it=lb_it; it!=ub_it; ++it){
            ans[it->second]=x;
        }
        d.erase(lb_it,ub_it);
    }
    
    rep(i,0,Q){
        cout << ans[i] << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 20608
f=lambda:map(int,input().split())
n,m=f()
ll=[[0]*n for _ in range(m)]
for l in ll:
  k,*s=f()
  for i in s: l[i-1]=1
p=list(f())
import itertools as it
print(sum(all(sum(a*b for a,b in zip(l,t))%2==p[i] for i,l in enumerate(ll)) for t in it.product([0,1],repeat=n)))

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

int main()
{
    ll n;
    cin>>n;
    ll a[n+7];
    for(int i=1;i<=n;i++) cin>>a[i];
    ll dp[n+7];
    memset(dp,-1,sizeof(dp));
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n]<<endl;

}


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

int main(void) {

    int N, M, K; cin >> N >> M >> K;
    bool flag = false;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            int masu = i*(M-j)+j*(N-i);
            if (masu == K) {
                flag = true;
                break;
            }
        }
        if (flag) break;
    }

    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
SUM = 0
for key in C.keys():
    num = C[key]
    SUM += (num*(num-1))//2
for a in A:
    if C[a] <= 1:
        print(SUM)
    else:
        num = C[a]
        A = num*(num-1)//2
        B = (num-1)*(num-2)//2
        print(SUM-A+B)

Measured memory_bytes: 26908
#include <iostream>
#include <queue>
#include <unordered_map>
#include <utility>
#include <array>
#include <cstring>

bool isObstacle[1000][1000];
bool done[1000][1000];

int main() {
	int h, w, n;
	std::cin >> h >> w >> n;

	std::unordered_map<int, int> factories;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			char c;
			std::cin >> c;

			if (c == 'S')
				factories[0] = j * 1000 + i;
			else if ('1' <= c && c <= '9')
				factories[c - '0'] = j * 1000 + i;
			else if (c == 'X')
				isObstacle[j][i] = true;
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		const int sx = factories[i] / 1000, sy = factories[i] % 1000;
		const int gx = factories[i + 1] / 1000, gy = factories[i + 1] % 1000;

		std::memset(done, 0, sizeof(done));

		done[sx][sy] = true;

		auto candidate = [h, w](int x, int y) {
			std::array<int, 4> arr;
			arr[0] = ((x == 0 || isObstacle[x - 1][y] || done[x - 1][y]) ? -1 : (done[x - 1][y] = true, (x - 1) * 1000 + y));
			arr[1] = ((x == w - 1 || isObstacle[x + 1][y] || done[x + 1][y]) ? -1 : (done[x + 1][y] = true, (x + 1) * 1000 + y));
			arr[2] = ((y == 0 || isObstacle[x][y - 1] || done[x][y - 1]) ? -1 : (done[x][y - 1] = true, x * 1000 + y - 1));
			arr[3] = ((y == h - 1 || isObstacle[x][y + 1] || done[x][y + 1]) ? -1 : (done[x][y + 1] = true, x * 1000 + y + 1));

			return std::move(arr);
		};

		std::queue<std::pair<int, int>> q;
		q.push({ factories[i], 0 });
		while (!q.empty()) {
			const auto& top = q.front();
			const int nx = top.first / 1000, ny = top.first % 1000;
			int cost = top.second;

			auto&& c = candidate(nx, ny);
			for (auto v : c) {
				if (v != -1) {
					if (v / 1000 == gx && v % 1000 == gy) {
						ans += cost + 1;
						q.pop();
						goto end;
					}
					q.push({ v, cost + 1 });
				}
			}

			q.pop();
		}
	end:;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 5032
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	
	int a, b, c, d;
	
	cin >> a >> b >> c >> d;
	
	int sum = a + b + c + d;
	
	cout << (sum / 60) << endl << (sum % 60) << endl;
	
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var k = sc.nextInt();
		var a = sc.nextInt();
		var b = sc.nextInt();
		sc.close();

		boolean result = false;
		for (int i = a; i <= b; i++) {
			if (i % k == 0) {
				result = true;
			}
		}

		System.out.println(result ? "OK" : "NG");
	}
}

Measured memory_bytes: 35716
N,M,X = map(int, input().split())
List = [list(map(int, input().split())) for i in range(N)]
#N,M,X=3,3,10
#List=[[60, 2, 2, 4], [70, 8, 7, 9], [50, 2, 3, 9]]

#print(List)
cost=1200100

for i in range(2**N-1):
    price=0
    num=format(i+1,'0{}b'.format(N))
    arg=[0]*M #それぞれのアルゴリズムの理解度
    for e in range(N):
        if  num[N-1-e]=="1":
            for u in range(M):
                arg[u]+=List[e][u+1]
            price+=List[e][0]  
    b=1
    #print(arg)
    #print(price)
    for t in range(M):
        if  not arg[t]>=X:
            b=2
        #print(b)
    if price<=cost and b==1:
        cost=price
if cost==1200100:
    print("-1")
else:
    print(cost)
 

Measured memory_bytes: 9228
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>

using namespace std;
vector<bool> visited;
vector<vector<int> > graph;
void dfs(int u){
	visited[u] = true;
	for(int i = 0; i  < (int)graph[u].size(); i++){
		if(!visited[graph[u][i]]){
			dfs(graph[u][i]);
		}
	}
}
int main(){
	int n, m; cin>>n>>m;
	graph.resize(n);
	visited.resize(n);
	for(int i = 0; i < m; i++){
		int a, b; cin>>a>>b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(!visited[i]){
			dfs(i);
			ans++;
		}
	}
	cout<<ans - 1;
}


Measured memory_bytes: 9532
count = 0
INFTY = 10 ** 10

def merge(A, left, mid, right):
  global count
  n1 = mid - left;
  n2 = right - mid;

  L = []
  R = []

  for i in range(n1):
    L.append(A[left + i])
  for i in range(n2):
    R.append(A[mid + i])

  L.append(INFTY)
  R.append(INFTY)

  i = 0
  j = 0
  for k in range(left, right):
    count = count + 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)/2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

import sys

n = raw_input()
for line in sys.stdin:
  items = line.strip().split()
  items = map(int, items)
  mergeSort(items, 0, len(items))
  print " ".join(map(str, items))
  print count

Measured memory_bytes: 75284
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[309][309],have[309];
char s[309][309];
int main() {
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if(s[i][j]=='#') {
				have[i]=1;
				break;
			}
	int num=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if(s[i][j]=='#') {
				int l=j,r=j,u=i,d=i;
				while(l>0&&s[i][l-1]!='#'&&a[i][l-1]==0) l--;
				while(r<m-1&&s[i][r+1]!='#'&&a[i][r+1]==0) r++;
				while(u>0&&have[u-1]==0&&a[u-1][j]==0) u--;
				while(d<n-1&&have[d+1]==0&&a[d+1][j]==0) d++;
				num++;
				for(int x=u;x<=d;x++)
					for(int y=l;y<=r;y++)
						a[x][y]=num;
			}
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) printf("%d ",a[i][j]);
		printf("\n");
	}
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] && s[0] == s[2]) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    if (n%2==0) cout << n/2 << endl;
    else cout << n/2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

main :: IO ()
main = do
  n <- readInt
  let
    ss = zip [1..] $ scanl1 (+) [1..n]
    getAns ((ind,s):xs)
      | s == n = (ind, s)
      | s > n = (ind, s)
      | otherwise = getAns xs
    (ind, s) = getAns ss
    exclude = s - n
    ans = filter (/= exclude) [1..ind]
  forM_ ans print





Measured memory_bytes: 1020
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int h, a; cin>>h>>a;

    cout << (h + a - 1) / a << endl;

    return 0;
}

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

int main(){
    int n,k,s=0;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i < n; ++i) cin >> arr[i];
    sort(arr,arr+n);
    for(int i = 0; i < k; ++i) s += arr[i];
    cout << s;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    //入力・初期化
    string S;
    cin >> S;
    bool can = false;

    //処理
    if(S[0]!=S[1] && S[1]!=S[2] && S[2]!=S[0]){
        can = true;
    }

    //出力
    cout<<(can?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (1LL<<62)
#define NINF ((-1)*(INF))
#define MOD (1000000007)

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	#ifdef LOCAL_PROJECT
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int n, k;
	cin >> n >> k;
	vector<int> h(n+105, INF), dp(n+105, INF);
	for(int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	dp[0] = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = 1; j <= k; j++)
		{
			dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j]-h[i]));
		}
	}
	cout << dp[n-1];
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
  
struct Point { double x,y;};
  
void koch(int n, Point a,Point b){
    if(n==0)return;
      
    Point s,t,u;
    double th=M_PI*60.0/180.0;
      
    s.x=(2.0*a.x+1.0*b.x)/3.0;
    s.y=(2.0*a.y+1.0*b.y)/3.0;
    t.x=(1.0*a.x+2.0*b.x)/3.0;
    t.y=(1.0*a.y+2.0*b.y)/3.0;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
      
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}
  
int main(){
    Point a,b;
    int n;
    scanf("%d",&n);
      
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
      
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
      
    return 0;
}

Measured memory_bytes: 2696
import itertools
a,b,c=map(int, input().split())
l = [input() for i in range(a)]

ans = 0
Ans = 0
for i in itertools.product((1,-1),repeat=a):
    for j in itertools.product((1,-1),repeat=b):
        for k in range(a):
            for m in range(b):
                if i[k] == j[m] == 1 and l[k][m] == '#':
                    ans += 1
        if ans == c:
            Ans += 1
        ans = 0
print(Ans)

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int N;
  int d[1000010];

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }

  sort(d, d + N);
  int boundary_index = N / 2;
  if (d[boundary_index - 1] == d[boundary_index]) {
    cout << 0 << endl;
    return 0;
  }

  cout << d[boundary_index] - d[boundary_index - 1] << endl;
  return 0;
}

Measured memory_bytes: 2688
import numpy as np

N,D=map(int,input().split())
listX=[]
X=0
for i in range(0,N):
  X=list(map(int,input().split()))
  listX.append(X)
Y=0
count=0

for i in range(0,N):
  for j in range(i+1,N):
    vec_a=np.array(listX[i])
    vec_b=np.array(listX[j])
    Y=np.linalg.norm(vec_a - vec_b)
  
    if Y.is_integer()==True:
      
      if Y==0:
        next
      else:
        count+=1
print(count)


Measured memory_bytes: 12384
A, B, C = map(int, input().split())

first_amari = A%B
next_amari=0
i=2
while(first_amari!=next_amari):
    next_amari = (A*i) % B
    if next_amari == C:
        print("YES")
        exit()
    i+=1

print("NO")

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

int r[100010], b[100010];
int main() {
	int N, M, x, y; cin >> N >> M;
	for(int i=1; i<=N; ++i) b[i]=1;
	r[1]=1;
	for(int i=0; i<M; ++i){
	    cin >> x >> y;
	    --b[x]; ++b[y];
	    if(r[x]){
	        r[y]=1;
	        if(b[x]<1) r[x]=0;
	    }
	}
	int ans=0;
	for(int i=1; i<=N; ++i) ans += r[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	long N, P;
	List<Long> coords;
	long limit;
	long result = 1;

	Main() {
		Scanner in = new Scanner(System.in);
		N = in.nextLong();
		P = in.nextLong();
		in.close();
		calcLimit();
	}

	void calcLimit() {
		long times = N;
		limit = P;
		while (times >= 2) {
			limit = (long) Math.sqrt((double) limit);
			times /= 2;
		}
	}

	void calc() {
		for (long v = limit; v > 0; --v) {
			if (Math.pow(v, N) > P) {
				continue;
			}
			if (P % (long)Math.pow(v, N) == 0) {
				result = v;
				break;
			}
		}
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calc();
		System.out.println(ins.result);
	}

}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int N,P;
int cnt[10101];
int T[2<<17];
string s;
main()
{
	cin>>N>>P>>s;
	long ans=0;
	if(P==2||P==5)
	{
		for(int i=0;i<N;i++)
		{
			if((s[i]-'0')%P==0)ans+=i+1;
		}
	}
	else
	{
		T[N-1]=1;
		for(int i=N-1;i--;)
		{
			T[i]=T[i+1]*10%P;
		}
		int now=0;
		cnt[0]=1;
		for(int i=0;i<N;i++)
		{
			now=(now+(s[i]-'0')*T[i])%P;
			ans+=cnt[now]++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
int main () {
	int a1, b1, a2, b2, a3, b3;
	cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;
	int count[4] = {0,0,0,0};
	count[a1-1] += 1;
	count[a2-1] += 1;
	count[a3-1] += 1;
	count[b1-1] += 1;
	count[b2-1] += 1;
	count[b3-1] += 1;
	bool result = true;
	for (int i = 0; i < 4; ++i)
	{
		if(count[i] >= 3){
			result = false;
			break;
		}
	}
	if(result){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    int n, a[100001], b[100001];
    cin >> n;
    priority_queue<pair<llong, int> > sum_A_plus_B;
    rep(i, n) {
        cin >> a[i] >> b[i];
        sum_A_plus_B.push(make_pair(a[i] + b[i], i));
    }

    llong ans = 0; 
    rep(i, n) {
        if (i % 2 == 0) ans += a[sum_A_plus_B.top().second];
        else ans -= b[sum_A_plus_B.top().second];

        sum_A_plus_B.pop();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2932
/*
 *  Author :: Kattu37
 */

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortallr(x) sort(allr(x))
#define PI 3.1415926535897932384626
#define mod 1000000007

typedef pair<int, int>  pii;
typedef pair<ll, ll>  pll;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pll>   vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;

void solve()
{
	int h, w, m;
	cin >> h >> w >> m;

	vector<int> r(h), c(w);
	set<pair<int, int> > s;

	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		r[x]++;
		c[y]++;
		s.insert({x, y});
	}

	int mxr = 0, mxc = 0;
	for (auto it : r)
		mxr = max(mxr, it);
	for (auto it : c)
		mxc = max(mxc, it);

	vector<int> rm, cm;
	//cout << mxr << mxc << "\n";
	for (int i = 0; i < r.size(); i++)
		if (r[i] == mxr)
			rm.pb(i);
	for (int i = 0; i < c.size(); i++)
		if (c[i] == mxc)
			cm.pb(i);

	//cout << rm.size() << cm.size();

	for (int i = 0; i < rm.size(); i++)
	{
		for (int j = 0; j < cm.size(); j++)
		{
			//cout << rm[i] << " " << cm[j] << "\n";
			if (s.find({rm[i], cm[j]}) == s.end())
			{
				cout << mxr + mxc << "\n";
				return;
			}
		}
	}

	cout << mxr + mxc - 1 << "\n";

}

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

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 23788
N, K, Q = gets.chomp.split.map(&:to_i)

if K - N >= Q*2
	(N..N+Q-1).each do |a|
		puts a
	end
	(K-Q+1..K).each do |b|
		puts b
	end
else
	(N..K).each do |c|
		puts c
	end
end

Measured memory_bytes: 1788
#include "bits/stdc++.h"

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 9;

ll n, w;
ll weight[105], value[105];
ll dp[105][maxn];

ll fnc(ll pos, ll baki)
{
    if(pos > n) return 0;

    if(dp[pos][baki]) return dp[pos][baki];

    ll p = 0, q = 0;

    if(baki >= weight[pos]) p = fnc(pos + 1, baki - weight[pos]) + value[pos];

    q = fnc(pos + 1, baki);

    return dp[pos][baki] = max(p, q);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    fast;

    cin >> n >> w;

    for(ll i = 1; i <= n; i++) cin >> weight[i] >> value[i];

    cout << fnc(1LL, w) << endl;

    return 0;
}


Measured memory_bytes: 75640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000000000010000;

ll bit[1000010];
//ll kai[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		(t += bit[i]) %= mod;
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 1;
	while (i <= 1000005)
	{
		(bit[i] += x) %= mod;
		i += i & -i;
	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}

void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 1000005; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N;
double value[301][301][301];
double pro[301][301][301];
bool flg[301][301][301];
ll a[301];
ll num[4];

P saiki(ll one, ll two, ll three) {
	if (one == num[1] && two == num[2] && three == num[3]) {
		return P(1, 0);
	}
	if (flg[one][two][three]) {
		return P(pro[one][two][three], value[one][two][three]);
	}

	flg[one][two][three] = true;
	double prob = 0, pr;
	double nu = 0;
	if (one < N) {
		P p = saiki(one + 1, two, three);
		pr = p.f * (one + 1) / (one + 1 + two + three);
		prob += pr;
		nu += (p.s + (double)N / (one + 1 + two + three)) * pr;
	}
	if (one > 0 && two < N) {
		P p = saiki(one - 1, two + 1, three);
		pr = p.f * (two + 1) / (one + two + three);
		prob += pr;
		nu += (p.s + (double)N / (one + two + three)) * pr;
	}
	if (two > 0 && three < N) {
		P p = saiki(one, two - 1, three + 1);
		pr = p.f * (three + 1) / (one + two + three);
		prob += pr;
		nu += (p.s + (double)N / (one + two + three)) * pr;
	}
	if (prob != 0) {
		nu /= prob;
	}
	pro[one][two][three] = prob;
	value[one][two][three] = nu;
	return P(prob, nu);
}

void solve() {
	cin >> N;
	rep(i, N) {
		cin >> a[i];
		num[a[i]]++;
	}
	pro[num[1]][num[2]][num[3]] = 1;

	P p = saiki(0, 0, 0);
	printf("%.10lf\n", p.s);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 455168