akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	count := 0
	// 1の位
	for i := 1; i < 10 && i <= n; i++ {
		count++
	}
	// 100の位
	for i := 100; i < 1000 && i <= n; i++ {
		count++
	}
	// 10000の位
	for i := 10000; i < 100000 && i <= n; i++ {
		count++
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define I ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    ll n,i,ans=0;
    cin>>n;
    ll a[n-1];
    for(i=0;i<n-1;i++)cin>>a[i];
    ans=a[0]+a[n-2];
    for(i=0;i<n-2;i++)
    {
        ans+=min(a[i],a[i+1]);
    }
    cout<<ans;
}


Measured memory_bytes: 3640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() 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 main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)

	ans := 0
	for i := 0; i < n; {
		j := i
		for ; j < n-1 && s[j] == s[j+1]; j++ {
		}
		i = j+1
		ans++
	}

	fmt.Println(ans)
}

Measured memory_bytes: 1280
# 点更新，区間クエリ
class SegTree:
    # n : 元の配列の長さ
    # init_list: 元の配列
    # segfunc : 載せる関数（演算）
    # ide_ele : segfuncの単位元
        
    def __init__(self, n, init_list ,segfunc, ide_ele):
        #　num : 2**num >= n となる最小の整数 （葉の数）
        # seg : segtreeのリスト
        self.num = 2**((n-1).bit_length())
        self.seg = [ide_ele]*(2*self.num)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        # 葉の要素をセット
        for i in range(n):
            self.seg[i+self.num-1] = init_list[i]        
        # segtreeの構築
        for i in range(self.num-2, -1, -1):
            self.seg[i] = segfunc(self.seg[2*i+1],self.seg[2*i+2])
        
        #memo: 要素iの子ノードは要素2*i+1, 2*i+2
        #    : 要素iの親ノードは要素(i-1)//2
        
    # 要素の更新 (init_list[k]=x)
    def update(self,k,x):
        k += self.num-1 #葉のノードのインデックス
        self.seg[k] = x
        #末端から頂点まで更新
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[2*k+1], self.seg[2*k+2])
     
    # 区間クエリ （区間[l,r)に対する演算結果）
    def query(self, l,r):
        if r<=l:
            return self.ide_ele
        
        l += self.num-1 #葉のノードのインデックス
        r += self.num-2 #半開区間から閉区間へ
        ret = self.ide_ele
        
        while r-l>1:
            if l&1 == 0:
                ret = self.segfunc(ret,self.seg[l])
            
            if r&1 == 1:
                ret = self.segfunc(ret,self.seg[r])
                r -= 1
            # 親ノードへ遷移
            l = l//2
            r = (r-1)//2
        if r==l:
            ret = self.segfunc(ret, self.seg[r])
        else:
            ret = self.segfunc(ret, self.seg[l])
            ret = self.segfunc(ret, self.seg[r])
        
        return ret
            
def segfunc(x,y):
    return x|y

N = int(input())
S = list(input())
Q = int(input())

A = [0]*N
atmp = ord('a')

for i in range(N):
    A[i] = 1<<(ord(S[i])-atmp)
    
seg = SegTree(N,A,segfunc,0)
popcount = lambda x: bin(x).count('1')

ans = []
for i in range(Q):
    t,l,r = map(str,input().split())
    if t=='1':
        i = int(l)-1
        c = r
        upt = 1<<(ord(c)-atmp)
        seg.update(i,upt)
        
    else:
        l,r = int(l)-1,int(r)
        ans.append(popcount(seg.query(l,r)))

for a in ans:
    print(a)











Measured memory_bytes: 109736
#include<stdio.h>

int main(){
	int min(int x, int y){
		if(x<y) return x;
		else return y;
	}
	int max(int x, int y){
		if(x>y) return x;
		else return y;
	}
	int i, j;
	int n,q;
	scanf("%d",&n);
	int S[n];
	for(i=0;i<n;i++)
	scanf("%d",&S[i]);
	scanf("%d",&q);
	int T[q];
	for(i=0;i<q;i++)
	scanf("%d",&T[i]);
	int left,right,mid;
	int count=0;
	left=0;
	right=n-1;
	mid=(n-1)/2; 

	for(i=0;i<q;i++){
		if(T[i]<=S[n-1] && T[i]>=S[0]){
		while(left<right){
			if(S[mid]==T[i]){
				count++;
				left=right;}
			else if(S[mid]<T[i]){
				left=max(left+1,mid);
				if(left > mid){if(S[left]==T[i]) count++;}
				mid=(left+right)/2;
				}
			else if(S[mid]>T[i]){
				right=min(right-1,mid);
				if(right < mid){if(S[right]==T[i]) count++;}
				mid=(left+right)/2;
				}
		}
		left=0;
		right=n-1;
		mid=(n-1)/2;
		}
	}
	printf("%d\n",count); 
	return 0;
}

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

int main() {
    int N, ls, le,sum = 0;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> ls >> le;
        sum += (le - ls) + 1;
    }
    cout << sum << endl;
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
int main(){
  int K;
  cin >> K;
  int ans = 0;
  for(int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        ans += gcd(i,gcd(j,k));
      }
    }
  }
  cout << ans << endl;
 }

Measured memory_bytes: 3616
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
flag = False

for value in A:
    if value % 2 == 0:
        if value % 3 != 0 and value % 5 != 0:
            flag = True

if flag:
    print('DENIED')
else:
    print('APPROVED')



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using P = pair<int, int>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int v, e, r;
  cin >> v >> e >> r;
  vector<vector<int>> to(v), co(v);
  rep(i, e) {
    int a, b, c;
    cin >> a >> b >> c;
    to[a].push_back(b);
    co[a].push_back(c);
  }
  vector<int> dist(v, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, r});
  dist[r] = 0;
  while (!que.empty()) {
    int now, cost;
    tie(cost, now) = que.top();
    que.pop();
    if (cost > dist[now])
      continue;
    rep(i, to[now].size()) {
      if (chmin(dist[to[now][i]], dist[now]+co[now][i]))
        que.push({dist[to[now][i]], to[now][i]});
    }
  }
  rep(i, v) {
    if (dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 16928
N = int(input())
H = list(map(int, input().split()))
i = 0
ctr = 0
done = False

while sum(H) > 0:
    
    if H[i] > 0:
        done = True 
        H[i] -= 1
    else: 
        if done:
            ctr += 1
            done = False
    i += 1
    if i == N:
        i = 0
        if done:
            ctr += 1
            done = False

if done:
    ctr += 1
print(ctr)

Measured memory_bytes: 39408
def main():
    n  = int(input())
    ans = {'AC':0 , 'WA':0, 'TLE':0, 'RE':0}
    for i in range(n):
        s = input()
        ans[s] += 1
    for key, v in ans.items():
        print(key + ' x ' + str(v))

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9164
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for _ in range(q)]

    res = []
    for e in range(1, m + 1):
        for f in range(e, m + 1):
            for g in range(f, m + 1):
                for h in range(g, m + 1):
                    for i in range(h, m + 1):
                        for j in range(i, m + 1):
                            for k in range(j, m + 1):
                                for l in range(k, m + 1):
                                    for o in range(l, m + 1):
                                        for p in range(o, m + 1):
                                            res.append([e, f, g, h, i, j, k, l, o, p])

    ans = 0
    for p in res:
        score = 0
        for a, b, c, d in ABCD:
            if p[b - 1] - p[a - 1] == c:
                score += d

        ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 91964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <math.h>

using namespace std;

int main()
{
	int n, h, b_h = 0, ans = 0;
	cin >> n;
	for (int t = 0; t < n; t++) {
		cin >> h;
		if (b_h <= h) {
			ans++;
			b_h = h;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int h, w;
int a[81][81], b[81][81];
bool dp[81][81][6500];
// DAME:
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;

    rep(i, h)rep(j, w) cin >> a[i][j];
    rep(i, h)rep(j, w) cin >> b[i][j];

    dp[0][0][abs(a[0][0] - b[0][0])] = true;

    rep(i, h)rep(j, w)rep(k, 6400){
        if(dp[i][j][k]){
            int kk = abs(a[i+1][j] - b[i+1][j]);
            int kkk = abs(a[i][j+1] - b[i][j+1]);
            dp[i+1][j][k+kk] = true;
            dp[i+1][j][abs(k-kk)] = true;
            dp[i][j+1][k+kkk] = true;
            dp[i][j+1][abs(k-kkk)] = true;
        }
    }
    rep(i, 6600){
        if(dp[h-1][w-1][i]){
            cout << i << endl;
            return 0;
        }
    }
    cout << 11111 << endl;
    return 0;
}

Measured memory_bytes: 41856
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll; 
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n)cin >> p[i];
  int count = 0;
  int mi = p[0];
  rep(i, n){
    if (p[i] <= mi ){++count;}
    mi = min(mi, p[i]);
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(S: str):
    result = 0
    for i in range(len(S)):
        for j in range(i, len(S)):
            if all("ACGT".count(c) == 1 for c in S[i : j + 1]):
                result = max(result, len(S[i : j + 1]))
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


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

static const int MAX = 100;
static const int INF = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    rep(i,n) {
        d[i] = INF;
        p[i] = -1;
        color[i] = WHITE;
    }
    d[0] = 0;

    while(1){
        minv = INF;
        u = -1;
        rep(i,n) {
            if( minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break;
        color[u] = BLACK;
        rep(v,n) {
            if (color[v] != BLACK && M[u][v] != INF) {
                if ( d[v] > M[u][v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    rep(i,n) {
        if (p[i] != -1) sum += M[i][p[i]];
    }
    return sum;
}

int main(){
    cin >> n;
    rep(i,n){
        rep(j,n){
            int e; cin >> e;
            M[i][j] = (e == -1)? INF : e;
        }
    } 
    cout << prim() << endl;
    return 0;
}


Measured memory_bytes: 3132
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    for i in range(n + 1):
        for j in range(n + 1):
            if i * 7 + j * 4 == n:
                print("Yes")
                exit()
    print("No")


if __name__ == '__main__':
    slove()


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

int main(){
	int n,m,c ;
	cin >> n >> m >> c ;
	vector<int> b(m) ;
	int cnt = 0 ;
	int sub ;
	for(int i=0;i<m;i++) cin >> b.at(i) ;
	for(int i=0;i<n;i++){
		sub = c ;
		for(int j=0;j<m;j++){
			int a ; cin >> a ;
			sub += b.at(j)*a ;
		}
		if(sub>0) cnt++ ;
	}
	cout << cnt << endl ;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        for(int i=0;i<str.length();i++){
            char ch = str.charAt(i);
            if(Character.isLowerCase(ch)) {
                ch = Character.toUpperCase(ch);
                System.out.print(ch);
            }else{
                ch = Character.toLowerCase(ch);
                System.out.print(ch);
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 26852
/*Flamenco Sketches*/
#include<bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
//#define FayeValentine 
void dbg(){cerr<<NL;}template<typename H,typename... T> void dbg(H h,T... t){cerr<<' '<<h;dbg(t... );}
#ifdef  FayeValentine
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dbg(__VA_ARGS__)
#else
#define debug(...) 
#endif


void absinthe() {
	ll sum = 0, n; cin >> n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 1; k <= n; k++)
				sum += __gcd(i, __gcd(j, k));
	cout << sum << NL; 
}
 
 
int main(){
  //freopen("input.txt", "r", stdin);
  async();
  int __t = 1; //cin >> __t;
  for(int __c = 1; __c <=__t; __c++) {
    //cout << "Case #" << __c << ": "; 
    absinthe();
  }
}  

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	string S; cin >> S;
	string t = S;
	ll K; cin >> K;
	if (S.size() == 1 && K == 1) {cout << 0; return 0;}
	if (S.size() == 1) {cout << K/2; return 0;}
	bool flag = true;
	for (int i = 0; i <= S.length()-2; i++) {
		if (S[i] != S[i+1]) {flag = false; break;}
	}
	if (flag) {
		cout << (S.size() * K) / 2;
		return 0;
	}
	bool prev = false;
	ll sum1=0, sum2=0;
	for (int i = 0; i < S.length()-1; i++) {
		if (S[i] == S[i+1] && !prev) {
			sum1++;
			prev = true;
		} else prev = false;
	}
	S += t;
	int n = S.length();
	prev = false;
	for (int i = 0; i < n-1; i++) {
		if (S[i] == S[i+1] && !prev) {
			sum2++;
			prev = true;
		} else prev = false;
	}
	cout << sum1 + (sum2-sum1) * (K-1);
    return 0;
}


Measured memory_bytes: 256
def main(n,a):
  sa=sum(a)
  tmp=(n*(n+1))//2
  if sa%tmp!=0:
    return 'NO'
  cnt=sa//tmp
  chk=0
  for i in range(n):
    t=a[i]-a[i-1]
    t-=cnt
    if t==0:continue
    if t%n!=0:return 'NO'
    chk+=abs(t)//n
  if cnt==chk:return 'YES'
  return 'NO'

n=int(input())
a=list(map(int,input().split()))
print(main(n,a))

Measured memory_bytes: 85540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N; cin >> N;
    vector<LL> T(N),A(N);
    vector<LL> rT(N),rA(N);

    REP(i,N)  cin>>T[i] >>A[i];
    REP(i,N)
    {
        rT[i]=T[i];
        rA[i] = A[i];
    }
    dump("check")

    REP(i,N)
    {
        dump(i)
        FOR(j,i+1,N)
        {
            dump(rT[j])
            dump(rA[j])
            if(rT[i] > rT[j] || rA[i]>rA[j])
            {
                LL shT = rT[i]-rT[j];
                LL shA = rA[i]-rA[j];
                LL want = max((shT+T[j]-1)/T[j], (shA+A[j]-1)/A[j]);
                rT[j] += T[j]*want;
                rA[j] += A[j]*want;
            }
        }
    }
    cout << rT[N-1]+rA[N-1] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin>>n;
    int h[n],dp[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

string s;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> s;
	bool flag = true;
	rep(i,0,4){
		int count = 0;
		rep(j,0,4){
			if(s[i]==s[j]){
				count++;
			}
		}
		if(count!=2){
			flag = false;
		}
	}
	if(flag){
		cout << "Yes";
	}else{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
import collections

n = int(input()) 

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

c = collections.Counter(prime_factorize(n))

c = list(c.values())

ans = 0

for i in range(len(c)):
    j = 1
    num = c[i]
    while num >= j:
        ans += 1
        num -= j
        j += 1
print(ans)

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

using namespace std;

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

#define faster ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define debug(x) cout<<#x<<" = "<<(x)<< endl
#define nl "\n"
#define sp " "

const int MOD = 1e9 + 7, SZ = 5e5 + 5;
int fact[SZ], N, M;


ll powmodk(ll a, ll k, ll m) {
    if (k == 0) return 1;
    ll r = powmodk(a, k / 2, m);
    r = (r * r) % m;
    if (k % 2) r = (r * a) % m;
    return r;
}

inline ll fix(ll x){
	return (x % MOD + MOD) % MOD;
}

inline ll modinverse(ll a) {
    return powmodk(fix(a), MOD - 2, MOD);
}

ll nck(int n, int k){
	if(k > n) return 0;
	ll num = fact[n];
	ll den = modinverse(1LL * fact[n - k] * fact[k]);
	return fix(num * den);
}

ll npk(int n, int k){
	return fix(nck(n,k) * fact[k]);
}

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

	fact[0] = 1;
	for(int i = 1; i < SZ; i++){
		fact[i] = fix(1LL * i * fact[i - 1]);
	}

	ll ans = npk(M,N);
	ll cur = 0;
	for(ll s = 1, i = 0; i <= N; i++, s = -s){
		cur += s * nck(N,i) * npk(M - i, N - i);
		cur = fix(cur);
	}

	cout << fix(ans * cur) << nl;
}


Measured memory_bytes: 5552
#include <iostream>
int main() {
	long long int n, p = 1;
	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		p = i * p % (1000000000 + 7);
	}
	std::cout << p;
	return 0;
	/*long long int n, l[86];
	l[0] = 2;
	l[1] = 1;
	std::cin >> n;
	for (int i = 2; i <= n; i++) {
		l[i] = l[i - 1] + l[i - 2];
	}
	std::cout << l[n];
		return 0;
		*/
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
W = [sr() for _ in range(N)]
bl = True
if len(set(W)) != N:
    bl = False
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        bl = False
print('Yes' if bl else 'No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n = s.length(),m=t.length();
	vector<vector<int> > dp(n,vector<int>(m,0));
	vector<vector<int> > res(n,vector<int>(m,-1));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(i==0&&j==0){
				if(s[i]==t[j]){
					dp[i][j] = 1;
					res[i][j] = i;
				}
				else{
					dp[i][j] = 0;
					res[i][j] = -1;
				}
			}
			else if(i==0){
				if(s[i]==t[j]){
					dp[i][j] = 1;
					res[i][j] = i;
				}
				else{
					dp[i][j] = dp[i][j-1];
					res[i][j] = res[i][j-1];
				}
			}
			else if(j==0){
				if(s[i]==t[j]){
					dp[i][j] = 1;
					res[i][j] = i;
				}
				else{
					dp[i][j] = dp[i-1][j];
					res[i][j] = res[i-1][j];
				}
			}
			else{
				if(s[i]==t[j]){
					dp[i][j] = 1+dp[i-1][j-1];
					res[i][j] = i;
				}
				else{
					if(dp[i][j-1]>dp[i-1][j]){
						dp[i][j] = dp[i][j-1];
						res[i][j] = res[i][j-1];
					}
					else{
						dp[i][j] = dp[i-1][j];
						res[i][j] = res[i-1][j];
					}
				}
			}
		}
	}
	string ans = "";
	int i=n-1,j=m-1;
	while(i>=0&&j>=0){
		if(s[i]==t[j]){
			ans += s[i];
			i--;j--;
		}
		else{
			if(i==0){
				j--;
			}
			else if(j==0){
				i--;
			}
			else if(dp[i-1][j]>dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
//	cout<<dp[n-1][m-1]<<endl;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(void) {
  int h, w;
  cin >> h >> w;

  int n;
  cin >> n;

  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }

  vector<vector<int> > G(h, vector<int>(w));
  int x = 0, y = 0;
  int num = 1;
  int cnt = 0;
  while (true) {
    G[y][x] = num;
    cnt++;
    v[num]--;
    if (v[num] == 0) {
      num++;
    }

    if (cnt == h * w) break;
    if (y % 2 == 0) {
      if (x == w - 1) y++;
      else x++;
    } else {
      if (x == 0) y++;
      else x--;
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j) cout << " ";
      cout << G[i][j];
    }
    cout << endl;
  }

  return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            var isFumiyasui = true;
            var oddArray = new char[] { 'R', 'U', 'D' };
            var evenArray = new char[] { 'L', 'U', 'D' };
            for (int i = 1; i <= S.Length; i++)
            {
                var c = S[i - 1];
                if (i % 2 == 0 && !evenArray.Contains(c))
                {
                    isFumiyasui = false;
                    break;
                }
                else if (i % 2 == 1 && !oddArray.Contains(c))
                {
                    isFumiyasui = false;
                    break;
                }
            }

            Console.WriteLine(isFumiyasui ? "Yes" : "No");
        }
    }
}


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

// 2分探索でnums配列からkeyのあるindexを返す
int binarySearch(vector<int> nums, int key)
{
    int left, right;
    left = 0;
    right = nums.size();

    // iterator
    auto pos = lower_bound(nums.begin(), nums.end(), key);
    int idx = pos - nums.begin();

    return nums.at(idx) == key ? idx : -1;
}

void debugVecPrint(vector<int> nums)
{
    rep(i, nums.size())
    {
        if (i)
            cout << " ";
        cout << nums.at(i);
    }
    cout << endl;
}

// ALDS1_4_B参照。配列numsから後に入力するkeyがあれば加算していく。
int main()
{
    int n, q;
    cin >> n;

    vector<int> nums(n);
    rep(i, n)
    {
        scanf("%d", &nums.at(i));
    }

    // 昇順ソート
    sort(nums.begin(), nums.end());
    //debugVecPrint(nums);

    cin >> q;
    int ans = 0;
    rep(i, q)
    {
        int v;
        scanf("%d", &v);
        if (binarySearch(nums, v) >= 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

long long H,W,INF = 1e9;
long long dx[4] = {0,0,1,-1},dy[4] = {1,-1,0,0};
vector<string> S;

long long bfs(long long X,long long Y){
    queue<pair<long long,long long>> Q;
    vector<vector<long long>> dist(H,vector<long long>(W,INF));
    Q.push({X,Y});
    dist[X][Y] = 0;

    while(!Q.empty()){
        pair<long long,long long> P = Q.front();
        Q.pop();
        for (int i = 0;i < 4;i++){
            long long next_x = P.first + dx[i],next_y = P.second + dy[i];
            if (next_x >= 0 && next_x < H && next_y >= 0 && next_y < W){
                if (S[next_x][next_y] == '.' && dist[next_x][next_y] == INF){
                    dist[next_x][next_y] = dist[P.first][P.second] + 1;
                    Q.push({next_x,next_y});
                }
            }
        }
    }
    long long MAX = 0;
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            if (dist[i][j] != INF) MAX = max(MAX,dist[i][j]);
        }
    }

    return MAX;
}

int main(){
    cin >> H >> W;
    S.resize(H);
    for (int i = 0;i < H;i++) cin >> S[i];
    long long ans = 0;

    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            if (S[i][j] == '.') ans = max(ans,bfs(i,j));
        }
    }

    cout << ans << endl;
}

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

#define INF (1e9)
#define INF_LL (1e17)
#define YJ 1145141919810
#define mod 1000000007

using LL = long long;
using ULL = unsigned long long;

using namespace std;

#define MAX_N 300005
int N;
LL A[MAX_N];

int main()
{
  cin >> N;
  N *= 3;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A, A+N);

  LL ans = 0;
  for (int i = 0; i < N/3; i++) {
    ans += A[N-1-1 -(2*i)];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
from bisect import bisect_left
from itertools import accumulate

n, m = map(int, input().split())
hands = [int(x) for x in input().split()]
increasing = sorted(hands)
hands = list(reversed(increasing))
xs = [0] + list(accumulate(hands))

max_x = 2 * 10**5 + 1
min_x = 0


def canGet(x):
    count = 0
    for hand in increasing:
        idx = bisect_left(increasing, x-hand)
        count += n - idx
    return count >= m


while max_x - min_x > 1:
    # left
    mid = (max_x + min_x) // 2
    if canGet(mid):
        min_x = mid
    else:
        max_x = mid

ans = 0
count = 0

for Ai in hands:
    idx = bisect_left(increasing, min_x-Ai)
    ans += Ai*(n-idx) + xs[n-idx]
    count += n-idx
print(ans-(count-m)*min_x)


Measured memory_bytes: 15652
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>

using namespace std;

int main()
{
	int N,average=0,count=0;
	int a[10000];

	start:

	scanf("%d", &N);

	if (N == 0) {
		goto finish;
	}

	for (int i = 0; i < N; i++) {
		cin >> a[i];
		//scanf("%d", &a[i]);
	}

	for (int i = 0; i < N; i++) {
		average += a[i];
	}

	average /= N;

	for (int i = 0; i < N; i++) {
		if (a[i] <= average) {
			count++;
		}
	}

	cout << count<<endl;

	average = 0;
	count = 0;

	goto start;

	finish:

	return 0;
}


Measured memory_bytes: 3168
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=()
import itertools
c=list(itertools.permutations(range(1,n+1)))
cc=[]
for i in c:
    cc.append(list(i))
for x,i in enumerate(cc):
    if a==i:
        aa=x
    if b==i:
        bb=x
print(abs(aa-bb))

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



Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a1[n],a2[n];
    REP(i,n){
        ll x,y;
        cin>>x>>y;
        a1[i]=x+y;
        a2[i]=x-y;
    }
    sort(a1,a1+n);
    sort(a2,a2+n);
    cout<<max(a1[n-1]-a1[0],a2[n-1]-a2[0])<<endl;
}


Measured memory_bytes: 6752
#include<bits/stdc++.h>
using namespace std;
const int maxn=100007;
int inf=1e9;
vector<int>G[maxn];
int dp[maxn],fa[maxn],vis[maxn];
int flag=0;
struct node{
	int id;
	int dis;
	bool operator <(node b)const{
		if(dis!=b.dis) return dis>b.dis;
		else return id>b.id;
	}
};
void dijkstra(){
	fill(dp,dp+maxn,inf);
	priority_queue<node>q;
	vis[1]=1;
	q.push(node{1,0});
	while(!q.empty()){
		node cur=q.top();q.pop();
		if(dp[cur.id]<cur.dis) continue;
		for(auto i:G[cur.id]){
			if(dp[i]>cur.dis+1){
				fa[i]=cur.id;
				vis[i]=1;
				dp[i]=cur.dis+1;
				q.push(node{i,cur.dis+1});
			}
		}	
	}

}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dijkstra();
	for(int i=1;i<=n;i++) if(!vis[i]) flag=1;
	if(!flag) {
		printf("Yes\n");
		for(int i=2;i<=n;i++)printf("%d\n",fa[i]);		
	}
	else printf("No\n");
}

Measured memory_bytes: 11612
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  string ans="Alice";
  if(a==1) a=14; if(b==1) b=14;
  if(a==b) ans="Draw";
  else if(a<b) ans="Bob";
  cout << ans << 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++)

// int f(int n) {
//     int count = 0;
//     for (int x = 1; x <= 100; x++) {
//         for (int y = x; y <= 100; y++) {
//             for (int z = y; z <= 100; z++) {
//                 int p = x * x + y * y + z * z + x * y + y * z + z * x;
//                 if (p == n) {
//                     if (x == y && y == z) count += 1;
//                     else if (x == y && y != z) count += 3;
//                     else if (y == z && z != x) count += 3;
//                     else if (z == x && x != y) count += 3;
//                     else count += 6;
//                 }
//             }
//         }
//     }
//     return count;
// }

int main() {
    int n;
    cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     cout << f(i) << endl;
    // }
    vector<int> count(n);
    for (int x = 1; x <= 100; x++) {
        for (int y = x; y <= 100; y++) {
            for (int z = y; z <= 100; z++) {
                int p = x * x + y * y + z * z + x * y + y * z + z * x;
                if (p > n) break;
                else if (x == y && y == z) count[p-1] += 1;
                else if (x == y && y != z) count[p-1] += 3;
                else if (y == z && z != x) count[p-1] += 3;
                else if (z == x && x != y) count[p-1] += 3;
                else count[p-1] += 6;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << count[i] << endl;
    }
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数（ll）
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

//素因数分解？
vector<pair<ll, int>>factorize(ll n){
  vector<pair<ll, int>> res;
  for(ll i = 2; i * i <= n; ++i){
    if(n % i) continue;
    res.emplace_back(i, 0);
    while(n % i == 0){
      n /= i;
      res.back().second++;
    }
  }
if(n != 1) res.emplace_back(n, 1);
return res;

}



int main(){
  int N, P;
  cin >> N >> P;
  bool even = true;
  REP(i, N){
    int x;
    cin >> x;
    if(x % 2 != 0) even = false;
  }
ll ans;
if(even && P == 0) ans = pow(2, N);
else if(even && P == 1) ans = 0;
else ans = pow(2, N -1);

print(ans);
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long ll;

inline int read(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

const int mod=998244353;

inline int fpow(int x,int k){
	int res=1;
	for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) res=(ll)res*x%mod;
	return res;
}

const int N=(1<<18)+10;

int m,n,a[N],b[N],c[N];

void fwt(int *a,int op){
	for(int i=1;i<n;i<<=1){
		for(int j=0,len=i<<1;j<n;j+=len){
			for(int k=0;k<i;++k){
				int p=a[j+k],q=a[j+i+k];
				a[j+k]=(p+q)%mod; a[j+i+k]=(p+mod-q)%mod;
			}
		}
	}
	if(op==-1){
		int inv_n=fpow(n,mod-2);
		for(int i=0;i<n;++i) a[i]=(ll)a[i]*inv_n%mod;
	}
}

int main(){
	m=read(); n=1<<m; int sum=0;
	for(int i=0;i<n;++i) sum+=(a[i]=read());
	sum=fpow(sum,mod-2);
	for(int i=0;i<n;++i) a[i]=(ll)a[i]*sum%mod;
	a[0]=(a[0]+mod-1)%mod;
	fwt(a,1);
	b[0]=n-1; for(int i=1;i<n;++i) b[i]=mod-1;
	fwt(b,1);
	for(int i=1;i<n;++i) c[i]=(ll)b[i]*fpow(a[i],mod-2)%mod;
	fwt(c,-1);
	int tmp=c[0];
	for(int i=0;i<n;++i) c[i]=(c[i]+mod-tmp)%mod;
	for(int i=0;i<n;++i) printf("%d\n",c[i]);
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

const int MAXN = 300;
int h, w, sol[MAXN + 5][MAXN + 5], k;
string s[MAXN + 5];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> h >> w >> k;
for(int i = 0 ; i < h ; ++i){
	cin >> s[i];
}
int br = 0;
for(int i = 0 ; i < h ; ++i){
	int last = 0;
	for(int j = 0 ; j < w ; ++j){
		if(s[i][j] == '#'){
			br++;
			for(int v = last ; v <= j ; ++v){
				sol[i][v] = br;
			}
			last = j + 1;
		}
	}
	if(!last){
		if(!i)
			continue;
		for(int j = 0 ; j < w ; ++j){
			sol[i][j] = sol[i - 1][j];
		}
	}
	else{
		for(int j = last ; j < w ; ++j){
			sol[i][j] = br;
		}
	}
}
for(int i = h - 2 ; i >= 0 ; --i){
	if(sol[i][0])
		continue;
	for(int j = 0 ; j < w ; ++j){
		sol[i][j] = sol[i + 1][j];
	}
}
for(int i = 0 ; i < h ; ++i){
	for(int j = 0 ; j < w ; ++j){
		cout << sol[i][j] << ' ';
	}
	cout << endl;
}

return 0;
}



Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[10],ans[10],vis1[10];
int a[100],b[100],k=0;
char mp[10][10];
struct note
{
    int x,y;
} l[1000];
int check(int x,int y)
{
    for(int i=0; i<k; i++)
    {
        if(l[i].x==x||l[i].y==y||abs(x-l[i].x)==abs(y-l[i].y))
            return 0;
    }
    return 1;
}
void pri()
{
    for(int i=0; i<9; i++)
    {
        for(int j=0; j<9; j++)
            mp[i][j]='.';
    }
    for(int i=0; i<k; i++)
        mp[l[i].x][l[i].y]='Q';
    for(int i=1; i<9; i++)
    {
        for(int j=1; j<9; j++)
            printf("%c",mp[i][j]);
        printf("\n");
    }
}
void dfs(int x)
{
    if(x>8)
    {
        pri();
        return;
    }
    else if(vis[x]==0)
    {
        for(int j=1; j<=8; j++)
        {
            if(vis1[j]==0&&check(x,j))
            {
                l[k].x=x;
                l[k++].y=j;
                vis1[j]=1;
                dfs(x+1);
                vis1[j]=0;
                k--;
            }
        }
    }
    else
        dfs(x+1);
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(vis,0,sizeof(vis));
        memset(vis1,0,sizeof(vis1));
        k=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            vis[a[i]+1]=1;
            vis1[b[i]+1]=1;
            l[k].x=a[i]+1;
            l[k++].y=b[i]+1;
        }
        dfs(1);
    }
    return 0;
}



Measured memory_bytes: 2704
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;

    for(int i=0; i<dx; i++) {
        cout << 'R';
    }
    for(int i=0; i<=dy; i++) {
        cout << 'U';
    }
    for(int i=0; i<=dx; i++) {
        cout << 'L';
    }
    for(int i=0; i<=dy; i++) {
        cout << 'D';
    }
    cout << 'R';

    for(int i=0; i<dy; i++) {
        cout << 'U';
    }
    for(int i=0; i<=dx; i++) {
        cout << 'R';
    }
    for(int i=0; i<=dy; i++) {
        cout << 'D';
    }
    for(int i=0; i<=dx; i++) {
        cout << 'L';
    }
    cout << 'U' << endl;
    return 0;
}


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

string cname[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
int crgb[8][3] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},{255,0,255},{255,255,0},{255,255,255}};
int hconvert(char a){
	if('0' <= a && a <= '9'){
		return (a - '0');
	}
	else{
		return (a - 'a' + 10);
	}
}
int main(){
	string str;
	int u,l,rgb[3],now,min,tmp;
	while(cin >> str){
		if(str == "0") break;
		min = 10000000;
		for(int i = 1;i < str.size();i+=2){
			u = hconvert(str[i]);
			l = hconvert(str[i+1]);
			rgb[(i / 2)] = u * 16 + l;
		}
		for(int i = 0;i < 8;++i){
			tmp = 0;
			for(int j = 0;j < 3;++j){
				tmp += (rgb[j] - crgb[i][j]) * (rgb[j] - crgb[i][j]);
			}
			if(tmp < min){
				min = tmp;
				now = i;
			}
		}
		cout << cname[now] << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  int x=stoi(a+b);
  for(int i=0;i<=1000;i++){
    if(i*i == x){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int q;
    cin >> q;
    int a[q] = {0}; 
    int b[q] = {0};
    vector<int> v, l;

    for(int i = 0; i < q; i++)
    {
        cin >> a[i];
        if(a[i] == 0)
        {
            cin >> b[i];
            v.push_back(b[i]);
        }
        else if(a[i] == 1)
        {
            int num;
            cin >> num;
            l.push_back(v[num]);
        }
        else if(a[i] == 2)
        {
            v.pop_back();
        }
    }

    for(auto ll : l)
    {
        cout << ll << endl;
    }

    return 0;


}


Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef pair<ll, ll> pll;
#define fi first
#define se second
#define pb push_back
#define ppb pop_back

int main() {
  ll h,w,k;
  char c[10][10];
  cin >> h >> w >> k;
  for (ll i=0;i<h;++i) {
    for (ll j=0;j<w;++j) {
      cin >> c[i][j];
    }
  }
  ll n = 1<<h;
  ll m = 1<<w;
  ll ans = 0;
  for (ll i=0;i<n;++i) {
    for (ll j=0;j<m;++j) {
      ll cur = 0;
      for (ll x=0;x<h;++x) {
        for (ll y=0;y<w;++y) {
          if ((((1<<x)&i)==0) && (((1<<y)&j)==0) && c[x][y]=='#') {
            ++cur;
          }
        }
      }
      if (cur==k) {
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    if(A>=K){
        cout<<K<<endl;
    }
    else{
        if(A+B>=K){
            cout<<A<<endl;
        }
        else{
            cout<<2*A+B-K<<endl;
        }
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){

	int n;
	cin >> n;
	long long sum = 0;
	for(int i = 1; i <= n; i++)
	{
		if(i%3 != 0 && i%5!=0)
			sum += i;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, A;
	cin >> N >> A;

	vector<Int> x(N);
	for (Int i = 0; i < N; i++) {
		cin>>x[i];
	}

	vector<vector<vector<Int>>> dp(N + 1, vector<vector<Int>>(N + 1, vector<Int>(3000)));
	dp[0][0][0] = 1;

	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < N; j++) {
			for (Int k = 0; k < 3000; k++) {
				//選ばない
				dp[i + 1][j][k] += dp[i][j][k];
				//選ぶ
				if (k - x[i] >= 0) {
					dp[i + 1][j + 1][k] += dp[i][j][k - x[i]];
				}
			}
		}
	}

	Int ans = 0;
	for (Int j = 1; j <= N; j++) {
		ans += dp[N][j][A * j];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 62592
#include<iostream>
using namespace std;
int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k<=a){
    cout << k << endl;
  }
  else if(k<=a+b){
    cout << a << endl;
  }
  else{
    cout << a-(k-a-b) << endl;
  }
}


Measured memory_bytes: 3632
#include<cstdio>
#include<string>
#include<map>
#include<utility>
#include<queue>
using namespace std;
typedef struct pair<string,int> p;
queue<p>Q;
map<string,int>P;
int pos;

void setP(string S,int c,int mv)
{
	swap(S[pos],S[pos+mv]);
	if(P.find(S)==P.end())
	{
		P[S]=c;
		Q.push(make_pair(S,c));
	}
}

int main()
{
	string S="01234567";
	P.insert(map<string,int>::value_type(S,0));
	Q.push(make_pair(S,0));
	while(!Q.empty())
	{
		p tmp=Q.front();Q.pop();
		pos=tmp.first.find('0');
		if(pos<4)
			setP(tmp.first,tmp.second+1,4);
		if(pos>3)
			setP(tmp.first,tmp.second+1,-4);
		if(pos%4!=0)
			setP(tmp.first,tmp.second+1,-1);
		if(pos%4!=3)
			setP(tmp.first,tmp.second+1,1);
	}
	char c[20];
	for(;gets(c);)
	{
		string a;
		for(int i=0;i<15;i+=2)a+=c[i];
		printf("%d\n",P[a]);
	}
}

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

int main() {
  int d, n;
  cin >> d >> n;
  int ans;
  if (d == 0) ans = n;
  if (d == 1) ans = n * 100;
  if (d == 2) ans = n * 10000;
  if (n == 100) {
    if (d == 0) ans += 1;
    if (d == 1) ans += 100;
    if (d == 2) ans += 10000;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256