akhauriyash/Code-Regression huggingface dataset:
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], q = tmp[1];
    string s = readln.chomp;
    int[] dp = new int[n];
    foreach (i; 1 .. n) {
        int cnt;
        if (s[i-1] == 'A' && s[i] == 'C') {
            ++cnt;
        }
        dp[i] += dp[i-1] + cnt;
    }
    foreach (i; 0 .. q) {
        tmp = readln.split.to!(int[]);
        int l = tmp[0] - 1, r = tmp[1] - 1;
        writeln(dp[r] - dp[l]);
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4220
import java.util.*;
import java.lang.*;
class Main{
    public static int p(int n){
        int count = 0;
        for(int i = 1; i < (int) Math.sqrt(n)+1; i++){
            if(n%i==0)count+=2;
        }
        return count;
    }
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int count = 0;
        for(int i = 105; i <= N; i+= 2){
            if(p(i) == 8)count++;
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 23636
class abc_167:
    
    def __init__(self):
        pass
    
    def A(self):
        S=input()
        T=input()
        if S==T[:len(S)]:print("Yes")
        else:print("No")
    
    def B(self):
        ABCK=list(map(int,input().split()))
        sum_num=0
        
        if ABCK[3]<=ABCK[0]:sum_num=ABCK[3]
        elif ABCK[3]<=ABCK[0]+ABCK[1]:sum_num=ABCK[0]
        else:sum_num=ABCK[0]-(ABCK[3]-ABCK[0]-ABCK[1])
        
        print(sum_num)
            
    def C(self):
        pass
            
    def D(self):
        
        NK=list(map(int,input().split()))
        A=list(map(int,input().split()))
        stack=[]
        A_memo=[0]*(NK[0]+1)
        flag=False
        
        
        count=0
        stack.append(A[count])
        count+=1
        A_memo[1]=count
        
        max_data = NK[0]+1 if NK[0]<=NK[1] else NK[1]
        
        while(count<max_data):
            data=stack.pop()
            stack.append(A[data-1])
            count+=1
            
            if A_memo[A[data-1]]==0:
                A_memo[A[data-1]]=count
            else:
                loop_val=A[data-1]
                flag=True
                break
            
        #a=count-A[loop_val]
        #b=NK[1]-A[loop_val]
        #print(count-A[loop_val])
        #print(NK[1]-A[loop_val])
        #print((b%a)+A[loop_val]-1)
        ans_stack=[]
        ans_stack.append(A[0])
            
        if flag==True:
            ans=((NK[1]-A[loop_val])%(count-A[loop_val]))+(A[loop_val]-1)
            for i in range(ans):
                ans_data=ans_stack.pop()
                ans_stack.append(A[ans_data-1])
            end=ans_stack.pop()
            print(end)
        else:
            ans=count
            for i in range(ans):
                ans_data=ans_stack.pop()
                ans_stack.append(A[ans_data-1])
            end=ans_stack.pop()
            print(end)
            
            
           
            
    
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_167()
    obj.B()

Measured memory_bytes: 62424
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 300000;
const int mod = 998244353;
const int K = 60;
const int M = 16;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            for (int l = 1; l <= n; l++){
                ans += __gcd(i, __gcd(j, l));
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <vector>
using namespace std;

typedef struct Node {
	char c;
	int v;
} Node;

void BubbleSort(vector<Node>& nums)
{
	for(unsigned int i = 1; i < nums.size(); ++i) {
		bool flag = true;
		for(unsigned int j = 0; j < nums.size()-i; ++j) {
			if(nums[j].v > nums[j+1].v) {
				Node t = nums[j+1]; nums[j+1] = nums[j]; nums[j] = t;
				flag = false;
			}
		}
		if(flag) {
			break;
		}
	}
}

void SelectSort(vector<Node>& nums)
{
	for(unsigned int i = 0; i < nums.size()-1; ++i) {
		unsigned int k = i;
		for(unsigned int j = i+1; j < nums.size(); ++j) {
			if(nums[j].v < nums[k].v) {
				k = j;
			}
		}
		if(k != i) {
			Node t = nums[k]; nums[k] = nums[i]; nums[i] = t;
		}
	}
}

void PrintNums(vector<Node>& nums)
{
	for(unsigned int i = 0; i < nums.size(); ++i) {
		if(i) {
			putchar(' '); 
		}
		printf("%c%d",nums[i].c,nums[i].v);
	}
	putchar('\n');	
}

int main()
{
	int n; scanf("%d%*c",&n);
	vector<Node> nums(n);
	for(int i = 0; i < n; ++i) {
		scanf("%c%d%*c",&nums[i].c,&nums[i].v);
	}
	vector<Node> nums_a(nums);
	BubbleSort(nums_a);
	PrintNums(nums_a);
	printf("Stable\n");
	
	vector<Node> nums_b(nums);
	SelectSort(nums_b);
	PrintNums(nums_b);
	bool Stable = true;
	for(int i = 0; i < n; ++i) {
		if(nums_a[i].c != nums_b[i].c) {
			Stable = false;
			break;
		}
	}
	printf("%s\n",!Stable?"Not stable":"Stable");
	return 0;
}



Measured memory_bytes: 2796
#include<cstdio>
#include<algorithm>
#define Mod 1000000007
struct node{
	int c,w;
}a[200001];
int n,X,Y,mini[200001],min1,min2=Mod,inv[200001],cnt[200001],sum;long long ans=1;
bool in1[200001],in2[200001];
bool cmp(node x,node y){return x.w<y.w;}
int main()
{
	scanf("%d%d%d",&n,&X,&Y);
	inv[1]=1;for(int i=2;i<=n;++i)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(int i=2;i<=n;++i)inv[i]=1ll*inv[i-1]*inv[i]%Mod;
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i].c,&a[i].w);
	std::sort(a+1,a+n+1,cmp);
	min1=a[1].w;for(int i=2;i<=n;++i)if(a[i].c!=a[1].c){min2=a[i].w;break;}
	for(int i=1;i<=n;++i){
		if(!mini[a[i].c])mini[a[i].c]=a[i].w,cnt[a[i].c]++,in1[i]=1;
		else if(a[i].w+mini[a[i].c]<=X&&!in1[i])cnt[a[i].c]++,in1[i]=1;
		if(a[i].c==a[1].c)if(min2+a[i].w<=Y){
			if(!in1[i])cnt[a[i].c]++;
			in2[a[i].c]=in1[i]=1;
		}
			
		if(a[i].c!=a[1].c)if(min1+a[i].w<=Y){
			if(!in1[i])cnt[a[i].c]++;
			in2[a[i].c]=in1[i]=1;
		}
	}
	for(int i=1;i<=n;++i)if(in2[i])
		sum+=cnt[i],ans=1ll*ans*inv[cnt[i]]%Mod;
	for(int i=2;i<=sum;++i)ans=1ll*ans*i%Mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4480
#include <stdio.h>

int main(){
	long long int n;
	scanf("%lld",&n);
	long long int num[n]={};
	long long int res=1;
	long long int temp;
	for (long long int i=0;i<n;i++){
		scanf("%lld",&num[i]);
	}
	for(long long int i=0;i<n;i++){
	
		if (num[i]==0){
			printf("0\n");
			return 0;
		}
		}
	for (int i=0;i<n;i++){
		if(num[i]<=1000000000000000000/res){
			res*=num[i];
		}
		else{
			printf("-1\n");
			return 0;
		}
	}	
		printf("%lld",res);
		return 0;
	}
	

Measured memory_bytes: 2432
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  bool zero = false;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) zero = true;
  }
  if (zero) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 0; i < n; ++i) {
    if ((ll)(1e18) / a[i] < ans) {
      cout << -1 << endl;
      return 0;
    }
    ans = ans * a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4020
import java.util.*;

import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	int[] eratosthenes(int n) {
		boolean[] dp = new boolean[n+1];
		dp[0] = dp[1] = true;
		List<Integer> prime = new LinkedList<Integer>();
		for (int i = 2; i <= n; i++) {
			if (dp[i]) continue;
			prime.add(i);
			for (int j = i + i; j <= n; j += i) 
				dp[j] = true;
		}
		
		int[] ret = new int[prime.size()];
		int count = 0;
		for (int num : prime)
			ret[count++] = num;
		
		return ret;
	}
	
	boolean isPrime(int n) {
		if (n < 2) return false;
		for (int i = 2; i * i <= n; i++)
			if (n % i == 0) return false;
			
		return true;
	}
	
	void run() {
		int n;
		int[] prime = eratosthenes(1299709);
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;
			
			if (isPrime(n)) {
				out.println(0);
				continue;
			}
			
			int index = 0;
			while (n > prime[index]) index++;
			out.println(prime[index] - prime[index-1]);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif

int main(){
	int h,w;
	cin>>h>>w;
	string data[100];
	rep(i,h){
		cin>>data[i];
	}


	int dp[100][100];
	rep(i,100)rep(j,100)dp[i][j]=999999999;
	dp[0][0]=data[0][0]-'0';

	rep(i,h){
		rep(j,w){
			if( i+1<h ) dp[i+1][j]=min( dp[i][j]+data[i+1][j]-'0' , dp[i+1][j] );
			if( j+1<w ) dp[i][j+1]=min( dp[i][j]+data[i][j+1]-'0' , dp[i][j+1] );
		}
	}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}

Measured memory_bytes: 1248
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		short[] xArray = new short[n];
		short[] yArray = new short[n];
		for (int i = 0; i < xArray.length; i++) {
			xArray[i] = sc.nextShort();
		}
		for (int i = 0; i < yArray.length; i++) {
			yArray[i] = sc.nextShort();
		}
		Calc cl = new Calc();
		for (byte i = 1; i <= 4; i++) {
			System.out.printf("%f\n", cl.calcDistance(xArray, yArray, i));
		}
	}
}

class Calc {
	public double calcDistance(short[] xArray, short[] yArray, byte operation) {
		double[] calcArray = new double[xArray.length];
		if (operation > 0 && operation < 4) {
			for (int i = 0; i < calcArray.length; i++) {
				calcArray[i] = Math.abs(Math.pow(xArray[i] - yArray[i], operation));
			}
			double sum = 0;
			for (int i = 0; i < calcArray.length; i++) {
				sum += calcArray[i];
			}
			switch (operation) {
				case 1:
					return sum;
				case 2:
					return Math.sqrt(sum);
				case 3:
					return Math.cbrt(sum);
				default:
					break;
			}
		} else if (operation == 4) {
			for (int i = 0; i < calcArray.length; i++) {
				calcArray[i] = Math.abs(xArray[i] - yArray[i]);
			}
			double max = calcArray[0];
			for (int i = 1; i < calcArray.length; i++) {
				if (max < calcArray[i]) {
					max = calcArray[i];
				}
			}
			return max;
		}
		return -1;
	}
}


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

using namespace std;

int main()
{
    int M, D;   cin >> M >> D;

    int Ans = 0;

    for(int m = 1; m <= M; m++)
        for(int x = 2; x <= 9; x++)
            for(int y = 2; y <= 9; y++)
            {
                int d = 10 * y + x;

                if(d > D)   continue;

                if(x * y == m)  Ans++;
            }

    cout << Ans << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<long double> p(n);
    for(int i = 0 ; i < n ; i++){
        cin >> p[i];
    }
    
    vector<vector<long double>> dp(n+1 , vector<long double>(n+1 , 0.0));
    dp[0][0] = 1.0;
    for(int i = 1 ; i <= n ; i++){
        dp[i][0] = (1 - p[i-1])*dp[i-1][0];
    }
    for(int i = 1 ; i<= n ; i++){
        for(int j = 1; j <= i ; j++ ){
            dp[i][j] = dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1]);
        }
    }
    //for(int i = 0 ; i<= n ; i++){
    //    for(int j = 0 ; j <= n ; j++){
    //        cout << dp[i][j]<<" ";
    //    }
    //    cout << "\n";
    //}

    long double ans = 0.0;
    for(int i = (n+1)/2; i <= n ;i++){
        ans += dp[n][i];
    }
    
    printf("%.9llf\n", ans);
    return 0;
}

Measured memory_bytes: 144276
from itertools import permutations


def main():
    result = 700
    cooking_time = []
    for _ in range(5):
        cooking_time.append(int(input()))
    for permutation in permutations(cooking_time, 5):
        tmp = 0
        for i in range(4):
            if not permutation[i] % 10 == 0:
                tmp += (permutation[i] // 10 + 1) * 10
            else:
                tmp += permutation[i]
        result = min(result, tmp + permutation[-1])
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    ll t1, t2, a1, a2, b1, b2, d1, d2, ans;

    scanf("%lld%lld%lld%lld%lld%lld", &t1, &t2, &a1, &a2, &b1, &b2);

    d1 = (a1 - b1) * t1;
    d2 = (a2 - b2) * t2;

    if (d1 > 0) {
        d1 = -d1;
        d2 = -d2;
    }

    if (d1 + d2 < 0) {
        printf("0\n");
        return 0;
    }

    if (d1 + d2 == 0) {
        printf("infinity\n");
        return 0;
    }

    ans = (-d1) / (d1 + d2) * 2 + 1;

    if ((-d1) % (d1 + d2) == 0) {
        ans--;
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

const int MAX_N = 1000;
const int MOD = 1e9 + 7;

char s[MAX_N + 3][MAX_N + 3];

inline int add(int x, int v) { return x + v >= MOD ? x + v - MOD : x + v; }

int f[MAX_N + 1][MAX_N + 1];

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int H, W;
  std::cin >> H >> W;
  for (int i = 1; i <= H; ++i) std::cin >> s[i] + 1;
  f[1][1] = 1;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (s[i][j] == '.' && !(i == 1 && j == 1)) {
        f[i][j] = add(f[i - 1][j], f[i][j - 1]);
      }
    }
  }
  std::cout << f[H][W];
  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
using namespace std;
static const int N = 100;

int main() {
    int M[N][N];
    int n, u, k, v;

    std::cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        std::cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            std::cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if(j) std::cout << " ";
            std::cout << M[i][j];
        }
        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3092
h, w = [int(i) for i in input().split()]

s = []

for i in range(h):
    s += [str(input())]
    
    

def padding(s,h,w):
    res = []
    res_0 = '.'*(w+2)
    for i in range(h+2):
        if i ==0:
            res = res + [res_0]
        elif i == h+1:
            res = res + [res_0]
        else:
            res_add = '.' + s[i-1] + '.'
            res += [res_add]
    return res

def check_mine(s,i,j):
    cout = 0
    for k in [-1+i,i,1+i]:
        for l in [-1+j,j,1+j]:
            if s[k][l] == '#':
                cout +=1
                
    if s[i][j] == '.':
        return str(cout)
    else:
        return '#'
    
s = padding(s,h,w)

for i in range(h):
    temp = str()
    for j in range(w):
        temp += check_mine(s,i+1,j+1)
    print(temp)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<map>

using namespace std;
int check(string data, string num){

  for(int i = 0; i < 8; i++){
    if(num[i] != '*' && num[i] != data[i]) return 0;
  }
  return 1;
}
int main(){

  int n, m;

  while(cin >> n >> m && n && m){
    int sum = 0;
    map <string, int> M;
    string num[n];
    for(int i = 0; i < n; i++){
      int in;
      cin >> num[i] >> in;
      M[num[i]] = in;
    }
    string data[m];

    for(int i = 0; i < m; i++){
      cin >> data[i];
      for(int j = 0; j < n; j++){
	if(check(data[i], num[j])) sum += M[num[j]];
      }
    }

    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] arrayv=new int[n];
		int sum1=0,sum2=0,min=99999;

		for(int i=0;i<n;i++) {
			arrayv[i]=sc.nextInt();
		}

		for(int i=1;i<=n;i++) {
			for(int j=0;j<i;j++) {
				sum1+=arrayv[j];
			}
			for(int j=i;j<n;j++) {
				sum2+=arrayv[j];
			}
			min=Math.min(Math.abs(sum2-sum1), min);
			sum1=0;
			sum2=0;
		}
		System.out.println(min);

	}
}
/*
 6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
 */

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));




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

int main() {
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end(), greater<int>());
  long long a = -1, b = -1;
  for (int i = 0; i < n - 1; i++) {
    if (v.at(i) == v.at(i + 1) && a == -1) {
      a = v.at(i);
      i++;
      continue;
    }
    if (v.at(i) == v.at(i + 1) && a != -1) {
      b = v.at(i);
      break;
    }
  }
  if (a == -1 || b == -1) {
    cout << 0 << endl;
  } else {
    cout << a * b << endl;
  }
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        char result = (char) ((int) s.charAt(0) + 1);

        // 出力
        System.out.println(result);
    }
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int n;
int a[112345];

int main() {
	while (cin >> n, n) {
		REP(i, n) scanf("%d", a + i);
		
		int k; cin >> k;
		
		int l = 0, r = n - 1;
		int c = 0;
		while (r - l >= 0) {
			int m = (l + r) / 2;
			c++;
			
			if (a[m] == k) break;
			if (a[m] < k) l = m + 1;
			else r = m - 1;
		}
		
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 3044
#include<iostream>
#include<vector>
#define MOD 998244353

using namespace std;

int X[100005],Y[100005],Z[100005];

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

    int n;
    string S;
    cin>>n>>S;

    vector<int> R,G,B;
    for(int i=0; i<3*n; i++)
    {
        if(S[i]=='R')
            R.push_back(i);
        else if(S[i]=='G')
            G.push_back(i);
        else
            B.push_back(i);
    }

    for(int i=0; i<n; i++)
    {
        int sum=R[i]+G[i]+B[i];

        X[i+1]=min(R[i],min(G[i],B[i]));
        Z[i+1]=max(R[i],max(G[i],B[i]));
        Y[i+1]=sum-X[i+1]-Z[i+1];
    }

    int rez=1;
    int ind1=0,ind2=0;
    for(int i=1; i<=n; i++)
    {
        ind1=max(ind1,i);
        while(ind1<n && Y[ind1+1]<Z[i])  //Y[ind+1] si Z[i] nu pot avea aceasi culoare deoarece ind+1>i si asta ar presupune si B>C
            ind1++;
        rez=(1LL*rez*(ind1-i+1))%MOD; //pot da swap lui Z[i] cu fiecare Z[i....ind]

        ind2=max(ind2,i);
        while(ind2<n && X[ind2+1]<Y[i])  //same
            ind2++;
        rez=(1LL*rez*(ind2-i+1))%MOD; //lui A
    }

    for(int i=n; i>=1; i--)
        rez=(1LL*rez*i)%MOD;
    cout<<rez<<"\n";
    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int a, b, c;
  cin >> a >> b >> c;

  int ans = b / a;
  cout << min(ans, c) << endl;

  return 0;
}


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


int a;
double b;
double v_sin[15];
double v_cos[15];
double x, y;

void koch_curve(int p);

int main(void)
{
    int n;
    for (int i = 0; i < 6; i++) v_cos[i] = cos(i*M_PI/3), v_sin[i]=sin(i*M_PI/3);
    scanf("%d", &n);
    b = 100;
    a = 0, x = 0, y = 0; puts("0.00000000 0.00000000");
    koch_curve(n);
    return 0;
}

void koch_curve(int p)
{
    if (p == 0) {
        x =x+ b*v_cos[a % 6], y += b*v_sin[a%6];
        printf("%.8lf %.8lf\n", x, y);
    }
    else {
        b =b/3;
        koch_curve(p-1), a++, koch_curve(p-1);
        a =a+4;
        koch_curve(p-1), a++, koch_curve(p-1);
        b =b*3;
    }
}







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

using namespace std;
constexpr int NMAX = 100;

int main() {
	int n; scanf("%d", &n);
	vector<int> ans(n + 1);
	for (int x = 1; x <= NMAX; ++x) {
		for (int y = 1; y <= NMAX; ++y) {
			for (int z = 1; z <= NMAX; ++z) {
				int val = x*x + y*y + z*z + x*y + y*z + z*x;
				if (val <= n) ++ans[val];
			}
		}
	}
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 3736
#include<cstdio>

int n, a[200000];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int sum = 0;
    for (int i = 0; i < n - 1; i++) sum ^= a[i] ^ a[n - 1];
    for (int i = 0; i < n; i++) printf("%d%c", sum ^ a[i], (i == n - 1) ? '\n' : ' ');
    return 0;
}


Measured memory_bytes: 3248
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll k ; cin >> k ;
	cout << 50 << endl ;
	if(k%50==0){
		for(int i=0;i<50;i++) cout << k/50+49 << (i==49?'\n':' ') ;
	}else{
		for(int i=0;i<50-k%50;i++) cout << k/50+49-k%50 << " " ;
		for(int i=0;i<k%50;i++) cout << k/50+100-k%50 << (i==k%50-1?'\n':' ') ;
	}
}


Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int q; cin >> q;
    const int n = 1e5;
    vector<bool> is_prime(n+1,true);

    is_prime[0] = false;
    is_prime[1] = false;

    for(int i = 2; i * i <= n; ++i) {
        if(is_prime[i]) {
            for(int j = i + i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }

    vector<ll> s(n+2,0);
    ll num = 0;
    for(int i = 0; i < n +1; ++i) {
        if(is_prime[i] && is_prime[(i+1)/2])
            num++;
        s[i+1] = s[0] + num;
    }

    REP(i, q) {
        int l, q;
        cin >> l >> q;
        cout << s[q+1] - s[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
/*
 * atcoder ABC 133 : B. Good Distance
 * Solution : editorial
 * 22 august 2019
 *
 */
#include <bits/stdc++.h>
using namespace std;

int N,D;
int arr[12][12];

int main()
{
	cin >> N >> D;

	// read element
	for(int i = 1 ; i <= N ; i++){
		for(int j = 1 ; j <= D ; j++){
			cin >> arr[i][j];
		}
	}

	int ans = 0;

	// nunjuk baris ke i
	for(int i = 1 ; i <= N ; i++){
		
		// nunju baris ke i+1
		for(int j = i + 1 ; j <= N ; j++){
			int norm = 0;

			// nunjuk kolom 
			for(int k = 1 ; k <= D ; k++){
				int diff = abs(arr[i][k] - arr[j][k]);
				norm += (diff * diff);
			}

			bool flag = false;
			for(int k = 1 ; k <= norm ; k++){
				if((k * k) == norm){
					flag = true;
				}
			}

			if(flag) ++ans;
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
N, M = [int(_) for _ in raw_input().split(" ")]

ret = [1] * N
color = [False]*N
color[0] = True
for i in range(M):
  _from, _to = [int(_) for _ in raw_input().split(" ")]
  ret[_from-1] -= 1
  ret[_to-1] += 1
  if color[_from-1] == True:
    color[_to-1] = True
  if ret[_from-1] == 0:
    color[_from-1] = False
  #print ret
  #print color
print color.count(True)


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

int main(){
    int a, b, h;
    cin >> a;
    cin >> b;
    cin >> h;
    if(a == b){
        cout << a * h << endl;
    }else{
        cout << (a + b) * h / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
#define ll long long int

int main()
{
    speed;

    ll n;
    cin>>n;

    vector<ll>v(n);
    ll ans=0;

    for(ll i=0;i<n;i++) cin>>v[i];

    stack<ll>s;
    s.push(v[0]);

    for(ll i=1;i<n;i++)
    {
        if(s.top() < v[i]) s.push(v[i]);

        else ans+=(s.top()-v[i]);
    }
    
    cout<<ans<<"\n";
}

Measured memory_bytes: 6272
// ...

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

typedef long long int ll;
typedef long double ld;
#define endl "\n"
#define int long long
#define float long double
#define u_s unordered_set
#define mm multimap
#define pb push_back
#define ff first
#define ss second
#define beg begin()
#define end end()
#define siz size()
#define baahubali ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
const int mod = 1000000007;
void deb(int arg_count, ...){
    cout<<endl;
    va_list ap;va_start(ap, arg_count);for(int i=0;i<arg_count;i++){
    cout<<va_arg(ap, int)<<" ";}
    cout<<endl;
}
unsigned int countBits(int number) {
    unsigned int l=log2(number)+1;
    return l; 
}
bool at_position(int num,int pos) 
{   
    unsigned int go=(1ULL<<pos);
    bool bit = num & go; 
    return bit; 
} 

//-----------------------------------------------------------------------------------

signed main(){
    baahubali;
    string a,b;
    cin>>a>>b;
    b.erase(0+(b.size()-1));
    if(a==b)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明


// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }


// ll my_gcd(ll a, ll b){
// 	return (b==0) ? a : my_gcd(b, a%b);
// }


//  ll my_lcm(ll a, ll b){
//  	return a*b / my_gcd(a,b);
//  }


// ll factorial(ll a){
// 	ll ans = 1;
// 	for(ll i=a; i>0; i--){
// 		ans *= i;
// 	}
// 	return ans;
// }

int main(int argc, char *argv[]){
    int N, K;
    cin >> N >> K;
    int A[N];
    for (int i=0; i<N; i++){
        cin >> A[i];
    }

    int m = 200001;
    int A_count[m] = {};
    for (int i=0; i<N; i++){
        A_count[A[i]]++;
    }

    sort(A_count, A_count + m);
    int N_tmp = 0;
    for (int i=0; i<K; i++) {
        N_tmp += A_count[m-1-i];
    }

    cout << N - N_tmp << endl;
    return 0;
}

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

int main(void)
{
  ll n, m;
  cin >> n >> m;
  vector<ll> hs(n);
  rep(i, n) cin >> hs[i];
  vector<ll> as(m);
  vector<ll> bs(m);
  rep(i, m)
  {
    cin >> as[i] >> bs[i];
  }

  map<ll, set<int>> map;
  rep(i, m)
  {
    ll a = as[i];
    ll b = bs[i];
    if (map.count(a))
    {
      map[a].insert(b);
    }
    else
    {
      set<int> s;
      s.insert(b);
      map[a] = s;
    }
    if (map.count(b))
    {
      map[b].insert(a);
    }
    else
    {
      set<int> s;
      s.insert(a);
      map[b] = s;
    }
  }


  ll ans = 0;
  for( auto i = map.begin(); i != map.end() ; ++i ) {
    ll start = i->first;
    set<int> set = i->second;
    ll startHeight = hs[start-1];
    bool ok = true;
    for (auto itr = set.begin(); itr != set.end(); ++itr) {
        ll aite = *itr;
        ll aiteHeight = hs[aite-1];
        if (startHeight <= aiteHeight) {
          ok = false;
          break;
        }
    }
    if (ok) ans++;
  }

  ans += n - map.size();

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


Measured memory_bytes: 23064
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	cout << fixed << setprecision(10);
	for (int n, w; cin >> n >> w&&n;) {
		vector<double> cnt(11, 0);
		vector<int> v(n); rep(i, 0, n) {
			cin >> v[i];
			cnt[v[i] / w]++;
		}
		int W = *max_element(begin(v), end(v)) / w;
		double max_cnt = *max_element(begin(cnt), end(cnt));
		double ans = 0.01;
		rep(i, 0, W)
			ans += (cnt[i] / max_cnt)*((double)(W - i) / W);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3236
from sys import stdin
from itertools import permutations
inf = 10**10
n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
lin = [[0 for i in range(n)]for j in range(n)]
for i in li:
    lin[i[0]-1][i[1]-1] = 1
    lin[i[1]-1][i[0]-1] = 1
def all_pairs_shortest_paths(W):
    n = len(W)
    res = [[0] * n for i in range(n)]
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res
lis = all_pairs_shortest_paths(lin)
liv = [i+1 for i in range(n-1)]
liv = list(permutations(liv))
count = 0
for i in liv:
    keiro = list(i)
    flag = 0
    now = 0
    for j in keiro:
        if lis[now][j] == inf or lis[now][j] != 1:
            flag = 1
        now = j
    if flag == 0:
        count += 1
print(count)

Measured memory_bytes: 3572
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  static int n;
  static int[] x, y;

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

    n = sc.nextInt();
    x = new int[n];
    y = new int[n];
    for(int i = 0; i < n; i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }

    Pair[] xp = new Pair[n];
    Pair[] yp = new Pair[n];
    for(int i = 0; i < n; i++){
      xp[i] = new Pair(x[i], i);
      yp[i] = new Pair(y[i], i);
    }

    Arrays.sort(xp);
    Arrays.sort(yp);

    Edge[] edges = new Edge[n - 1 + n - 1];
    int sp = 0;
    for(int i = 0; i < n - 1; i++){
      edges[i] = new Edge(
        xp[i].index, xp[i + 1].index, xp[i + 1].value - xp[i].value);
    }
    for(int i = 0; i < n - 1; i++){
      edges[i + n - 1] = new Edge(
        yp[i].index, yp[i + 1].index, yp[i + 1].value - yp[i].value);
    }
    Arrays.sort(edges);

    UnionFindTree uf = new UnionFindTree(n);
    long sum = 0;
    for(int i = 0; i < edges.length; i++){
      Edge e = edges[i];
      if(!uf.isSame(e.v, e.w)){
        uf.union(e.v, e.w);
        sum += e.value;
      }
    }

    System.out.println(sum);
  }

  static class Pair implements Comparable< Pair >{
    int value;
    int index;

    Pair(int value, int index){
      this.value = value;
      this.index = index;
    }

    @Override
      public int compareTo(Pair p){
        if(value == p.value){
          return Integer.compare(index, p.index);
        }
        return Integer.compare(value, p.value);
      }

    @Override
      public boolean equals(Object obj){
        if(!(obj instanceof Pair)){
          return false;
        }
        Pair p = (Pair)obj;
        return value == p.value && index == p.index;
      }
  }

  static class Edge implements Comparable< Edge >{
    int v, w;
    int value;

    Edge(int v, int w, int value){
      this.v = v;
      this.w = w;
      this.value = value;
    }

    @Override
      public int compareTo(Edge e){
        return Integer.compare(value, e.value);
      }

    @Override
      public boolean equals(Object obj){
        if(!(obj instanceof Edge)){
          return false;
        }
        Edge e = (Edge)obj;
        return (value == e.value) &&
          (v == e.v && w == e.w) ||
          (w == e.v && v == e.w);
      }
  }
}

class UnionFindTree {
  private int N;
  private int[] root, rank;

  public UnionFindTree(int n){
    this.N = n;
    this.root = new int[N];
    this.rank = new int[N];
    for(int i = 0; i < root.length; i++){
      root[i] = i;
    }
  }

  public void union(int v, int w){
    int vr = root(v), wr = root(w);
    if(vr == wr){
      return;
    }
    if(rank[vr] < rank[wr]){
      root[vr] = wr;
    }
    else{
      root[wr] = vr;
      if(rank[vr] == rank[wr]){
        ++rank[vr];
      }
    }
  }

  public int root(int v){
    if(root[v] == v){
      return v;
    }
    return root[v] = root(root[v]);
  }

  public boolean isSame(int v, int w){
    return root(v) == root(w);
  }
}


Measured memory_bytes: 99920
/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/

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

/*
use these format of input when number of inputs not provided
while(scanf("%lld",&n)!=EOF)
*/

#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< ll , ll >
#define vpii vector< pii >
#define mii unordered_map< ll , ll >
#define mci map< char , ll >
#define pq priority_queue
#define str string
#define len length()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl cout <<  endl
#define sp " "
#define all(ar) ar.begin(), ar.end()
#define itern(n) for (int i=0; i<n; i++)
#define ritern(n) for (int i=n-1; i>=0; i--)
#define sz(x) ((int)(x).size())
#define pi acos(1);                   /* pi */
#define inf (int(1e9+7))
#define fl(x) int(x)
#define mod %(inf)
#define yes "YES"
#define no "NO"
//debugger
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
//functions
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}


//#------------------------------complete template------------------------------#//


int main()
{
	fast;
	int n;
	cin >> n;
	vi a(n);
	int cnt=0;
	ll sum=0;
	ll sub=INT_MAX;
	itern(n){
		cin >> a[i];
		if (a[i]<0)cnt++;
		a[i]=abs(a[i]);
		sum+=a[i];
		sub=min(a[i],sub);
	}
	if(cnt%2)sum-=2*sub;
	cout << sum;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static String input=sc.nextLine();
	private static ArrayList<String> result=new ArrayList<String>();
	public static void main(String[] args){
		for(int i=0;i<input.length();i++){
			char c=exchanger(input.charAt(i));
			result.add(String.valueOf(c));
		}
		for(int i=0;i<result.size();i++){
			System.out.print(result.get(i));
		}
		System.out.println("");
	}
	private static char exchanger(char x){
		if(Character.isUpperCase(x)) return Character.toLowerCase(x);
		if(Character.isLowerCase(x)) return Character.toUpperCase(x);
		else return x;
	}
}

Measured memory_bytes: 26848
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner((System.in));
		char[] o = sc.next().toCharArray();
		char[] e = sc.next().toCharArray();
		sc.close();
		if( o.length == e.length) {
			for(int i = 0; i < o.length; i++) {
				System.out.print(o[i] + "" + e[i]);
			}
			System.out.println("");
		}else {
			for(int i = 0; i < e.length; i++) {
				System.out.print(o[i] + "" + e[i]);
			}
			System.out.println(o[o.length-1]);
		}
	}
}

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

int main() {
  int K; cin >> K;
  
  queue<ll> que;
  vector<ll> lunlun(100010);
  for (int i = 1; i <= 9; i++) {
    que.push(i);
  }
  
  ll x = 0;
  while (x != 100010) {
    ll i = que.front();
   
    ll r = i % 10;
    if (r == 0) {
      que.push(10 * i + r);
      que.push(10 * i + r + 1);
    }
    else if (r == 9) {
      que.push(10 * i + r - 1);
      que.push(10 * i + r);
    }
    else {
      que.push(10 * i + r - 1);
      que.push(10 * i + r);
      que.push(10 * i + r + 1);
    }
    
    lunlun.at(x) = que.front();
    x++;
    que.pop();
  }
  cout << lunlun.at(K-1) << endl;
}

Measured memory_bytes: 2560
class MakingTriangle
  def initialize(n, al)
    @n = n
    @al = al
  end

  def solve
    ans = 0
    
    (0 .. @n-3).each do |i|
      (i+1 .. @n-2).each do |j|
        (j+1 .. @n-1).each do |k|
          if @al[i] < @al[j] && @al[j] < @al[k] && @al[i] + @al[j] > @al[k]
            ans += 1
          end
        end
      end
    end
    
    ans
  end
end

def run
  n = gets.chomp.to_i
  al = gets.split(/\s+/).map(&:to_i)
  al.sort!

  puts MakingTriangle.new(n, al).solve
end

run


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define LLFOR(i, a, b) for(long long i = (a); i < (b); ++i)
#define LLRFOR(i, a, b) for(long long i = (a); i >= (b); i--)
#define SORT(v, n) sort(v, v+n)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define LLREP(i, n) for(long long i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)
#define LLRREP(i, n) for(long long i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T MAX(T a,T b){if(a>b){return a;}return b;}
template <typename T>
inline T MIN(T a,T b){if(a<b){return a;}return b;}
template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
   ios::sync_with_stdio(false);
   
   int n, d[100];
   vector<int> v;
   cin >> n;
   REP(i, n) cin >> d[i];

   REP(i, n){
      bool dabu = false;
      if(v.empty()) v.pb(d[i]);
      else{
         REP(j, v.size()){
            if(d[i] == v.at(j)){
               dabu = true;
               break;
            }
         }
         if(dabu == false) v.pb(d[i]);
      }
   }

   cout << v.size() << endl;

	rtn 0;
}

Measured memory_bytes: 256
import math

k = int(input())
x, y = map(int, input().split())

if k % 2 == 0 and (x + y) % 2 == 1:
    print(-1)
    exit()

a = 1
b = 1
d = 0
if x < 0:
    x *= -1
    a = -1
if y < 0:
    y *= -1
    b = -1
if x < y:
    d = 1
    x, y = y, x

def show_xy(tx, ty):
    if d == 1:
        print(ty * a, tx * b)
    else:
        print(tx * a, ty * b)

if x + y < k and (x + y) % 2 == 1:
    print(3)
    temp_x = x
    temp_y = x - k
    show_xy(temp_x, temp_y)
    temp_x = x + (k+x-y)//2
    temp_y += k - (k+x-y)//2
    show_xy(temp_x, temp_y)
    temp_x = x
    temp_y = y
    show_xy(temp_x, temp_y)
    exit()

c = (k - ((x + y) % k)) % k
if x + y < k:
    n = 2
else:
    n = math.ceil((x + y) / k) + (c % 2)

print(n)

ans = 0
temp_x = 0
temp_y = 0

temp = - (k * n - x - y) // 2
while 1:
    temp_y -= k
    if temp_y >=  temp:
        show_xy(temp_x, temp_y)
    else:
        temp_x = temp - temp_y
        temp_y = temp
        #print(temp_x * a, temp_y * b)
        break

while temp_x <= x:
    show_xy(temp_x, temp_y)
    temp_x += k

temp_y += temp_x - x
temp_x = x

while temp_y <= y:
    show_xy(temp_x, temp_y)
    temp_y += k


Measured memory_bytes: 5588
Q = 10**9+7
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

def getFactorialInv(N):
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    ret = [1]*(N+1)
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
        ret[i] = ret[i-1]*inv[i] % Q
    return ret

def getFactorial(N):
    ret = [1]*(N+1)
    for i in range(2,N+1):
        ret[i] = ret[i-1]*i%Q
    return ret

def main():
    n, k = map( int, input().split())
    fact = getFactorial(n)
    invfact = getFactorialInv(n)
    if k >= n-1:
        ans = 1
        for i in range(1,n*2):
            ans *= i
            ans %= Q
        print( ans*invfact[n-1]%Q*invfact[n]%Q)
        return
    ans = 0
    for i in range(k+1):
        ans += fact[n]*invfact[i]%Q*invfact[n-i]%Q*fact[n-1]%Q*invfact[i]%Q*invfact[n-1-i]%Q
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

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

const int mod = 1000000007;

int main(){
    int n; cin >> n;
    ll ans = 1;
    for(int i = 1; i <= n; i++){
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, H, W;

void solve() {
	cin >> N >> H >> W;
	cout << (N - H + 1) * (N - W + 1) << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
object Main {
    def main(args:Array[String]) = {
        val dp = Array.ofDim[Int](4001)
        val elem = Array.tabulate(4001)(_ => 1)
        for(k <- 1 to 3) {
            for(i <- 0 to k * 1000) {
                for(j <- 0 to 1000) {
                    dp(i + j) += elem(i)
                }
            }
            for(i <- 0 to (k + 1) * 1000) {
                elem(i) = dp(i)
                dp(i) = 0
            }
        }
        val sc = new java.util.Scanner(System.in)
        while(sc.hasNextInt) {
            val n = sc.nextInt
            println(elem(n))
        }
    }
}

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


#define SUCCESS NULL
#define MAX_N 1000
char vertical[ MAX_N +1 ][ MAX_N +1 ] ;
char horizontal[ MAX_N +1 ][ MAX_N +1 ] ;

int C ,N ;
int IsSucceed( char ( *dat )[ MAX_N +1 ] )
{
	int ret = SUCCESS ;
	int head = 1 ,tail = N ;
	while( (ret = strcmp( dat[ head++ ] +1 ,dat[ tail-- ] +1 )) == SUCCESS && head < tail ) ;

	return (ret == SUCCESS) ;
}


int main( void )
{
	scanf( "%d %d" ,&C ,&N ) ;

	int i ,j ;
	for( i = 1 ; i <= N ; ++i )
	{
		scanf( "%s" ,horizontal[ i ] +1 ) ;
	}

	for( i = 1 ; i <= N ; ++i )
	{
		for( j = 1 ; j <= N ; ++j )
		{
			vertical[ i ][ j ] = horizontal[ j ][ i ] ;
		}
	}

	int c ;
	int y ,x ;

	int ans = IsSucceed( vertical ) & IsSucceed( horizontal ) ;
	for( i = 1 ; i < C ; ++i )
	{
		scanf( "%d" ,&c ) ;
		for( j = 0 ; j < c ; ++j )
		{
			scanf( "%d %d" ,&y ,&x ) ;

			vertical[ x ][ y ] = vertical[ x ][ y ] == '0' ? '1' : '0' ;
			horizontal[ y ][ x ] = horizontal[ y ][ x ] == '0' ? '1' : '0' ;
		}

		ans += IsSucceed( vertical ) & IsSucceed( horizontal ) ;
	}

	printf( "%d\n" ,ans ) ;

	return 0 ;
}


Measured memory_bytes: 3768