akhauriyash/Code-Regression huggingface dataset:
#初期値の挿入
list_nml = list(map(int, input().split()))
list_nm = list()
list_ml = list()
result_nl = [[0]*list_nml[2] for n in range(list_nml[0])]

#インプットdataの格納
for n in range(list_nml[0]):
    list_nm.append(list(map(int, input().split())))
for m in range(list_nml[1]):
    list_ml.append(list(map(int, input().split())))

#計算
for n in range(list_nml[0]):
    for l in range(list_nml[2]):
        result_temp = 0
        for m in range(list_nml[1]):
            result_temp += list_nm[n][m] * list_ml[m][l]
        result_nl[n][l] = result_temp

#計算結果の表示
for a in result_nl:
    print(*a)



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

bool hantei(string S){
    bool h = 1;
    if(S.size()%2==1){
        return 0;
    }
    REP(i,S.size()/2){
        if(S[i]!=S[i+S.size()/2]){
            h = 0;
        }
    }
    return h;
}

int main() {
    string S;
    cin >> S;
    REP(i,S.size()){
        if(hantei(S.substr(0,S.size()-i-1))){
            cout << (S.substr(0,S.size()-i-1)).size() << endl;
            exit(0);
        }
    }
    return 0;
}


Measured memory_bytes: 256
// 2011/01/17 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	while(!cin.eof()){
		string str;
		getline(cin, str);
		if(str.empty())
			continue;

		istringstream ist(str);
		double tim500, tim1000;
		ist >> tim500 >> tim1000;

		if(tim500<35.50 && tim1000<71.00)
			cout << "AAA" << endl;
		else if(tim500<37.50 && tim1000<77.00)
			cout << "AA" << endl;
		else if(tim500<40.00 && tim1000<83.00)
			cout << "A" << endl;
		else if(tim500<43.00 && tim1000<89.00)
			cout << "B" << endl;
		else if(tim500<50.00 && tim1000<105.00)
			cout << "C" << endl;
		else if(tim500<55.00 && tim1000<116.00)
			cout << "D" << endl;
		else if(tim500<70.00 && tim1000<148.00)
			cout << "E" << endl;
		else
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9){
        cout << -1;
    }
    else
    {
        cout << a*b;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m,x;cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m,0));
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++) cin>>a[i][j];
  }
  int minc=1e9;
  for(int i=0;i<(2<<n);i++){
    vector<int> s(m,0);
    int tc=0;
    for(int j=0;j<n;j++){
      if((i>>j)&1){
        for(int k=0;k<m;k++){ s[k]+=a[j][k]; }
        tc+=c[j];
      }
    }
    bool f=true;
    for(int k=0;k<m;k++){ if(s[k]<x){ f=false; break; } }
    if(f){
      if(minc>tc){ minc=tc; }
    }
  }
  if(minc==1e9) cout<<-1<<endl;
  else cout<<minc<<endl;

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>
#include <complex>
using namespace std;

int main()
{
	int n, seq = 1;
	while (cin >> n) {
		if (n == 0)
			break;

		vector<complex<double> > p(n+1);
		for (int i = 0; i < n; ++i)
			cin >> p[i].real() >> p[i].imag();
		// rev
		p[n].real() = p[0].real();
		p[n].imag() = p[0].imag();

		double ans = 0.0;
		for (int i = 0; i < n; ++i)
			ans += (p[i].real() * p[i+1].imag() - p[i].imag() * p[i+1].real());

		printf("%d %.1f\n",seq++, abs(ans)/2.0);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void){

	int H, W;
	cin >> H >> W;

	vec cnt(26, 0), ms(3, 0);;

	rep(H, i) rep(W, j)
	{
		char c;
		cin >> c;
		cnt[c-'a']++;
	}

	rep(26, i)
	{
		if (cnt[i] & 1)
		{
			ms[2]++;
			cnt[i]--;
		}
		if (cnt[i] % 4 == 0)
		{
			ms[0] += cnt[i] / 4;
		}
		else
		{
			ms[1]++;
			ms[0] += (cnt[i]-2) / 4;
		}
	}

	//cout << ms << endl;

	int f = 1;

	f &= ms[0] >= (H / 2) * (W / 2);
	ms[1] += (ms[0] - (H / 2) * (W / 2)) * 2;
	f &= ms[1] == (H & 1) * W / 2 + (W & 1) * H / 2;
	f &= ms[2] == (H & 1) * (W & 1);

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


}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $Q);

while ($Q--) {
  fscanf(STDIN, "%d", $R);

  $found = array();
  $count = 0;
  
  while ($R > 9) {
    if (isset($found[$R])) {
      $count = -1;
      break;
    }
    $found[$R] = 1;
    $tmp = 0;
    $r = (string)$R;
    for ($i = 1; $i < strlen($r); $i++) {
      $tmp = max($tmp, (int)substr($r, 0, $i) * (int)substr($r, $i));
    }
    $R = $tmp;
    $count++;
  }

  print $count . "\n";
}

Measured memory_bytes: 6600
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;

int N, A, B, C;

int main() {
	cin >> C >> A >> B;

	string ans;
	if (A == B and B == C) {
		ans = "Yes";
	}
	else {
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}

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



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a, b,k;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++) {
		if(i%k==0) {
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, M, s[6], c[6];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) scanf("%d %d", &(s[i]), &(c[i]));
	
	int digit[4] = {-1, -1, -1, -1};
	for (i = 1; i <= M; i++) {
		if (digit[s[i]] == -1) digit[s[i]] = c[i];
		else if (digit[s[i]] != c[i]) break;
	}
	if (i <= M) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	
	int ans = 0, tmp;
	for (i = 1, tmp = 1; i <= N; i++, tmp *= 10) {
		if (digit[N-i+1] != -1) ans += digit[N-i+1] * tmp;
	}
	if (ans == 0 && N == 1) printf("0\n");
	else if (ans >= tmp / 10) printf("%d\n", ans);
	else if (digit[1] == -1) printf("%d\n", ans + tmp / 10);
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t,h,w,n;
  cin>>t;
  for(int i=0;i<t;++i){
    char s[22][22],com[100];
    int z,x,y; //z 0:up 1:down 2:left 3:right
    cin>>h>>w;
    for(int j=0;j<=h+1;++j){
      for(int k=0;k<=w+1;++k){
	if(j==0||k==0||j==h+1||k==w+1) {
	  s[j][k]='A';
	}else{
	  cin>>s[j][k];
	  if(s[j][k]=='^'){ z=0; x=k; y=j;}
	  if(s[j][k]=='v'){ z=1; x=k; y=j;}
	  if(s[j][k]=='<'){ z=2; x=k; y=j;}
	  if(s[j][k]=='>'){ z=3; x=k; y=j;}
	}
      }
    }
    cin>>n>>com;
    for(int j=0;j<n;++j){
      if(com[j]=='U'){
	z=0;
	if(s[y-1][x]=='.') {
	  s[y-1][x]='^';
	  s[y][x]='.';
	  y--;
	}else s[y][x]='^';
      }
      else if(com[j]=='D'){
	z=1;
	if(s[y+1][x]=='.') {
	  s[y+1][x]='v';
	  s[y][x]='.';
	  y++;
	}else s[y][x]='v';
      }
      else if(com[j]=='L'){
	z=2;
	if(s[y][x-1]=='.') {
	  s[y][x-1]='<';
	  s[y][x]='.';
	  x--;
	}else s[y][x]='<';
      }
      else if(com[j]=='R'){
	z=3;
	if(s[y][x+1]=='.') {
	  s[y][x+1]='>';
	  s[y][x]='.';
	  x++;
	}else s[y][x]='>';
      }
      else{
	if(z==0){
	  for(int j=y;j>=1;--j){
	    if(s[j][x]=='*'||s[j][x]=='#'){
	      if(s[j][x]=='*') s[j][x]='.';
	      break;
	    }
	  }
	}else if(z==1){
	  for(int j=y;j<=h;++j){
	    if(s[j][x]=='*'||s[j][x]=='#'){
	      if(s[j][x]=='*') s[j][x]='.';
	      break;
	    }
	  }
	}else if(z==2){
	  for(int j=x;j>=1;--j){
	    if(s[y][j]=='*'||s[y][j]=='#'){
	      if(s[y][j]=='*') s[y][j]='.';
	      break;
	    }
	  }
	}else{
	  for(int j=x;j<=w;++j){
	    if(s[y][j]=='*'||s[y][j]=='#'){
	      if(s[y][j]=='*') s[y][j]='.';
	      break;
	    }
	  }
	}
      }
    }
    for(int j=1;j<=h;++j){
      for(int k=1;k<=w;++k) cout<<s[j][k];
      cout<<endl;
    }
    if(i!=t-1) cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
from collections import Counter
N,M = map(int,input().split())

ctr = Counter()
m,r = 2,M
while m*m <= r:
    while r%m==0:
        r //= m
        ctr[m] += 1
    m += 1
if r > 1:
    ctr[r] += 1

MAXN = N+50
MOD = 10**9+7
         
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 1
for v in ctr.values():
    ans *= ncr(N-1+v, v)
    ans %= MOD
print(ans)

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

int main() {
	int n, a, b, c, d, ways;
	while (cin >> n) {
		ways = 0;
		for (a = 0; a < 10; a++) {
			for (b = 0; b < 10; b++) {
				for (c = 0; c < 10; c++) {
					for (d = 0; d < 10; d++) {
						if (a + b + c + d == n) ways++;
					}
				}
			}
		}

		cout << ways << endl;
	}
}


Measured memory_bytes: 3124
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sa = b-a;
        int ans = 0;
        
        for(int i=sa; i>0; i--){
            ans += i;
        }
        
		System.out.println(ans-b);
    }
}


Measured memory_bytes: 35652
def read_i
  gets.chomp.split(' ').map(&:to_i)
end

a, b, k = read_i
arr = []
1.upto([a, b].max) do |n|
  if (a % n) == 0 && (b % n) == 0
    arr << n
  end
end
puts arr[-k]
__END__
8 12 2


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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n, k; cin>>n>>k;

    vector<int> v(n);

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

    int ans = MOD;

    for(int i=0; i+(k-1)<n; i++){
        int tmp = min(abs(v[i]), abs(v[i+k-1])) + v[i+k-1]-v[i];
        ans = min(ans, tmp);
    }

    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
typedef long long int ll ;
using namespace std ;
int main()
{
    ll n,a,b,i,p=0;
    cin>>n ;
    ll result = n - 1 ;
    for(i=1;i<=sqrt(n);++i)
    {
        if(!(n % i))
        {
            a=i;
            b=n/i ;
            p=1 ;
            result=min(result , ((a - 1) + (b - 1))) ;
        }
    }
    if(p) cout<<result<<"\n";
    else cout<<n - 1<<"\n";
    return 0 ;
}


Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int n,m;
int b[500],r[500],p[500];
bool f[500],c[500][500];

int gcd(int a,int b){
	if(a < b) swap(a,b);
	if(a%b == 0) return b;
	else return gcd(b,a%b);
}
bool match(int u){
	for(int i = 0; i < n; ++i){
		if(f[i] || !c[u][i]) continue;
		f[i] = true;
		if(p[i] == -1 || match(p[i])){
			p[i] = u;
			return true;
		}
	}
	return false;
}

int main(){
	while(cin >> m >> n,m){
		for(int i = 0; i < m; ++i) cin >> b[i];
		for(int i = 0; i < n; ++i) cin >> r[i];
		for(int i = 0; i < n; ++i){
			p[i] = -1;
		}
		for(int i = 0; i < m;++i)for(int j = 0; j < n;++j){
			c[i][j] = gcd(b[i],r[j]) > 1;
		}
		int sum = 0;
		for(int i = 0; i < m; ++i){
			for(int j = 0; j < n; ++j) f[j] = false;
			if(match(i)) ++sum;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1424
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        ArrayList<Point> li = new ArrayList<Point>();
        for(int i = 0; i < n; i++){
            li.add(new Point(sc.nextInt(),sc.nextInt(),sc.nextInt()));
        }
        Collections.sort(li);
        for(int i = 0; i <= 100; i++){
            for(int j = 0; j <= 100; j++){
                boolean flg = true;
                Point c = li.get(0);
                int chk = Math.abs(c.x-i)+Math.abs(c.y-j)+c.h;
                for(int k = 1; k < n; k++){
                    Point p = li.get(k);
                    if(!(p.h == 0 && chk <= Math.abs(p.x-i)+Math.abs(p.y-j)) && chk != Math.abs(p.x-i)+Math.abs(p.y-j)+p.h){
                        flg = false;
                        break;
                    }
                }
                if(flg){
                    System.out.println(i+" "+j+" "+chk);
                    return;
                }
            }
        }
    }
}

class Point implements Comparable<Point>{
    int x,y,h;
    public Point(int x, int y, int h){
        this.x = x;
        this.y = y;
        this.h = h;
    }
    public int compareTo(Point p){
        if(this.h > p.h){
            return -1;
        }else if(this.h < p.h){
            return 1;
        }else{
            return 0;
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

bool isPrime(int j);

int main(void){
    long long ans;
    int N;
    cin >> N;
    ans = 1;

    for(int i=2;i<=N;i++){
        int tmp;
        tmp = 0;
        if(isPrime(i)==true){
            for(int j=i;j<=N;j++){
               int tmpj=j;
               while(tmpj%i==0){
                tmp+=1;
                tmpj=tmpj/i;
               } 
            }
            ans = (tmp+1)*ans%1000000007;
        }
    }
    cout << ans;
    return 0;
}

bool isPrime(int j){
    bool flag;
    flag = true;
    if(j==2) {
        flag = true;
    }else{
        for(int i=2; i<=j-1; i++){
            if(j%i==0){
                flag = false;
                break;
            }
        }
    }
    return flag;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> G[200000];
int bi[200000];
int n,m;
bool dfs(int v,int c){
    bi[v]=c;
    for(auto p:G[v]){
        if(bi[p]==c)return false;
        if(bi[p]==0&&!dfs(p,-c))return false;
    }
    return true;
}
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int K;
            cin>>K;
            G[i].push_back(n-1+K);
            G[n-1+K].push_back(i);
        }
    }
    bool ok=true;
    dfs(0,1);
    for(int i=0;i<n;i++){
        if(!bi[i])ok=false;
    }
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 9088
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    a, b = LI()
    gcd = fractions.gcd(a, b)
    print(a*b//gcd)

main()



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

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000]{ 1 };
queue<int>que;

void bfs(int u, int t) {
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop(); for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.push(v);
				}
			}
			else if (!~d[v]) {
				d[v] = d[p] + 1; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1e6 + 3;

void solve() {
  int n;
  cin >> n;

  vi divi(n + 1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      ++divi[j];
    }
  }

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

signed main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 11068
#include <bits/stdc++.h>
using namespace std;
const int BASE = 998244353;

long long power(int x, int y)
{
  if (!y)
    return 1;
  long long res = power(x, y / 2);
  res = res * res % BASE;
  if (y % 2)
    res = res * x % BASE;
  return res;
}

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

  vector<long long> fact(n + 1), invFact(n + 1), p2(n + 1);
  fact[0] = p2[0] = 1;
  for (int i = 1; i <= n; i++)
  {
    fact[i] = fact[i - 1] * i % BASE;
    p2[i] = p2[i - 1] * 2 % BASE;
  }
  invFact[n] = power(fact[n], BASE - 2);
  for (int i = n; i; i--)
    invFact[i - 1] = invFact[i] * i % BASE;

  long long ans = power(3, n);
  for (int i = n / 2 + 1; i <= n; i++)
  {
    long long ways = fact[n] * invFact[i] % BASE * invFact[n - i] % BASE;
    ans = (ans + BASE - ways * p2[n - i + 1] % BASE) % BASE;
  }
  cout << ans << endl;
}


Measured memory_bytes: 234624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    int n,d;
    cin >> n >> d;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans=0;
    rep(i,n){
        if (a[i]-d>=0) ans+=a[i]-d;
    }
    if (ans==0) cout << "kusoge" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3104
n=int(input())
s=input()

score = 0

for p in range(1000):
    
    pw = str(p).zfill(3)
    
    start = 0
    n_match = 0
    
    for j in range(3):
        for i in range(start, len(s)):
            
            if s[i] == pw[j]:
                start = i+1
                n_match = n_match+1
                
                if j == 3-1:
                    # print(pw)
                    score = score+1
                
                break
        if n_match <= j:
            break
            
print(score)

Measured memory_bytes: 74240
# coding: utf-8
import itertools

n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

s = set(range(1,n+1))

t = list(itertools.permutations(s, n))
a = t.index(P) + 1
b = t.index(Q) + 1
print((abs(a-b)))

Measured memory_bytes: 8052
#レート
#1-399：灰色
#400-799：茶色
#800-1199：緑色
#1200-1599：水色
#1600-1999：青色
#2000-2399：黄色 
#2400-2799：橙色
#2800-3199：赤色

N = int(input())
scores = list(map(int,input().split()))

colors = []
color = ""
another = 0

for point in scores:
  if point <= 399:
    color = "gray"
    if color not in colors:
      colors.append(color)
  elif point <= 799:
    color = "brown"
    if color not in colors:
      colors.append(color)
  elif point <= 1199:
    color = "green"
    if color not in colors:
      colors.append(color)
  elif point <= 1599:
    color = "sky"
    if color not in colors:
      colors.append(color)
  elif point <= 1999:
    color = "blue"
    if color not in colors:
      colors.append(color)
  elif point <= 2399:
    color = "yellow"
    if color not in colors:
      colors.append(color)
  elif point <= 2799:
    color = "orange"
    if color not in colors:
      colors.append(color)
  elif point <= 3199:
    color = "red"
    if color not in colors:
      colors.append(color)
  elif point > 3199:
    another += 1
    
ans = len(colors)
if ans == 0:
  print(1,another)
else:
  print(ans,ans + another)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int A=sc.nextInt();
      int B=sc.nextInt();

      int C=A+B;

      int c=(A+B)/2;

      int ans=0;

      for(int k=0;k<=c;k++){
        if(C==2*k){
          ans=k;
        }
      }

      if(ans!=0){
        System.out.println(ans);
      }
      else{
        System.out.println("IMPOSSIBLE");
      }

    }
}


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

int main() {
  int n,k=0;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)%2 == 1){
      k++;
    }
  }
  
  if(k%2==0){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
  return 0;
}


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

#define M 1000000
#define L 14
#define NIL 0

char H[M][L]; /* Hash Table */

int getChar(char);
long long getKey(char *);
int h1(int);
int h2(int);
int find(char *);
int insert(char *);


int main() {
  int i, n, h;
  char str[L], com[9];

  for ( i=0; i<M; i++ ) H[i][0] = '\0';
    
  scanf( "%d" , &n );
  for ( i=0; i<n; i++ ) {
    scanf( "%s %s" , com , str );
    if ( com[0] == 'i' ) insert(str);
    else {
      if ( find(str) ) printf( "yes\n" );
      else printf( "no\n" );
    }
  }

  return 0;
}


int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum=0, p=1, i;
  
  for ( i=0; i<strlen(str); i++ ) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  
  return sum;
}

int h1(int key) {
  return key%M;
}

int h2(int key) {
  return 1+key%(M-1);
}

int find(char str[]) {
  int i=0;
  long long j, sum=getKey(str);

  while ( 1 ) {
    j = ( h1(sum)+i*h2(sum) ) % M;
    if ( strcmp(H[j], str) == 0 ) return j;
    if ( (H[j][0]=='\0') || (i>=M) ) return NIL;
    i++;
  }

  return NIL;
}

int insert(char str[]) {
  int i=0;
  long long j, sum=getKey(str);

  while ( 1 ) {
    j = ( h1(sum)+i*h2(sum) ) % M;
    if ( (H[j][0] == '\0') || (strcmp(H[j], str) == 0) ) {
      strcpy(H[j], str);
      return j;
    }
    else i++;
  }

  return NIL;
}



Measured memory_bytes: 15460
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n,k; cin >> n >> k ; vl snuke(n); ll cnt = 0;
  
  rep(i,k){
    ll d; cin >> d;
    rep(i,d){
      ll x; cin >> x; x--;
      snuke[x]++;
    }
  }
  
  rep(i,n){
    if(snuke[i] == 0) cnt++;
  }
  
  cout << cnt << endl;
}
      

Measured memory_bytes: 3608
def main():
  h,w = map(int,input().split())

  q = []
  reached = [[True]*(w+2)]
  for i in range(1, h+1):
    reached.append([True] + [s == '#' for s in list(input())] + [True])
    for j in range(1,w+1):
      if reached[i][j]: q.append((i,j))
  reached.append([True]*(w+2))

  res = 0
  for i in range(100000000):
    qq = []
    for k,l in q:
      if not reached[k+1][l]:
        qq.append((k+1, l))
        reached[k+1][l] = True
      if not reached[k][l+1]:
        qq.append((k, l+1))
        reached[k][l+1] = True
      if not reached[k-1][l]:
        qq.append((k-1, l))
        reached[k-1][l] = True
      if not reached[k][l-1]:
        qq.append((k, l-1))
        reached[k][l-1] = True
    if len(qq) == 0:
      break
    else:
      pass

    q = qq
    res += 1

  print(res)
  return 0

if __name__ == "__main__":
  main()


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


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

    vector<int> v(n);
    vector<int> c(n);

    rep(i,n)cin >> v[i];
    rep(i,n)cin >> c[i];
    int sum = 0;

    for (int i = 0; i < n; ++i) {
        if(v[i] > c[i])sum += v[i] - c[i];
    }

    print(sum);

}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define SZ(v)       (ll)(v).size()
#define ALL(v)      (v).begin(),(v).end()
#define UNIQ(v)     sort(ALL(v));(v).erase(unique(ALL(v)),(v).end())
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define BIT(n)      (1LL<<(n))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>
#define SHOW(x)     cout<<#x<<" = "<<x<<endl

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

int main() {
    ll N, K; cin >> N >> K;
    N -= 2;
    
    ll cal[15][7];
    memset(cal, 0, sizeof(cal));
    FOR(i, 2, 15) REP(j, 7) cal[i][j] = 7 * (i - 1) + (j + 1) - 7;
    
    REP(i, 13) REP(j, 5) {
        ll sum = 0;
        REP(x, 3) REP(y, 3) sum += cal[i+x][j+y];
        cal[i][j] = sum % 11;
    }
    
    ll ans = 0;
    if (N > 0) {
        ans += (N / 11) * 5;
        N %= 11;
        FOR(i, 2, N+2) REP(j, 5) if (cal[i][j] == K) ans++;
    } else {
        N += 2;
        REP(i, N) REP(j, 5) if (cal[i][j] == K) ans++;
    }
    cout << ans << endl;;
    
    return 0;
}


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

typedef struct Dice {
	int north,south,east,west,top,bottom;
} Dice;

typedef void (*DiceCmd)(Dice* dp);

void turn_north(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->south;
	dp->south = dp->bottom;
	dp->bottom = dp->north;
	dp->north = tmp;
}

void turn_south(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->north;
	dp->north = dp->bottom;
	dp->bottom = dp->south;
	dp->south = tmp;
}

void turn_east(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->west;
	dp->west = dp->bottom;
	dp->bottom = dp->east;
	dp->east = tmp;
}

void turn_west(Dice* dp){
	int tmp;

	tmp = dp->top;
	dp->top = dp->east;
	dp->east = dp->bottom;
	dp->bottom = dp->west;
	dp->west = tmp;
}

void clockwise(Dice* dp){
	int tmp;

	tmp = dp->south;
	dp->south = dp->east;
	dp->east = dp->north;
	dp->north = dp->west;
	dp->west = tmp;
}

void anticlockwise(Dice* dp){
	int tmp;

	tmp = dp->south;
	dp->south = dp->west;
	dp->west = dp->north;
	dp->north = dp->east;
	dp->east = tmp;
}

void input_dice(Dice *dp){
	scanf("%d",&dp->top);
	scanf("%d",&dp->south);
	scanf("%d",&dp->east);
	scanf("%d",&dp->west);
	scanf("%d",&dp->north);
	scanf("%d",&dp->bottom);
}

int is_same_dice(Dice *dp1, Dice *dp2){
	Dice d1;
	int q_cnt,q_top,q_south;
	DiceCmd dice_cmd[6][3] = {
		{ turn_north, NULL, NULL }, // South -> Top
		{ turn_south,  NULL, NULL }, // North -> Top
		{ turn_east, NULL, NULL }, // West -> Top
		{ turn_west, NULL, NULL }, // Eas  -> Top
		{ NULL, NULL, NULL }, // Top -> Top
		{ turn_north, turn_north,  NULL }, // Bottom -> Top
	};
	int i,j;
	int yes;

	// Solve
	yes = 0;
	for(i=0;i<=5;i++){
		// Reset
		memcpy( &d1, dp1, sizeof(Dice) );
		// Turn
		for(j=0; dice_cmd[i][j]!=NULL; j++){
			dice_cmd[i][j](&d1);
		}

		// Turn & Check
		j=1;
		for(;;){
			if( memcmp(&d1, dp2, sizeof(Dice)) == 0 ){
				yes = 1;
				break;
			} else if( j<4 ){
				clockwise(&d1);
				j++;
			} else {
				break;
			}
		}

		if( yes ) {
			break;
		}
	}

	return yes;
}

int main(int argc, char** argv){
	int n;
	Dice d[100];
	int i,j;
	int found;

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

	// Solve
	found = 0;
	for(i=0; i<n-1; i++){
		for( j=i+1; j<n; j++){
			if( is_same_dice( &d[i], &d[j] ) ){
				found = 1;
				break;
			}
		}
		if( found ){
			break;
		}
	}

	// Output
	if( found ){
		printf("No\n");
	} else {
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int H;
    int n;
    cin >> H;
    cin >> n;
    int total = 0;
    for(int i = 0; i< n; i++){
        int a;
        cin >> a;
        total += a;
        if( H <= total) {
            break;
        }
    }
    if(H<=total){
        cout << "Yes" << endl;
    }
    else{
        cout <<  "No" << endl;
    }
}

Measured memory_bytes: 256
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (N, M, X) = readInts()
    val A = readInts()

    var c = 0
    for (k in (0 + 1) until X) {
        if (A.contains(k)) c += 1
    }

    var d = 0
    for (k in (X + 1) until N) {
        if (A.contains(k)) d += 1
    }

    println(if (c < d) c else d)
}

Measured memory_bytes: 37856
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int sum=0;
        while(n!=0||x!=0){
            for(int i=n;i>=3;i--){
                for(int j=i-1;j>=2;j--){
                    if(i==j) continue;
                    for(int k=j-1;k>=1;k--){
                        if(i==k||j==k) continue;
                        if(i+j+k==x) sum++;
                    }
                }
            }
            System.out.println(sum);
            sum = 0;
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
}


Measured memory_bytes: 26692
//
// Created on 2020/04/12.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll ans = 0;
    ll n;
    cin>>n;
    for (ll i = 1; i <= n; ++i) {
        if(i % 3 == 0 || i % 5 == 0){
            continue;
        }else{
            ans += i;
        }
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    LL N,M,D;
    GLL(N);GLL(M);GLL(D);
    double x=2*(N-D)/(double)(N*N);
    if(D==0)
        x/=2.0;
    printf("%.10lf\n",x*(M-1));
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,a,b,c,d;
    scanf("%d",&N);
    a = N / 1000;
    b = N % 1000 / 100;
    c = N % 1000 % 100 / 10;
    d = N % 1000 % 100 % 10 / 1;
    
    if (a == b && b == c){
        printf("Yes");
        return 0;
    }

    if(b == c && c == d){
        printf("Yes");
        return 0;
    }

    printf("No");

}

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

typedef long long ll;
typedef vector<int> vi;

int main(){
	int a;
    cin >> a;
    cout << 3 * a * a;
    
    return 0;
}


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


int main() {

    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i,n) {
        rep(j,d) cin >> x[i][j];
    }
    int ans = 0;
    rep(i,n)rep(j,i) { // j < i
        int sq = 0;
        rep(k,d) {
            int s = x[i][k]-x[j][k];
            sq += s*s;
        }
        int t = sqrt(sq)+0.5;
        if (t*t == sq) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

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

long long gcd(long long a, long long b) {
    // O(log min(a,b))
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

    int N;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    vector<int> L(N), R(N);
    L[0] = 0;
    R[N - 1] = 0;
    for (int i = 1; i < N; i++) {
        L[i] = gcd(A[i - 1], L[i - 1]);
    }
    for (int i = N - 2; i >= 0; i--) {
        R[i] = gcd(A[i + 1], R[i + 1]);
    }

    vector<int> M(N);
    for (int i = 0; i < N; i++) {
        M[i] = gcd(L[i], R[i]);
    }

    auto iter = max_element(M.begin(), M.end());
    cout << *iter << endl;

    return 0;
}


Measured memory_bytes: 1912
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

int main() {
SS(ll,n,k,m);
vl ord(m, -1); // かつて来た地点を求める
    vl rireki, syu;
    ll res = 0;
    rep(j,n){
        // かつて来た地点に戻ったら
        if (ord[k] != -1) {
            int p = ord[k];
            for (ll i = p; i < j; ++i) syu.push_back(rireki[i]);
            break;
        }
        ord[k] = j;
        rireki.push_back(k);
        res += k;
        k = (k * k) % m;
    }
    n -= rireki.size();

    // 戻る前に N 項目に到達した場合
    if (n == 0) {
        p(res);
        return 0;
    }
    // 周期の累積和をとる
    vl sum(syu.size() + 1, 0);
    rep(i,syu.size()) sum[i+1] = sum[i] + syu[i];
    // 周期を q 週して r あまる
    ll q = n / syu.size();
    ll r = n % syu.size();
    res += sum[syu.size()] * q + sum[r];
    p(res);
}


Measured memory_bytes: 5452
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int itemCount = inpt[0];

        this.Target = inpt[1];

        for (int i = 1; i <= itemCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            this.Haiten.Add(i * 100, inpt[0]);
            this.Complete.Add(i * 100, inpt[1]);
        }
        this.KeyList = this.Haiten.Keys.OrderByDescending(a => a).ToArray();

        int ans = GetAns(0, this.Target);
        Console.WriteLine(ans);
    }

    private int Target;

    private Dictionary<int, int> Complete = new Dictionary<int, int>();
    private Dictionary<int, int> Haiten = new Dictionary<int, int>();


    private int GetAns(int idx, int remain) {
        if(remain <= 0) {
            return 0;
        }
        if(idx >= this.KeyList.Length) {
            return -1;
        }
        if(!dic.ContainsKey(idx)) {
            dic.Add(idx, new Dictionary<int, int>());
        }
        if(dic[idx].ContainsKey(remain)) {
            return dic[idx][remain];
        }

        int ans = int.MaxValue;
        int unit = KeyList[idx];

        for (int i = 0; i < Haiten[unit]; i++) {
            int tmp = GetAns(idx + 1, remain - (unit * i));
            if(tmp < 0) {
                continue;
            }
            tmp += i;
            ans = Math.Min(ans, tmp);
        }
        int t2 = GetAns(idx + 1, remain - (unit * Haiten[unit] + Complete[unit]));
        if(t2 >= 0) {
            t2 += Haiten[unit];
            ans = Math.Min(ans, t2);
        }
        if(ans == int.MaxValue) {
            ans = -1;
        }
        dic[idx][remain] = ans;
        return ans;
    }

    private int[] KeyList;
    private Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>();

    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




5 25000
20 1000
40 1000
50 1000
30 1000
1 1000


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 20576
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int[] colors = new int[]{
			1,400,800,1200,1600,2000,2400,2800,3200
		};
		
		int[] mem = new int[colors.Length];
		for(int i=0;i<N;i++){
			for(int j=colors.Length-1;j>=0;j--){
				if(colors[j] <= A[i]){
					mem[j]++;
					break;
				}
			}
		}
		
		int cnt = 0;
		for(int j=0;j<colors.Length-1;j++){
			if(mem[j] > 0) cnt++;
		}
		int min = cnt;
		int max = cnt;
		if(mem[colors.Length-1] > 0){
			min = min == 0 ? 1 : min;
			max = max + mem[colors.Length-1];
		}
		Console.WriteLine("{0} {1}",min,max);
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
string S;

bool valid(string s){
	for(int i = 0; i < s.length() / 2; i++)
		if(s[i] != s[s.length() / 2 + i]) return false;
	return true;
}

int main(void){
	//IO("test.in", "test.out");
	cin >> S;
	for(int i = 2; i < S.length(); i += 2)
		if(valid(S.substr(0, S.length() - i))){
			printf("%d\n", S.length() - i);
			break;
		}
}

Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
 */

import java.util.*;

class Point {
	double x, y;
	Point(double x, double y) {
		this.x = x;
		this.y = y;
	}
	void print() {
		System.out.printf("%.8f %.8f\n", x, y);
	}
}

public class Main {
	
	double dist(Point s, Point t) {
		double xd = t.x - s.x;
		double yd = t.y - s.y;
		return Math.sqrt(xd*xd + yd*yd);
	}
	
	void koch(int n, Point p1, Point p2) {
		if (n <= 0) return;
		n--;
		Point s = new Point((p1.x*2 + p2.x) / 3.0, (p1.y*2 + p2.y) / 3.0);
		Point t = new Point((p1.x + p2.x*2) / 3.0, (p1.y + p2.y*2) / 3.0);
		double ux = (t.x - s.x) * Math.cos(Math.toRadians(60)) - (t.y - s.y) * Math.sin(Math.toRadians(60)) + s.x;
		double uy = (t.x - s.x) * Math.sin(Math.toRadians(60)) + (t.y - s.y) * Math.cos(Math.toRadians(60)) + s.y;
		Point u = new Point(ux, uy);
		koch(n, p1, s);
		s.print();
		koch(n, s, u);
		u.print();
		koch(n, u, t);
		t.print();
		koch(n, t, p2);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point p1 = new Point(0, 0);
		Point p2 = new Point(100, 0);
		
		p1.print();
		koch(n, p1, p2);
		p2.print();
	}

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

}



Measured memory_bytes: 40720
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    double l;
    cin >> l;
    cout << SYOU(15) << pow(l/3.0, 3) << '\n';
    return 0;
} 


Measured memory_bytes: 256