akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();

        int i = 6;
        List<Integer> primes = new ArrayList<>();
        while(primes.size() < 55) {
            if (isPrime(i)) {
                primes.add(i);
            }
            i += 5;
        }

        StringBuilder sb = new StringBuilder();
        for (int l = 0; l < N; l++) {
            sb.append(primes.get(l));
            sb.append(" ");
        }
        System.out.println(sb.toString().trim());
    }

    private boolean isPrime(int n) {
        for(int i = 2; i < n; i++) {
            if(n % i == 0) {
                return false;
            }
        }
        return true;
    }


    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21204
import queue

INF = 123456789

def main():
    n,m = map(int,input().split())

    G = [[] for _ in range(n)]
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append((b,c))
        G[b].append((a,c))

    used = set()
    for i in range(n):
        d = [INF for _ in range(n)]
        par = [-1 for _ in range(n)]

        # dijkstra
        que = queue.PriorityQueue()
        d[i] = 0
        que.put((0,i))
        while not que.empty():
            p = que.get()
            v = p[1]
            if d[v] < p[0]:
                continue
            for (to,cost) in G[v]:
                if d[to] > d[v]+cost:
                    d[to] = d[v]+cost
                    par[to] = v
                    que.put((d[to],to))

        for j in range(n):
            if i != j:
                a,b = j,par[j]
                if a>b:
                    a,b = b,a
                used.add((a,b))

    print(m - len(used))

if __name__ == '__main__':
    main()


Measured memory_bytes: 62548
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
vector<int>a[MAXN];
int n,t;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n*2;i++) if (i*(i-1)/2==n) {
		t=i; break;
	}
	else if (i*(i-1)/2>n) {
		printf("%s\n","No"); return 0;
	}
	printf("%s\n","Yes");
	a[1].push_back(1); a[2].push_back(1);
	for (int i=3;i<=t;i++) {
		int s=(i-1)*(i-2)/2;
		for (int j=s+1;j<=s+i-1;j++) {
			a[i].push_back(j); a[j-s].push_back(j);
		}
	}
	printf("%d\n",t);
	for (int i=1;i<=t;i++) {
		int len=a[i].size();
		printf("%d ",len);
		for (int j=0;j<len;j++)
		 printf("%d ",a[i][j]);
		printf("\n"); 
	}
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	vector<char> bil1;
	vector<char>bil2;
	char op;
	bool cek = false;

	for(int i=0; i<s.size(); i++){
		if(s[i] == '+' || s[i] == '-' || s[i] == '/' || s[i] == '*')
		{
			op = s[i];
			cek = true;
		} else if(cek){
			bil2.push_back(s[i]);
		} else
			bil1.push_back(s[i]);

	}

	int tbil1 = bil1[0]-'0';
	for(int i=1; i<bil1.size(); i++){
		tbil1 *= 10 + ((bil1[i] - '0') % 10);
	}

	int tbil2 = bil2[0]-'0';
	for(int i=1; i<bil2.size(); i++){
		tbil2 *= 10 + ((bil2[i] - '0') % 10);
	}

	int ans = 0;
	string jawab;
	if(op == '+'){
		ans = tbil1 + tbil2;
		if(ans * 2 == 0){
			jawab = "genap";
		}
	}
	else if(op == '-')
	{
		ans = tbil1 - tbil2;
		if(ans * 2 == 0){
			jawab = "genap";
		}
	}
	else if(op == '*')
	{
		ans = tbil1 * tbil2;
		if(ans * 2 == 0){
			jawab = "genap";
		}
	}
	else if(op == '/'){
		if(tbil1 % tbil2 == 0)
			jawab = "genap";
		else
			jawab = "ganjil";
	}


	cout << jawab << endl;




	return 0;
}
*/


#include<bits/stdc++.h>

using namespace std;

const unsigned int M = 1e9 + 7;

int main(){

	int ans = 0;
	int j = 1;
	int n;
	cin >> n;
	int arr[n];
	for(int i=0; i<n; i++)
		cin >> arr[i];

	for(int i=0; i<n; i++){
		if(arr[i] == j){
			j++;
		} else {
			ans++;
		}


	}

	if(j == 1){
		cout << "-1\n";
	} else {
		cout << ans << endl;
	}



    return 0;
}


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

using namespace std;

const int N = 1234567;

#define next NEXT
#define prev PREV

int next[N], prev[N];
int at_least[N];

int main() {
  string a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  if (b.find("1") == string::npos) {
    cout << -1 << endl;
    return 0;
  }
  int n = a.length();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (b[(i + j) % n] == '1') {
        next[i] = j;
        break;
      }
    }
    for (int j = 0; j < n; j++) {
      if (b[(i + n - j) % n] == '1') {
        prev[i] = -j;
        break;
      }
    }
  }
  int ans = (int) 1e9;
  for (int shift = -n; shift <= n; shift++) {
    for (int x = 0; x <= n; x++) {
      at_least[x] = 0;
    }
    int flips = 0;
    for (int i = 0; i < n; i++) {
      int j = (i + shift + n) % n;
      if (a[i] != b[j]) {
        flips++;
        int x = min(0, shift) - prev[i];
        int y = next[i] - max(0, shift);
        if (x > 0 && y > 0) {
          at_least[x - 1] = max(at_least[x - 1], y);
        }
      }
    }
    int y = 0;
    for (int x = n; x >= 0; x--) {
      y = max(y, at_least[x]);
      ans = min(ans, 2 * (x + y) + abs(shift) + flips);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int N;

int main()
{
  while(cin >> N, N){
    int res = 0;
    rrep(i, 1, N) rep(j, i) if(i*(i+1)/2 - j*(j+1)/2 == N) res += 1;
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > ab;

    for (int i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }

    sort(ab.begin(), ab.end());

    ll ans = 0;
    ll n_bought = 0;
    // int ab_idx = 0;
    for (int ab_idx = 0; ab_idx < n; ab_idx++){
        ll next_n_bought = n_bought + ab[ab_idx].second;
        if (next_n_bought < m){
            ans += ab[ab_idx].first * ab[ab_idx].second;
            n_bought += ab[ab_idx].second;
        // }else if (next_n_bought > m & n_bought < m) {
        }else{
            ans += ab[ab_idx].first * (m - n_bought);
            n_bought += m - n_bought;
            cout << ans << endl;
            return 0;
        }
    }
}




















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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define int long long

int x, res = 1;

signed main()
{
	IOS;
	cin >> x;
	for (int i = 2; i <= 1000; i++) {
		int j = i;
		while (j * i <= x) {
			j *= i;
			res = max(res, j);
		}
	}
	cout << res << endl;
	return 0;
}


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

int main() {

  long long N, A, B;
  cin >> N >> A >> B;

  long long answer = N / (A + B) * A;
  
  long long a = N % (A + B);

  answer += min(a, A);

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)

    def list(self):
        return self.__q

    def length(self):
        return len(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    N = Scanner.int()
    ans = 0
    for i in range(1, N + 1, 2):
        if len(Math.divisor(i)) == 8:
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    main()


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

int main() {
    int r,D,x2000;
    cin >> r >> D >> x2000;
    long long now = x2000;
    rep(i,10) {
        now = now*r-D;
        cout << now << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	k, _ := sc.NextInt()
	p, _ := sc.NextInts(n)
	sort.Ints(p)
	sum := 0
	for i := 0; i < k; i++ {
		sum += p[i]
	}
	fmt.Println(sum)
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}

// NextInts reads n integers from io stream.
func (sc *Scanner) NextInts(n int) (arr []int, e error) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		v, e := sc.NextInt()
		if e != nil {
			return nil, e
		}
		arr[i] = v
	}
	return arr, nil
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}

  sort(ret.begin(), ret.end());

	return ret;
}

int main(){
  ll n, m; cin >> n >> m;

  vector<ll> y = enum_div(m);

  ll ans = 1;
  for(auto x: y){
    if(m >= n*x) ans = x;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {

	double n, s[1000], atmp = 0.0, ave = 0.0;
	while (true){
		
		atmp = 0.0;
		ave = 0.0;

		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++){
			cin >> s[i];
			ave += s[i];
		}
		ave = ave / n;
		for (int i = 0; i < n; i++){
			atmp += pow(s[i] - ave, 2);
		}
		cout << setprecision(10) << sqrt(atmp / n) << endl;
	}

	return 0;
}


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

using namespace std;

static const int64_t MOD = 1000000007;

int64_t modpow(int64_t base, int64_t k, int64_t mod) {
  base %= mod;
  int64_t answer = 1;
  while (k > 0) {
    if (k & 1) answer = (answer * base) % mod;
    base = (base * base) % mod;
    k >>= 1;
  }
  return answer;
}

int main() {
  int64_t N, K;
  cin >> N >> K;

  vector<int64_t> counts(K + 1);

  int64_t answer = 0;
  for (int64_t gcd = K; gcd >= 1; gcd--) {
    int64_t multiples = K / gcd;
    int64_t count = modpow(multiples, N, MOD);
    for (int k = 2; gcd * k <= K; k++) {
      count = (count + MOD - counts[gcd * k]) % MOD;
    }
    counts[gcd] = count;
    answer = (answer + gcd * counts[gcd]) % MOD;
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 4052
public class Main {
	public static void main(String[] args) throws Exception {		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				System.out.print(i + "x");
				System.out.print(j + "=");
				System.out.println(i*j);
			}
		}

	}
}

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

int main (){
  long long n,m=1000,s=0;
  
  cin >> n;
  int a[n];
  for (int i=0;i<n;i++) cin >> a[i];
  for (int i=0;i<n-1;i++) {
    if (a[i]<a[i+1]) {
      long long t=m/a[i];
      s+=t;
      m-=t*a[i];
      //cout << "buy" << " ";
    }
    if (a[i]>a[i+1]) {
      m+=s*a[i];
      s=0;
      //cout << "sell" << " ";
    }
    //cout << s << " " << m << endl;
  }
  m+=s*a[n-1];
  s=0;
  cout << m << endl;
}


Measured memory_bytes: 3140
#include <stdio.h>
#include <climits>
#include <iostream>
using namespace std;
int main(){
  int n,work;
  while(1){
    int sum = 0,max=0,min=INT_MAX;
    cin >> n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin >> work;
      max = (max < work) ? work : max;
      min = (min > work) ? work : min;
      sum+=work;
    }
    sum -=max;
    sum -=min;
    printf("%d\n",sum/(n-2));
  }

  return 0;
}

Measured memory_bytes: 1144
n=int(input())
h=list(map(int,input().split()))
ct=0
ans=0
for i in range(n-1):
    if h[i]<h[i+1]:
        ans=max(ans,ct)
        ct=0
    else:
        ct+=1
if ans<ct:
    ans=ct
print(ans)

Measured memory_bytes: 14252
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int K = scan.nextInt();
        int[][] blacks = new int[H][W];
        for (int i = 0; i < H; i++) {
            char[] t = scan.next().toCharArray();
            for (int j = 0; j < W; j++) {
                if (t[j] == '#') {
                    blacks[i][j] = 1;
                }
            }
        }
        int max = pow(2, H + W);
        int ans = 0;
        for (int t = 0; t < max; t++) {
            int current = t;
            HashSet<Integer> selectedRow = new HashSet<>();
            HashSet<Integer> selectedColumn = new HashSet<>();
            for (int i = 0; i < H + W && 0 < current; i++) {
                if (current % 2 == 0) {
                    current /= 2;
                    continue;
                }
                if (i < H) {
                    selectedRow.add(i);
                    current /= 2;
                    continue;
                }
                selectedColumn.add(i - H);
                current /= 2;
            }
            int count = 0;
            for (int i = 0; i < H; i++) {
                if (selectedRow.contains(i)) {
                    continue;
                }
                for (int j = 0; j < W; j++) {
                    if (selectedColumn.contains(j)) {
                        continue;
                    }
                    count += blacks[i][j];
                }
            }
            if (count == K) {
                ans += 1;
            }
        }
        System.out.println(ans);
    }
    private int pow(int base, int count) {
        if (count == 0) {
            return 1;
        }
        if (count % 2 == 1) {
            return base * pow(base, count - 1);
        }
        int t = pow(base, count / 2);
        return t * t;
    }
}


Measured memory_bytes: 40456
#include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    double t5,t10;
	string ans;
	while(cin>>t5>>t10){
		if(t5<35.50&&t10<71.00){
			ans="AAA";
		}else if(t5<37.50&&t10<77.00){
			ans="AA";
		}else if(t5<40.00&&t10<83.00){
			ans="A";
		}else if(t5<43.00&&t10<89.00){
			ans="B";
		}else if(t5<50.00&&t10<105.00){
			ans="C";
		}else if(t5<55.00&&t10<116.00){
			ans="D";
		}else if(t5<70.00&&t10<148.00){
			ans="E";
		}else{
			ans="NA";
		}
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int b_s(vector<llint>& a, llint key) {
	int left = -1;
	int right = a.size();
	while (right - left > 1) {
		int mid = left + (right - left) / 2;
		if (a[mid] > key)right = mid;
		else left = mid;
	}
	return right;
}
int main() {
	int n;
	cin >> n;
	map<string, int> S;
	rep(i, 0, n) {
		string s;
		cin >> s;
		S[s]++;
	}
	cout << "AC" << " x " << S["AC"] << endl;
	cout << "WA x " << S["WA"] << endl;
	cout << "TLE x " << S["TLE"] << endl;
	cout << "RE x " << S["RE"] << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
vector<ll> v;

struct C
{
    ll x, y, h;
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vector<C> v;
    REP(i, N)
    {
        C D;
        cin >> D.x >> D.y >> D.h;
        v.push_back(D);
    }

    for (int i = 0; i <= 100; ++i)
    {
        for (int j = 0; j <= 100; ++j)
        {

            bool f = true;
            ll H;

            for (int k = 1; k < N; ++k)
            {
                if (v[k].h != 0)
                {
                    H = v[k].h + abs(v[k].x - i) + abs(v[k].y - j);
                }
            }

            for (int k = 0; k < N; ++k)
            {
                if (v[k].h != 0)
                {
                    if (H != v[k].h + abs(v[k].x - i) + abs(v[k].y - j))
                        f = false;
                }
                else
                {
                    if (H - abs(v[k].x - i) - abs(v[k].y - j) > 0)
                        f = false;
                }
            }
            if (f)
            {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	static Scanner scanner = new Scanner(System.in);
 
	public static void main(String[]$) {
		int a = scanner.nextInt() - 1;
		int b = scanner.nextInt() - 1;
		char[][] grid = new char[98][99];
		for (int i = 0; i < 98; i++) {
			if (i < 49) {
				Arrays.fill(grid[i], '#');
			} else {
				Arrays.fill(grid[i], '.');
			}
		}
		for (int i = 0; i < a; i++) {
			grid[i / 49 * 2 + 1][i % 49 * 2 + 1] = '.';
		}
		for (int i = 0; i < b; i++) {
			grid[i / 49 * 2 + 50][i % 49 * 2 + 1] = '#';
		}
		System.out.println("98 99");
		Arrays.stream(grid).map(String::valueOf).forEach(System.out::println);
	}
}

Measured memory_bytes: 29140
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(auto &i:a) cin >> i;
  int ans = 0;
  bool flag = false;
  sort(a.begin(),a.end());
  for(int i=2;i<=a[n-1];i*=2){
    for(auto &t:a) if(t%i!=0) flag = true;
    if(!(flag)) ans++;
    else break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n;
	string s,t;
	cin>>n>>s>>t;
	for(ll i=0;i<2*n;i++)
	{
		if(i%2==0)
		cout<<s[i/2];
		else
		cout<<t[i/2];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000003LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll fact[3000005];

ll mod_pow(ll xi,ll ni){
	ll ans=1;
	while(ni>0){
		if(ni&1LL)ans=ans*xi%MOD;
		xi=xi*xi%MOD;
		ni>>=1LL;
	}
	return ans;
}

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll& e){
	e=0;
	if(n==0)return 1;
	ll res=mod_fact(n/p,p,e);
	e+=n/p;
	if(n/p%2!=0){
		return res*(p-fact[n%p])%p;
	}
	return res*fact[n%p]%p;
}

ll mod_comb(ll n,ll k,ll p){
	if(n<0 || k<0 || n<k)return 0;
	ll e1,e2,e3;
	ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
	if(e1>e2+e3)return 0;
	return a1*mod_inverse(a2*a3%p,p)%p;
}

int q;
ll val[1000005];

ll solve(ll x,ll d,ll n){
	ll dn=mod_pow(d,n);
	ll xd=x*mod_inverse(d,MOD)%MOD;
	if(xd+n-1>=MOD){
		return 0;
	}else{
		ll ans=fact[xd+n-1]*mod_inverse(fact[xd-1],MOD)%MOD;
		ans=ans*dn%MOD;
		return ans;
	}
	
}

int main(void){
	fact[0]=1;
	for(ll i=1;i<=MOD*2;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		ll x,d,n;
		scanf("%lld%lld%lld",&x,&d,&n);
		if(d==0LL){
			printf("%lld\n",mod_pow(x,n));
		}else if(n>=MOD){
			printf("%lld\n",0LL);
		}else{
			printf("%lld\n",solve(x,d,n));
		}
	}
	return 0;
}


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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int const N = 200 * 1010;

/********************i**********************************/
void solve(){
	int n;
	cin >> n;
	vector<int> dp(3, 0);
	for(int x = 0; x<3; x++)cin >> dp[x];
	for(int x = 1; x<n; x++){
		int a, b, c;
		cin >> a >> b >> c;
		vector<int>d = dp;
		d[0] = max(dp[1], dp[2]) + a;
		d[1] = max(dp[0], dp[2]) + b;
		d[2] = max(dp[1], dp[0]) + c;
		swap(dp, d);
	}
	cout << max(dp[0], max(dp[1], dp[2]));
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<cctype>
#include<cmath>
#include<cstdio>

using namespace std;
int main(){

int a;
cin >> a;

char b[52];
int c[52];

int d[4][14];

for(int i=0;i<4;i++){
	for(int j=0;j<14;j++){
	d[i][j]=0;
	}
}

for(int i=0;i<a;i++){
	cin >> b[i] >> c[i];
	int n=c[i];
	if(b[i]=='S') d[0][c[i]]=1; 
	else if(b[i]=='H') d[1][n]=1;
	else if(b[i]=='C') d[2][n]=1;
	else d[3][n]=1;
}

for(int i=0;i<4;i++){
	for(int j=1;j<14;j++){
		if(d[i][j]==0){
			char ch;
			if(i == 0) ch = 'S';
                if(i == 1) ch = 'H';
                if(i == 2) ch = 'C';
                if(i == 3) ch = 'D';
                printf("%c %d\n", ch, j);
			}
	}
}

return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,x;
  cin>>N>>x;
  if(N==2){
    if(x==2){
      cout<<"Yes"<<endl;
      cout<<1<<endl;
      cout<<2<<endl;
      cout<<3<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
  }
  if(1<x&&x<2*N-1){
    cout<<"Yes"<<endl;
    vector<int>ans(2*N-1,0);
    ans[N-3]=x-1;
    ans[N-2]=x;
    ans[N-1]=x+1;
    ans[N]=x-2;
    if(x==2){
      ans[N-3]=x+1;
      ans[N-2]=x;
      ans[N-1]=x-1;
      ans[N]=x+2;
    }
    int j=0;
    for(int i=1;i<=2*N-1;i++){
      if(x==2){
        if(x-1<=i&&i<=x+2)continue;
      }
      else{
        if(x-2<=i&&i<=x+1)continue;
      }

      while(ans[j]!=0)j++;
      ans[j]=i;
    }
    for(auto it:ans)cout<<it<<endl;
  }
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <numeric>
#include <climits>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm> 
#include <map> 
#include <set>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; }
template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; }
template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; }
template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; }


int h,w,c;

int panel[8][8];
int c_panel[8][8];
int ans;

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


void c_dfs(int y,int x,int p_c,int c_c){
	if(x < 0 || x >= w || y < 0 || y >= h) return;
	if(c_panel[y][x]!=p_c) return;

	//cout << x << "," << y << endl;

	c_panel[y][x] = c_c;
	ans++;

	rep(i,4){
		c_dfs(y+dy[i],x+dx[i],p_c,c_c);	
	}
}

void init(){
	rep(i,h) rep(j,w) c_panel[i][j] = panel[i][j];
	ans=0;
}

void print(){
	
	cout << "--------------" << endl;
	rep(i,h){
		rep(j,w){
			cout << c_panel[i][j];
		}
		cout << endl;
	}
	cout << "--------------" << endl;
}

int main(){
	while(1){
		cin >> h >> w >> c;	
		if(h==0&&w==0&&c==0) break;
		fill_n((int *)panel,sizeof(panel)/sizeof(int),-1);	
		fill_n((int *)c_panel,sizeof(c_panel)/sizeof(int),-1);		
	
		rep(i,h){
			rep(j,w){
				cin >> panel[i][j];
			}
		}
		
		int output=0;
		rep(i,6) rep(j,6) rep(k,6) rep(l,6){
			init();
			if(c_panel[0][0]==i+1) continue;
			c_dfs(0,0,c_panel[0][0],i+1);
			if(c_panel[0][0]==j+1) continue;
			c_dfs(0,0,c_panel[0][0],j+1);
			if(c_panel[0][0]==k+1) continue;
			c_dfs(0,0,c_panel[0][0],k+1);
			if(c_panel[0][0]==l+1) continue;
			c_dfs(0,0,c_panel[0][0],l+1);
			if(c_panel[0][0]==c) continue;
			c_dfs(0,0,c_panel[0][0],c);	
			ans=0;
			c_dfs(0,0,c_panel[0][0],8);
			output = max(output,ans);
		}


		cout << output << endl;
	}
}

Measured memory_bytes: 1164
import sys
input = sys.stdin.readline
import math

N = int(input())

if N == 2:
    print(0)
    exit()

m = int(math.sqrt(N))+1

s, a = divmod(N,m)

sum_of_m = 0
for i in range(s, 0, -1):
    m = N/i - 1
    if m > 0 and m.is_integer() and divmod(N, m) == (i, i):
        sum_of_m += int(m)

print(sum_of_m)


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define RSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))
#define PREC(n) setprecision(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    string s;
    ll n,i;

    cin>>n>>s;

    if(n%2==0){
        rep(i,n/2){
            if(s[i]!=s[n/2+i]){
                No;
                return 0;
            }
        }
        Yes;
    }
    else{
        No;
    }
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
#include<math.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int a, b, c;

signed main(){
    cin >> a >> b >> c;
    if(a == b && b == c)printf("Yes\n");
    else printf("No\n");


    return 0;
}

/*

*/

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

    string s;
    cin >> s;
    int l = s.size();
    int ans=0;
    rep(i,l/2){
        if(s[i]!=s[l-1-i]) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define FST first
#define SND second

#define MAX_N   (100000)                  // 10^5
// #define MAX_N   (1000000000)              // 10^9
// #define MAX_N   (1000000000000000000)     // 10^18
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

ll N, A, B, C;
ll H[MAX_N], H2[MAX_N];

bool check(ll k) {
  for (int i = 0; i < N; i++) {
    H2[i] = max(0LL, H[i] - k * B);
  }
  ll x = 0;
  for (int i = 0; i < N; i++) {
    x += (H2[i] + C - 1) / C;
  }
  return x <= k;
}

void solve() {
  sort(H, H + N);

  ll kl = -1, kr = INFI;
  while (kr - kl > 1) {
    ll km = (kl + kr) / 2;
    if (check(km)) {
      kr = km;
    } else {
      kl = km;
    }
  }

  cout << kr << endl;
}

int main() {
  cin >> N >> A >> B;
  C = A - B;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  solve();

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint a) const {mint res(*this); return res+=a;}
    mint operator-(const mint a) const {mint res(*this); return res-=a;}
    mint operator*(const mint a) const {mint res(*this); return res*=a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int main() {
	int n, m;
	cin >> n >> m;
	int a[N];
	rep(i, m) cin >> a[i];

	mint dp[N + 1];
	dp[0].x = 1;
	int a_idx = 0;
	for(int i = 1; i <= n; i++) {
		dp[i] += dp[i - 1];
		if(i >= 2) dp[i] += dp[i - 2];
		if(a_idx < m && i == a[a_idx]) {
			dp[i].x = 0;
			a_idx++;
		}
	}
	cout << dp[n].x << endl;
}


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

int main(){
    long n;
    string s;
    cin >> n >> s;
    long r=0,g=0,b=0;
    rep(i,n){
        if(s.at(i)=='R')r++;
        if(s.at(i)=='G')g++;
        if(s.at(i)=='B')b++;
    }

    long ans = r*g*b;
    //find duplicates
    rep(i,n){
        for(long j=i+1;j<n;j++){
            long k = 2*j-i;
            if(k<n && s.at(i) != s.at(j) && s.at(i) != s.at(k) && s.at(j) != s.at(k))ans--;
        }
    }
    if(ans < 0) ans =0;
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<bitset>
using namespace std;

const int N=1005;
const int M=5005;

struct E{
	int to,next;
}mem[N<<1];
int n,num,x,inf;
bool tag;
int head[N],a[N],f[2][M],dp[N];

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

void dfs(int k){
	int w,b,j,u,now,last,i,mn=inf;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		dfs(u);
	}
	now=0; last=1;
	memset(f,0x3f,sizeof(f)); f[0][0]=0;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		now^=1; last^=1;
		memset(f[now],0x3f,sizeof(f[now]));
		w=dp[u]; b=a[u];
		for (i=0;i<=a[k];i++){
			if (i+w<=a[k]) f[now][i+w]=min(f[now][i+w],f[last][i]+b);
			if (i+b<=a[k]) f[now][i+b]=min(f[now][i+b],f[last][i]+w);
		}
	}
	for (i=0;i<=a[k];i++) mn=min(mn,f[now][i]);
	if (mn==inf) tag=0;
	dp[k]=mn;
}

int main(){
	int i;
	scanf("%d",&n); tag=1;
	for (i=2;i<=n;i++){
		scanf("%d",&x);
		add(x,i);
	}
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	memset(f,0x3f,sizeof(f)); inf=f[0][0];
	dfs(1);
	if (tag) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 384
H,W = map(int,input().split())
grid = [input().split() for _ in range(H)]
check = []

for i in range(H):
    if '#' not in grid[i][0]:
        check.append(i-len(check))
for i in check:
    grid = grid[:i] + grid[i+1:]
check = []

for i in range(W):
    if all(grid[j][0][i]=='.' for j in range(len(grid))):
        check.append(i - len(check))
for i in check:
    for k in range(len(grid)):
        grid[k][0] = grid[k][0][:i] + grid[k][0][i+1:]
        
for i in grid:
    print(i[0])

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

int a[2010];
int zen[2010];
int po[2010];

int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}
    
signed main(){
  int n,k;
  cin>>n>>k;
  rep(i,n)cin>>a[i];
  rep(i,n){
    rep(j,n){
      if(a[j]<a[i])zen[i]++;
    }
  }
  rep(i,n){
    for(int j=i+1;j<n;j++){
      if(a[j]<a[i])po[i]++;
    }
  }
  int ans=0;
  rep(i,n){
    int m=prod(zen[i],(k*(k-1)/2)%MOD);
    ans=add(ans,add(prod(po[i],k),m));
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int eaten;
  
  if (a+b >= c){
    eaten = b+c;
  }
  else {
    if (c<b){
      eaten = 2*c+1;
    }
    else {
      eaten = 2*b+a+1;
    }
  }
  
 cout << eaten << endl;
}

Measured memory_bytes: 256
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define Jehian using
#define Norman namespace
#define Saviero std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

Jehian Norman Saviero;

/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n")
#define sp printf(" ")

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y
#define SQR(x) (x)*(x)
#define CUBE(x) SQR(x)*(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main(){
	ll N, TOT;
	cin >> N >> TOT;
	for (ll i = 0; i <= 2000; ++i){
		for (ll j = 0; j <= 2000; ++j){
			ll k = N-i-j;
			if (k >= 0){
				if (i*10000LL + j*5000LL + k*1000LL == TOT){
					cout << i << " " << j << " " << k << endl;
					return 0;
				}
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
  int A,B,C;
  cin >>A >>B;
  C=A-2*B;
  if(C>0){
    cout << C << endl;
  }
  else{
    cout<<"0"<<endl;
  }
  return(0);
 
  
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  int v;
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

  for ( i = 1; i <= n; i++ ){
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    trace(A, n);
  }
  return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;

    rep(t, N) {
        ll n = t + 1;
        ll ans = 0;
        for (ll x = 1; x * x <= n; x++) {
            for (ll y = 1; y * y <= n; y++) {
                ll c = x * x + y * y + x * y - n;
                ll b = x + y;
                if (b * b - 4 * c < 0) continue;
                double q = sqrt(b * b - 4 * c);
                if ((ll)(q + 0.00005) * (ll)(q + 0.00005) == b * b - 4 * c) {
                    ll z = -b + (ll)(q + 0.5);
                    if (z % 2 == 0 && z >= 1) {
                        ans++;
                    }

                }
                
                
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3668
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<stdint.h>
#include<memory.h>
#include<deque>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<bitset>
int main(){
    int n,p=0,k=0,g;
    scanf("%d",&n);
    g=n;n=0;
    while((360-n)%g!=0){
        p=((360-n)/g+1)*g;
        k+=((360-n)/g+1);n=p%(360-n);
       
    }
    k+=((360-n)/g);
    printf("%d\n",k);
}


Measured memory_bytes: 1728