akhauriyash/Code-Regression huggingface dataset:
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


ll n;
vector<pll> stp;
vector<vector<char>> A(4,vector<char>(4));

bool same(ll a,ll h,ll w,ll num){
    char c=0;
    for(ll i=max(h,0LL);i<4 && i-h<stp[num].F;i++){
        for(ll t=max(w,0LL);t<4 && t-w<stp[num].S;t++){
            if(a>>(i*4+t)&1){continue;}
            if(c==0){
                c=A[i][t];
            }
            else if(c!=A[i][t]){return false;}
        }
    }
    return true;
}

ll put(ll a,ll h,ll w,ll num){
    for(ll i=max(h,0LL);i<4 && i-h<stp[num].F;i++){
        for(ll t=max(w,0LL);t<4 && t-w<stp[num].S;t++){
            a|=1LL<<(i*4+t);
        }
    }
    return a;
}


int main(){
    cin>>n;
    stp.resize(n);
    for(auto &i:stp){cin>>i.F>>i.S;}
    for(auto &i:A){
        for(auto &t:i){cin>>t;}
    }
    vector<ll> dp(1LL<<16,E);
    queue<ll> Q;
    dp[0]=0;
    Q.push(0);
    while(!Q.empty()){
        ll W=Q.front();
        Q.pop();
        for(int i=0;i<n;i++){
            for(int h=-3;h<4;h++){
                for(int w=-3;w<4;w++){
                    ll next=put(W,h,w,i);
                    if(dp[next]==E && same(W,h,w,i)){
                        if(next==(1LL<<16)-1){cout<<dp[W]+1<<endl; return 0;}
                        dp[next]=dp[W]+1;
                        Q.push(next);
                    }
                }
            }
        }
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3668
import java.util.*
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val ab = (1..n).map { Pair(sc.nextInt(), sc.nextInt()) }
    val cd = (1..m).map { Pair(sc.nextInt(), sc.nextInt()) }
    for (abP in ab) {
        println(cd.mapIndexed { idx, cdP -> Pair(dist(abP, cdP), idx + 1) }
            .minWith(compareBy({it.first}, {it.second}))!!.second)
    }
}

fun dist(a: Pair<Int, Int>, b: Pair<Int, Int>): Int {
    return Math.abs(a.first - b.first) + Math.abs(a.second - b.second)
}


Measured memory_bytes: 31768
#include<stdio.h>
#include<string.h>
int main()
{
     char s[11],t[12];
     scanf("%s",&s);
      scanf("%s",&t);
     int l1=strlen(s),l2=strlen(t),c=0;
        for(int i=0;i<l1;i++){
             if(s[i]==t[i])
        c++;}

     if(c==l1)
          printf("Yes\n");
     else
          printf("No\n");
}


Measured memory_bytes: 1616
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <ctime>

using namespace std;

const int MAXN = 200000 + 10;

long long n;
char s[MAXN];
long long pos[MAXN];

void Work()
{
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; s[i]; i ++)
		pos[s[i] - 'a'] ++;

	long long ans = (n * (n - 1)) / 2LL;
	for (int i = 0; i < 26; i ++)
		ans -= pos[i] * (pos[i] - 1) / 2LL;

	printf("%lld\n", ans + 1);
}

int main()
{
	Work();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[5],n;
    cin>>n;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    int x=*(min_element(a,a+5));
    int ans=n/x;
    if(n%x==0){
        ans-=1;
    }
    ans+=5;
    cout<<ans<<endl;
 
    return 0;
    
}
 

Measured memory_bytes: 256
# encoding: utf-8
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

given = []
giving = []
for Ai, Bi in zip(A, B):
    if Ai < Bi: given.append(Bi - Ai)
    else: giving.append(Ai - Bi)

cost = sum(given)
if cost < 1:
    print(0)
else:
    ans = len(given)
    giving.sort(key=lambda x: -x)
    for Xi in giving:
        # print('#', Xi)
        ans += 1
        cost -= Xi
        if cost <= 0:
            print(ans)
            break
        else: continue
    else:
        print(-1)

Measured memory_bytes: 18292
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
int a;
int b;
int c;
void solve(){
    int ans=0;
    while(ans<c){
        b-=a;
        if(b<0) break;
        ans++;
    }
    cout<<ans<<'\n';
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b>>c;
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

const double PI = 3.14159265358;

double to_radian(double k) {
    return k * PI / 180.0;
}

double get_dist(double ax, double ay, double bx, double by) {
    double dx = ax - bx;
    double dy = ay - by;
    return sqrt(dx * dx + dy * dy);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    // cout << sin(90 * 180 / PI) << endl;
    double hk = 1 / 12.0 * 360;
    double mk = 1 / 60.0 * hk;
    double ay = a * sin(to_radian(h * hk + m * mk));
    double ax = a * cos(to_radian(h * hk + m * mk));
    mk = 1 / 60.0 * 360;
    double by = b * sin(to_radian(mk * m));
    double bx = b * cos(to_radian(mk * m));
    // cout << sin(to_radian(90)) << endl;
    // cout << 1.41421356 * sin(to_radian(45)) << endl;
    printf("%.10f\n", get_dist(ax, ay, bx, by));
    return 0;
}


Measured memory_bytes: 4084
import java.util.Scanner;

public class Main {

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

	void solve() {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		sc.close();
		System.out.println(a==b&&b==c?"Yes":"No");
	}

}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        HashSet<String> in;
        in = new HashSet<>();
        int count = Integer.parseInt(reader.readLine());
        for (int i = 0; i < count; i++) {
            String number = reader.readLine();
            if (in.contains(number)) {
                in.remove(number);
            } else {
                in.add(number);
            }
        }
        System.out.println(in.size());
    }
}

Measured memory_bytes: 32852
#include <iostream>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	int mat[100][100] = {};
	int vec[100] = {};

	int i, j, k;
	for(i = 0; i < n; ++i){
		for(j = 0; j < m; ++j){
			cin >> mat[i][j];
		}
	}

	for(i = 0; i < m; ++i)
		cin >> vec[i];

	for(i = 0; i < n; ++i){
		int t = 0;
		for(j = 0; j < m; ++j){
			t += mat[i][j] * vec[j];
		}
		cout << t << "\n";
	}

	return 0;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	int h[n];
	for(int i = 0;i<n;i++){
		cin >> h[i];
	}
	sort(h,h+n);
	if(k>=n){
		cout << 0 << endl;
	}else{
		int i = n-1;
		for(k=k;k>0;k--){
			h[i] = 0;
			i--;
		}
		unsigned long long sum = 0;
		for(i = 0;i<n;i++){
			sum += h[i];
		}
		
		cout << sum << endl;
	}
}

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

int main(){
    long long x,y;
    cin >> x >> y;
    long long ans=LLONG_MAX;

    //反転0
    if(x<=y) ans=min(ans,y-x);
    //最初に反転しておわり
    if(-x<=y) ans=min(ans,1+y-(-x));
    //2回とも反転
    if(-x<=-y) ans=min(ans,2+(-y)-(-x));
    //最後だけ反転
    if(x<=-y) ans=min(ans,1+(-y)-x);

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

Measured memory_bytes: 3580
n = int(input())

num =[[[0 for i in range(10)] for i in range(3)] for i in range(4)]

for i in range(n):
  b,f,r,v = map(int, input().split())
  num[b-1][f-1][r-1] += v

x = 0

for i in range(4):
  if x!=0:
    print('#'*20)
  x += 1
  
  for b in range(3):
    for f in range(10):
      print(' %d'%(num[i][b][f]), end ='')
    print()


Measured memory_bytes: 5620
import java.util.Scanner;

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

		double ret = getProcess(R);

		System.out.println(ret);
	}

	public static double getProcess(int R){
		double ret = 2 * Math.PI * R ;

		return ret;
	}


}

Measured memory_bytes: 27140
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<long long> v1, v2;
	int n, i, v;
	cin >> n;
	for (i = 0; i <= n; i++) {
		cin >> v;
		v1.push_back(v);
	}
	for (i = 0; i < n; i++) {
		cin >> v;
		v2.push_back(v);
	}
	long long ans = 0;
	for (i = 0; i <= n; i++) {
		if (i && v1[i] > 0) {
			if (v1[i] <= v2[i - 1]) {
				v2[i - 1] -= v1[i];
				ans += v1[i];
				v1[i] = 0;
			}
			else {
				v1[i] -= v2[i - 1];
				ans += v2[i - 1];
				v2[i - 1] = 0;
			}
		}
		if (v1[i] > 0 && i < n) {
			if (v1[i] <= v2[i]) {
				v2[i] -= v1[i];
				ans += v1[i];
				v1[i] = 0;
			}
			else {
				v1[i] -= v2[i];
				ans += v2[i];
				v2[i] = 0;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2548
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
 
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
const string sp = " ";
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }
 
int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}
 
int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}
 
int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}
 
int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}
 
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
 
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
 
bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}
 
map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n, x, ans;
int a[100010];
signed main() {
  scanf("%lld %lld", &n, &x);
  rep(i, n) {
    scanf("%lld", &a[i]);
  }
  if(x < a[0]) {
    ans += a[0] - x;
    a[0] = x;
  }
  rep(i, n - 1) {
    if(x < a[i] + a[i + 1]) {
      ans += a[i] + a[i + 1] - x;
      a[i + 1] = x - a[i];
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A,B,C;
    cin >> A >> B >> C;
    if (A[A.length()-1] == B[0] && B[B.length()-1] == C[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int cnt=0;
  for(int i=0;i<n;i++){
    int h;
    cin >> h;
    if(h>=k){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] k = new int[n][m];
		//input
		for(int i = 0; i < k.length; i++){
			int tmp = sc.nextInt();
			for(int j = 0; j < tmp; j++){
				k[i][sc.nextInt()-1] = 1;
			}
		}
		int outp=0;
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				if(k[j][i] == 0){
					break;
				}else if(j == k.length-1){
					outp++;
				}
			}
		}
		System.out.println(outp);
	}
}

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

using namespace std;
int mod = 10007;
int n;
int dp[1003][30];
char s[1003];
int calc(char tmp){
	int res=2;
	if(tmp == 'J'){
		res = 0;
	}else if(tmp == 'O'){
		res = 1;
	}
	return res;
}
int main(){
	cin >> n >> s;
	int ch = calc(s[0]);
	for(int i = 1;i < 8;i++){
		if(i & 1 && i >> ch&1)dp[0][i] = 1;
		//cout << i << ":" << dp[0][i] << " ";
	}

	for(int i = 1;i < n;i++){
		int z = calc(s[i]);
		for(int j = 1;j < 8;j++){
			if((j >> z&1)==0)continue;
			for(int k = 1;k < 8;k++){
				for(int l = 0;l < 3;l++){
					if(k >> l & 1 && j >> l & 1)goto ok;
				}
				continue;
				ok:
				;
				dp[i][j] += dp[i-1][k];
				dp[i][j] %= mod;

			}
		}
	}
	int ans = 0;
	for(int i = 1;i < 8;i++){
		ans += dp[n-1][i];
		ans %= mod;
	}
	cout << ans%mod << endl;
	return 0;
}


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



int main()
{
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    while(!s.empty()){
        bool flag=false;
        if(s.substr(0,5)=="maerd"){
            flag=true;
            s.erase(0,5);
            continue;

        }
        if(s.substr(0,7)=="remaerd"){
            flag=true;
            s.erase(0,7);
            continue;
        }
        if(s.substr(0,5)=="esare"){
            flag=true;
            s.erase(0,5);
            continue;
        }
        if(s.substr(0,6)=="resare"){
            flag=true;
            s.erase(0,6);
            continue;
        }
        if(!flag)break;
    }
    if(s.empty())
        cout<<"YES";
    else
        cout<<"NO";



}


Measured memory_bytes: 512
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}
int main(void){
	int n=nextint();
	int k=nextint();
	int d=nextint();
	int ans=0;
	for(int i=n; i<=k; i++){
		if(i%d==0) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1584
import math
a,b,x = map(int,input().split())
max = a * a * b
if x > max/2 :
    p = max - x
    y = p / (a*a) * 2
    print(math.degrees(math.atan(y/a)))
else:
    y = x  / (a*b) * 2
    print(math.degrees(math.atan(b/y)))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int T = scanner.nextInt();
    int n = T / A;
    System.out.println(B * n);
  }
}


Measured memory_bytes: 21844
def C():
    nk=list(map(int,input().split()))
    
    abs_val=abs(nk[0]-nk[1])
    
    while True:
        if abs_val>nk[1]:
            abs_val=abs_val%nk[1]
        elif abs_val<nk[1]:
            abs_val=min(abs_val,abs(abs_val-nk[1]))
            break
        else :
            # 0
            abs_val=abs_val-nk[1]
            break
    
    print(min(abs_val,nk[0]))
    
    
    
if __name__=='__main__':
    C()


Measured memory_bytes: 3060
from sys import stdin


def main() -> None:
    n = int(next_str())
    ans = 0
    for i in range(n):
        l, r = map(int, input().split())
        ans += r - l + 1
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;


const string MINUS_INF="-"; 
const ll m[] = {-123,2,5,5,4,5,6,3,7,6};
string dp[100000];

void chmax(string &a, string b){
    if (a==MINUS_INF)
        a=b;
    else if (a.size() < b.size())
        a=b;
    else if (a.size() == b.size() && a<b){
        a=b;
    }
}
signed main() {
    ll N,M;
    cin>>N>>M;
    vector<ll> A(M);
    rep(i,0,M) cin>>A[i];
    rep(i,0,100000) dp[i]=MINUS_INF;
    dp[0]="";
    rep(i,0,N){
        if (dp[i]==MINUS_INF)
            continue;
        for(auto a: A){
            chmax(dp[i+m[a]], dp[i] + (char)('0'+a));
        }
    }
    cout<<dp[N]<<endl;
    return 0;
}


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

using namespace std;
int main(){

    int n,flg,tmp,a,b;

    cin >> n;

    vector<int> arr(n);
    vector<int> arrP(n);
    vector<int> arrQ(n);

    for(int i=0;i<n;i++) arr.at(i) = i+1; 
    for(int i=0;i<n;i++) cin >> arrP[i];
    for(int i=0;i<n;i++) cin >> arrQ[i];

    tmp = 1;

    do{
        if(arr==arrP) a = tmp;
        if(arr==arrQ) b = tmp;
        tmp += 1;
        
    }while(next_permutation(arr.begin(),arr.end()));

    cout << abs(a-b) << endl;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()
s = s.replace('BC', 'D')

a_num = 0
ans = 0
for c in s:
    if c == 'A':
        a_num += 1
    elif c == 'D':
        ans += a_num
    else:
        a_num = 0

print(ans)


Measured memory_bytes: 3500
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc =new Scanner(System.in);
        
        int ab = sc.nextInt();
        int bc = sc.nextInt();
        int ca = sc.nextInt();
        int cal = (ab * bc) /2;

        System.out.println(cal);
    }
}


Measured memory_bytes: 21844
N, M = map(int, input().split())
drink = []
for _ in range(N):
    A, B = map(int, input().split())
    drink.append([A, B])

drink = sorted(drink)
money = 0
for a, b in drink:
    if b > M:
        money += a * M
        break
    else:
        money += a * b
        M -= b
print(money)

Measured memory_bytes: 20832
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin >> n >> k;
    vl p,m;
    rep(i,n){
        ll x;
        cin >> x;
        if(x>=0){
            p.pb(x);
        }
        else{
            m.pb(x);
        }
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    sort(m.begin(),m.end());
    ll ans=1;
    if(n==k){
        rep(i,p.size()){
            ans*=p[i];
            ans%=MOD;
        }
        rep(i,m.size()){
            ans*=m[i];
            ans%=MOD;
        }
        cout << (MOD+ans)%MOD << endl;
        return 0;
    }
    if(p.size()==0){
        if(k%2==0){
            rep(i,k){
                ans*=m[i];
                ans%=MOD;
            }
        }
        if(k%2==1){
            rep(i,k){
                ans*=m[m.size()-i-1];
                ans%=MOD;
            }
        }
        cout << (MOD+ans)%MOD << endl;
        return 0;
    }
    ll i=0;
    if(k%2==1){
        ans*=p[0];
        i=1;
    }
    vl np,nm;
    while(i+1<p.size()){
        np.pb(p[i]*p[i+1]);
        i+=2;
    }
    np.pb(0);
    i=0;
    while(i+1<m.size()){
        nm.pb(m[i]*m[i+1]);
        i+=2;
    }
    nm.pb(0);
    k/=2;
    ll s=0,t=0;
    rep(i,k){
        ans*=max(np[s],nm[t])%MOD;
        if(np[s]>nm[t]){
            s++;
        }
        else{
            t++;
        }
        ans%=MOD;
    }
    cout << ans << endl;
}

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

int ans[2010][50];

int main() {
	int K=38;
	int N=K*(K-1)+1;
	cout << N << ' ' << K << endl;
	for(int i=0; i<K; ++i){
		ans[i][0]=N;
		for(int j=1; j<K; ++j) ans[i][j]=i*(K-1)+j;
	}
	for(int p=1; p<K; ++p){
		for(int i=1; i<K; ++i){
			ans[p*(K-1)+i][0]=p;
			for(int j=1; j<K; ++j){
				ans[p*(K-1)+i][j]=ans[j][(i+(j-1)*(p-1))%(K-1)+1];
			}
		}
	}
	for(int i=0; i<N; ++i){
		cout << ans[i][0];
		for(int j=1; j<K; ++j) cout << ' ' << ans[i][j];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  int x, a, b, lal, lbl;
  scanf("%d %d %d", &x, &a, &b);
  lal = abs(a - x);
  lbl = abs(b - x);
  if (lal < lbl)
    printf("A\n");
  else
    printf("B\n");
  return 0;
}

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

long long MOD = 1000000007;

long long Calc(long long A, long long B) {
	if (B == 0) return 1;
	if (B % 2 == 0) {
		long long C = Calc(A, B / 2);
		return (C * C) % MOD;
	}
	return (A * Calc(A, B - 1)) % MOD;
}

long long GCD(long long A, long long B) {
	return (B == 0 ? A : GCD(B, A % B));
}

int main() {
	long long S, ANS = 0;
	cin >> S;
	long long R = 0, SUM = 0, LD = 0, RD = 0, LM = 1, RM = 1;
	for (int L = 1; L < 100000000; L++) {
		if (L == LM) LD++, LM *= 10;
		while (SUM < S) {
			R++;
			if (R == RM) RD++, RM *= 10;
			SUM += RD;
		}
		if (SUM == S) ANS++;
		SUM -= LD;
	}
	ANS %= MOD;
	for (int i = 1; i * 9 <= S; i++) {
		long long D = S / i;
		if (S % i == 0) {
			ANS += 9 * Calc(10, D - 1) - i + 1 + MOD;
		}
		else {
			ANS++;
		}
	}
	cout << ANS % MOD << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	cin >> N;

	vector<pint> T(N);
	vector<pint> Q(N);

	map<pint, int> mpT, mpQ;

	for (int i = 0; i < N; i++) {
		cin >> T[i].first >> T[i].second;
		Q[i].second = T[i].first;
		Q[i].first = T[i].second;
	}

	sort(all(T));
	sort(Q.begin(), Q.end());
	/*
	for (int i = 1; i < N; i++) {
		pint tmp;
		tmp.first = T[i].first - T[i - 1].first;
		tmp.second = T[i].second - T[i - 1].second;
		mpT[tmp]++;
	}*/

	//
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			pint tmp;
			tmp.first = T[i].first - T[j].first;
			tmp.second = T[i].second - T[j].second;
			mpT[tmp]++;
		}
	}
	//

	int mx = 0;

	for (auto x : mpT) {
		mx = max(mx, x.second);
	}
	/*
	for (int i = 1; i < N; i++) {
		pint tmp;
		tmp.first = Q[i].first - Q[i - 1].first;
		tmp.second = Q[i].second - Q[i - 1].second;
		mpQ[tmp]++;
	}
	*/
	//
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			pint tmp;
			tmp.first = Q[i].first - Q[j].first;
			tmp.second = Q[i].second - Q[j].second;
			mpT[tmp]++;
		}
	}
	//

	for (auto x : mpQ) {
		mx = max(mx, x.second);
	}

	cout << N - mx << endl;

	return 0;
}

Measured memory_bytes: 384
A = list(map(int, input().split()))

m = A[0]
n = A[1]
M = 1000000007

def pos(m, n):
    if n == 0:
        return 1
    res = pos(m * m % M, int(n / 2))
    if n % 2 == 1:
        res *= m
        res = res % M
    return res

r = pos(m, n)
print(r)

Measured memory_bytes: 7740
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,k;
        long sum;
        int[][] A = new int[101][101];
        int[][] B = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<3;i++){
            n[i]=Integer.parseInt(str[i]);   
        }
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                A[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[1];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[2];j++){
                B[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[0];i++){
            for(j=0;j<n[2];j++){
                sum=0;
                for(k=0;k<n[1];k++){
                    sum += B[k][j]*A[i][k];             
                }
                if(j!=0) System.out.print(" ");
                System.out.print(sum);
            }
            System.out.println();
        }      
        System.out.flush();
    }
}

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

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

ans = 0
yoryoku = 0
for i in range(N):
    if yoryoku >= A[i]:
        ans += min(yoryoku, A[i]) # Use yoryoku
        yoryoku = B[i]
    else:
        ans += min(yoryoku + B[i], A[i]) # Use yoryoku + B[i]
        yoryoku = max(B[i] - (A[i] - yoryoku), 0)

ans += min(A[N], yoryoku)
print(ans)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){
    if(b%a==0) return a;
    else return gcd(b%a,a);
}
ll p[10000];
ll pp=0;
map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(ll i=2;i*i<=n;i++){
        bool w=true;
        while(n%i==0){
            res[i]++;
            n=n/i;
            if(w){
                w=false;
                p[pp]=i;
                pp++;
            }
        }
    }
    if(n!=1){
        res[n]=1;
        p[pp]=n;
        pp++;
    }
    return res;
}
int main(void){
    ll a,b;
    cin>>a>>b;
    ll g=gcd(a,b);
    map<ll,ll> M=prime_factor(g);
    cout<<pp+1<<endl;
    
}


Measured memory_bytes: 3588
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)
#define PI 3.14159265358979323846264338327950L
#define MOD 1e9+7

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
} 

int main(){
    go(); 

    // code here
    int n;cin>>n;
    map<int,int> mp;
    forn(0,n-1,1){
        int inp;cin>>inp;
        mp[inp-1]++;
    }
    forn(0,n,1){
        cout<<mp[i]<<endl;
    }

    
} 



Measured memory_bytes: 13012
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	double s;
	cin>>s;
	cout<<s*6.28318;
	re 0;
}

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

int main()
{
	string str;
	cin >> str;
	while (str[0] != '0')
	{
		int i, o = 0;
		for (int i = 0; i < str.size(); i++)
		{
			o += str[i] - '0';
		}
		cout << o << endl;
		cin >> str;
	}
	return 0;
}


Measured memory_bytes: 3204
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}
fn main() {
    let N: u64 = read();
    let mut ans: u64 = 0;
    if N % 2 == 1 {
        println!("0");
        return;
    }
    let mut n_tmp = 2;
    loop {
        n_tmp *= 5;
        if n_tmp > N {
            break;
        }
        ans += N / n_tmp;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/*
    Stay motivated and keep working hard
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N, W, maxsum;
const ll INF = 1e15 + 7;
ll dp[107][100007]; // dp[N][V] - min wt for N items equal to value V
// if this min weight is <= W and V is as max as possible that is our answer
ll wt[107], val[107];
bool vis[107][100007];
ll recur(ll n, ll v){
    // base case
    if(v <= 0){
        return 0;
    }
    if(n == N){
        return INF;
    }
    if(vis[n][v]){
        return dp[n][v];
    }
    vis[n][v] = 1;
    return dp[n][v] = min(dp[n][v], min(recur(n+1, v), wt[n] + recur(n+1, v-val[n])));
    // if(v >= val[n]){
    //     return dp[n][v] = min(dp[n][v], min(recur(n+1, v), wt[n] + recur(n+1, v-val[n])));
    // }
    // else{
    //     return dp[n][v] = min(dp[n][v], recur(n+1, v));
    // }
}
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N >> W;
    for(ll i=0;i<N;i++){
        cin >> wt[i] >> val[i];
        maxsum += val[i];
    }
    for(ll i=0;i<=N;i++){
        for(ll j=0;j<=maxsum;j++){
            dp[i][j] = INF;
        }
    }
    // recur(0, maxsum);
    bool flag = false;
    for(ll V = maxsum; V >= 0; V--){
        if(recur(0, V) <= W){
            cout << V << "\n";
            flag = true;
            break;
        }
    }
    if(!flag){
        cout << "0\n";
    }
    // for(ll i=0;i<=N;i++){
    //     for(ll j=0;j<=maxsum;j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }


    return 0;
}


Measured memory_bytes: 90368
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m,s,g1,g2;
int b1[1010],b2[1010],c[1010];
int d[1010][1010];
vector<int> vv;

int main(){
	while(1){
		cin>>n>>m>>s>>g1>>g2;
		if(n==0&&m==0&&s==0&&g1==0&&g2==0)break;
		REP(i,1010)
			REP(j,1010)
				d[i][j]=1e8;
		REP(i,1010)d[i][i]=0;
		REP(i,m){
			cin>>b1[i]>>b2[i]>>c[i];
			d[b1[i]][b2[i]]=c[i];
			//d[b2[i]][b1[i]]=c[i];
		}
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		int ans=INF;
		for(int i=1;i<=n;i++){
			int t=d[s][i]+d[i][g1]+d[i][g2];
			ans=min(ans,t);
		}
		vv.push_back(ans);
	}
	REP(i,vv.size())
		cout<<vv[i]<<endl;
	return 0;
}


Measured memory_bytes: 7076
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
using P = pair<int,int>;
using ll = long long;
constexpr int MOD=998244353;
constexpr int MAX=510000;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    ll ret=0;
    for(int i=0;i<k;i++)ret+=a[i];
    cout<<ret<<endl;
}

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

    long long int num,n,counter=0,index=-1;
    vector<long long int>vec;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        cin>>n;
        if(i==0)
            n-=1;
        vec.push_back(n);
    }
    for(int u=1;u<vec.size();u++)
    {
        if(vec[u]>vec[u-1])
        {
            vec[u]-=1;
        }
        else if(vec[u]<vec[u-1])
            {cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 1400
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
			#define inf 1e9
		    
			#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;


		    bool isprime(int n)
		    {
		        for(int i=2;i*i<=n;i++)
		            if(n%i==0)
		                return false;
		        return true;
		    }
		     
		    bool comp(pair<int,int> a, pair<int,int> b)
		    {
		    	return b.ff < a.ff ;
		    }

		    int modpow(int b,int p,int m)
		    {
		    	if(p==0) return 1%m;
		    	if(p%2) return (b*modpow(b,p-1,m))%m;
		    	int u=modpow(b,p/2,m);
		    	return (u*u)%m;
		    }

		    vector<int> ar[100005];
		    int vis[100005],from[100005];
		    double dis[100005];
		    
		     
		/*    void dikstra(int s,int n)
		    {
		    	forn(i,n+3)
		    	{
		    		dis[i]=inf;
		    		vis[i]=0;
		    		from[i]=-1;
		    	}

		    	dis[s]=0;
		    	priority_queue<pair<int,int>> q;
		    	q.push({0,s});
		    	from[s]=s;

		    	while(!q.empty())
		    	{
		    		pair<int,int> a;
		    		a=q.top();
		    		q.pop();
		    		//cout<<a.ss<<" ";

		    		if(vis[a.ss]) continue;
		    		vis[a.ss]=1;

		    		for(pair<int,int> b:ar[a.ss])
		    		{
		    			if(dis[b.ff]>dis[a.ss] + b.ss)
		    			{
		    				dis[b.ff]=dis[a.ss] + b.ss;
		    				from[b.ff]=a.ss;
		    				q.push({-dis[b.ff],b.ff});
		    			}
		    		}
		    	}
		    }*/


		    int main()
		    {
		    //	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int t=1;
		    	//cin>>t;
		    	
		    	while(t--)
		    	{
		    		int n,m;
		    		cin>>n>>m;

		    		int h[n+1],cnt=0;
		    		map<int,int> mp;

		    		fori(i,1,n)
		    		cin>>h[i];

		    		forn(i,m)
		    		{
		    			int x,y;
		    			cin>>x>>y;

		    			mp[x]=max(mp[x], h[y]);
		    			mp[y]=max(mp[y], h[x]);
		    		}

		    		fori(i,1,n)
		    		{
		    			
		    			if(h[i] > mp[i])
		    			{
		    				cnt++;
		    			//	cout<<i<<" ";
		    			}
		    		}

		    		cout<<cnt;
		    	}

		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP...

Measured memory_bytes: 11216
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL
ll pw(ll a, ll b){
	ll c = 1;
	do{
		if(b&1) c = c * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}while(b);
	return c;
}
ll inv(ll a){
	return pw(a, MOD - 2);
}
#define N 1123456
ll a[N];
ll f[N] = {};

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		scanf("%lld", a+i);
		ll b = a[i];
		for(ll j = 2; j * j <= a[i]; j++){
			ll cnt = 0;
			while(b % j == 0){
				cnt++;
				b /= j;
			}
			LAR(f[j], cnt);
		}
		if(b > 1) LAR(f[b], 1ll);
	}
	ll k = 1;
	REP(i, N){
	 	k = k * pw(i, f[i]) % MOD;
	}
	DEBUG("k = %lld\n", k);
	ll ans = 0;
	REP(i, n) ans = (ans + k * inv(a[i]) ) % MOD;
	printf("%lld\n", ans);
}



Measured memory_bytes: 10240
/**
*    author:  yuya1234
*    created: 13.07.2020 14:29:39
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  int n,m;
  cin>>n>>m;

  int a[m],b[m],ca[200010];
  MEMSET(ca,0);

  vector<int> v;
  
  REP(i,m)
  {
    cin>>a[i]>>b[i];
    if(a[i]==1)v.emplace_back(b[i]);
    if(b[i]==n)ca[a[i]]=1;
  }

  string ans="IMPOSSIBLE";

  REP(i,SZ(v)){
    if(ca[v[i]]==1)ans="POSSIBLE";
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 6052
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
#define p 998244353
using namespace std;
inline ll read(){
    ll x = 0; char zf = 1; char ch = getchar();
    while (ch != '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int i,j,k,m,n,x,y,z,cnt,sum,ans;
int d[100010];
int main(){
	int x=r,y=r,z=r;
	if(x==y&&y==z)puts("Yes");
	else puts("No");
}








Measured memory_bytes: 256
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    S = input()

    """
    反転させる区間は独立であるとしてよい。実際反転させる２区間が左図のように
    オーバーラップしていたとすると、これは右図のように反転させるのと同値だからである：
               _______________                             _______  
        ______|_______        |     --->    ______        |       |
    ___|______|_______|_______|_____    ___|______|_______|_______|_____ 
    
    そうすると安直には0がなるべく長く連続している区間に反転をかけたくなるが、
    長い順に反転をかけた場合1が連続する保証がないのでダメ。

    そこで1の連続する箇所を固定したうえで、そこから0の連続する区間に順番に反転をかけることを考える。
    当然愚直にやるとTLEなので、累積和で実装する
    """

    A = []
    char = S[0]
    cnt = 1
    for i in range(1, N):
        if S[i] == char:
            cnt += 1
        else:
            A.append(cnt)
            char = S[i]
            cnt = 1
    A.append(cnt)
    #print("A={}".format(A))

    B = list(accumulate(A))
    B.append(B[-1])
    #print("B={}".format(B))
    l = len(A)
    if S[0] == '0':
        ans = B[min(K * 2 - 1, l - 1)]
        for i in range(1, l - K * 2 + 1):
            if i % 2 == 0:
                j = i + K * 2 - 1
                val = B[j] - B[i - 1]
            else:
                j = i + K * 2
                val = B[j] - B[i - 1]
            #print("[{}, {}]->val={}".format(i, j, val))
            ans = max(ans, val)
    else:
        ans = B[min(K * 2, l - 1)]
        for i in range(1, l - K * 2 + 1):
            if i % 2 == 1:
                j = i + K * 2 - 1
                val = B[j] - B[i - 1]
            else:
                j = i + K * 2
                val = B[j] - B[i - 1]
            #print("[{}, {}]->val={}".format(i, j, val))
            ans = max(ans, val)
    print(ans)
       


if __name__ == "__main__":
    main()


Measured memory_bytes: 47156
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    int N, X, T;
    io.read(N, X, T);

    int ans = N / X;
    if(N % X != 0) ans++;
    cout << ans * T;

    return 0;
}


Measured memory_bytes: 3632
program ddd
implicit none

integer :: n, i, j, k,  res
integer,allocatable,dimension(:) :: l

read*, n
allocate(l(n))
read*, l

call heapsort(n,l)

res=0

do i=1,n
	do j=i+1, n
    	do k=j+1, n
    		if(l(i)+l(j)>l(k)) then
            	res=res+1
            else
            	exit
            end if
		end do
    end do
end do

write(*,'(i0)') res

end program

subroutine heapsort(n,array)
  implicit none
  
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
 
  integer ::i,k,j,l
  integer :: t
 
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][] a = new int[n+1][n+2];
		for(int i = 0; i < n; i++) {
			String[] str = br.readLine().split(" ");
			int u = Integer.parseInt(str[0]);
			for(int j = 2; j < str.length; j++){
				//a[u][0] = number of visited nodes 
				a[u][j-1] = Integer.parseInt(str[j]);
			}
		}
		
		int[] d = new int[n+1];
		int[] f = new int[n+1];
		int t = 0; // time
		int[] st = new int [n]; // stack
		int p = 0; // stack pointer
		
		for(int i = 1; i <= n; i++){
			if(d[i] != 0){
				continue;
			}
			p = 0;
			st[p] = i; // first node
			
			while(p >= 0){
				int pn = st[p]; // present node
				if(d[pn] == 0){
					t += 1;
					d[pn] = t;
				}
				// nn?????°???????
				int nn;
				do{
					// increase visited num
					a[pn][0] += 1;
					nn = a[pn][a[pn][0]];
				}while(d[nn] != 0);
				
				if(nn != 0){
					// the present node has unvisited adjacent node(s)
					// push the next node to the stack
					p += 1;
					st[p] = nn;
				}else if(f[pn] == 0){
					// does not have
					// write finish time
					t += 1;
					f[pn] = t;
					// pop from the stack
					p -= 1;
				}else{
					p -= 1;
				}
				
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= n; i++){
			sb.append(i + " " + d[i] + " " + f[i] + "\n");
		}
		System.out.print(sb);
	}

}

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

signed main () {
	int n;
	cin >> n;
	vector < int > a(n);
	for (int &x: a)
		cin >> x;
	set < int > b;
	b.insert(0);
	for (int i = 0; i < n; ++i) {
		if (*prev(b.end()) == a[i] - 1)
			b.insert(a[i]);
	}
	if (int(b.size()) == 1)
		cout << "-1\n";
	else
		cout << n - ((int(b.size())) - 1) << '\n';
}


Measured memory_bytes: 10496
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//D

//C

//B

//A
int main() {
	ll r;
	scanf("%lld", &r);

	ll result = r * r;

	printf("%lld\n", result);
}



Measured memory_bytes: 256