akhauriyash/Code-Regression huggingface dataset:
def main():
    mod = 10 ** 9 + 7

    K = map(int, input())
    D = int(input())

    s = 0
    dp = [0] * D
    for k in K:
        ndp = [0] * D
        for d in range(10):
            for i, dpi in enumerate(dp):
                ndp[(i + d) % D] += dpi

        for d in range(k):
            ndp[(s + d) % D] += 1

        s = (s + k) % D
        dp = [x % mod for x in ndp]

    print((dp[0] - (s != 0)) % mod)

main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
const ll LINF = 1e18;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
  int n;
  cin >> n;
  vector<ll> a(n),size(n+1);
  vector<vector<ll>> dp(n,vector<ll>(n,0));

  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  size[0] = 0;
  for(int i=0;i<n;i++){
    size[i+1] = size[i] + a[i];
  }
  for(int i=1;i<n;i++){
    for(int j=0;j<n-i;j++){
      ll min = LINF;
      ll s = size[i+j+1] - size[j];
      for(int k=0;k<i;k++){
        ll cost = s + dp[j][j+k] + dp[j+k+1][i+j];
        if (cost < min) min = cost;
      }
      dp[j][i+j] = min;
    }
  }
  cout << dp[0][n-1] << endl;
  return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += s[i];
	}
	cout << ans << '\n';	
	
	return 0;
}


Measured memory_bytes: 256
def main():
    x = int(input())
    if x < 600:
        print(8)
    elif x < 800:
        print(7)
    elif x < 1000:
        print(6)
    elif x < 1200:
        print(5)
    elif x < 1400:
        print(4)
    elif x < 1600:
        print(3)
    elif x < 1800:
        print(2)
    else:
        print(1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9176
#include <iostream>
#include <stdio.h>
#include <cctype>
using namespace std;
int main(){
	char a;
	
	for(;;){
		scanf("%c",&a);
		/* cin >> a; */
		if(a=='\n'){
			cout << endl;
			break;
		}
		else{
			if( islower(a)){
				printf("%c",toupper(a));
				/*cout <<  (char)toupper(a);*/
			}
			else if(isupper(a)){
				printf("%c",tolower(a));
				/*cout <<  (char)tolower(a);*/
			}
			else{
				printf("%c",a);
				/*cout << a;*/
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1144
S = [list(map(int,input().split()))for i in range(3)]
check = False
for i in range(101):
  for j in range(101):
    if (S[0][0]-i == S[1][0]-j and S[0][1]-i == S[1][1]-j) and S[0][2]-i == S[1][2]-j:
      if (S[2][0]-S[0][0] == S[2][1]-S[0][1])and(S[2][0]-S[0][0] == S[2][2]-S[0][2]):
        check = True
        print('Yes')
        exit()
if check == False: print('No')

Measured memory_bytes: 38512
n,m=map(int,input().split())
if n==1:
    A=[i for i in range(10)]
    for i in range(m):
        _,c=map(int,input().split())
        if not c in A:
            print(-1)
            exit()
        else:A=[c]
    print(min(A))

if n==2:
    A=[[i+1 for i in range(9)] , [i for i in range(10)]]
    for i in range(m):
        t,c=map(int,input().split())
        t=t-1
        if not c in A[t]:
            print(-1)
            exit()
        else: 
            A[t]=[c]
    print(10*min(A[0]) + min(A[1]))

if n==3:
    A=[[i+1 for i in range(9)] ,[i for i in range(10)] ,[i for i in range(10)]]
    for i in range(m):
        t,c=map(int,input().split())
        t=t-1
        if not c in A[t]:
            print(-1)
            exit()
        else: 
            A[t]=[c]
    print(100*min(A[0]) + 10*min(A[1]) + min(A[2]))

Measured memory_bytes: 3064
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+9;
const long double pi=3.14159265358979323846;
void raushan_kumar(){

    /////////////////variables///////////////
    int d=0,e=0,f=0,g=0;
    double f1=0.0,f2=0.0,f3=0.0;
    int flag=0,ans=0,res=0,cnt=0,sum=0;
    /////////////////////////////////////////
    ld n;cin>>n;
    ld k=2*pi*n;
    cout<<k;    
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fast;int t=1;
    //cin>>t;
    while(t--){
        raushan_kumar();
    }

}

Measured memory_bytes: 3820
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    cout << (24 - N) + 24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
#define int ll
signed main(){
        int n; cin>>n;
    int ans=0;
    for(int i=1;i*i<=n;i++){
        cmax(ans,i);
    
    }
    cout<<ans*ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,ans,sum=0;
    cin>>n;
    for(int i=sqrt(n);i>=0;i--)
    {
        if(n%i==0)
        {
            ans=n/i;
            break;
        }
    }
    while(ans)
    {
        sum++;
        ans=ans/10;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 384
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){


    ll N, K;
    cin >> N >> K;
    V v(N);
    rep(i, N)cin >> v[i];
    sort(v.begin(), v.end());
    ll ng = -INF, ok = INF;
    while(ng + 1 < ok){
        ll mid = (ng + ok) / 2;
        ll cnt = 0;
        rep(i, N){
            if(i + 1 == N)continue;
            ll x = v[i];
            if(x < 0){
                if(x * v[i + 1] <= mid)cnt += N - (i + 1);
                else if(x * v[N - 1] > mid);
                else{
                    ll ng2 = i + 1, ok2 = N - 1;
                    while(ng2 + 1 < ok2){
                        ll mid2 = (ng2 + ok2) / 2;
                        if(x * v[mid2] <= mid)ok2 = mid2;
                        else ng2 = mid2;
                    }
                    cnt += N - ok2;
                }
            }
            if(x == 0){
                if(mid >= 0)cnt += N - i - 1;
            }
            if(x > 0){
                if(x * v[i + 1] > mid);
                else if(x * v[N - 1] <= mid)cnt += N - (i + 1);
                else{
                    ll ok2 = i + 1, ng2 = N - 1;
                    while(ok2 + 1 < ng2){
                        ll mid2 = (ok2 + ng2) / 2;
                        if(x * v[mid2] <= mid)ok2 = mid2;
                        else ng2 = mid2;
                    }
                    cnt += ok2 - i;
                }
            }
        }
        if(cnt >= K)ok = mid;
        else ng = mid;
    }
    cout << ok << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator++() { x += 1; return *this;}
  mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
  mint& operator--() { x -= 1; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { mint res(*this); return res+=a; }
  mint operator-(const mint a) const { mint res(*this); return res-=a; }
  mint operator*(const mint a) const { mint res(*this); return res*=a; }
  bool operator==(const int n) const { mint a(n); return this->x == a.x; }
  bool operator==(const ll n) const { mint a(n); return this->x == a.x; }
  bool operator!=(const int n) const { mint a(n); return this->x != a.x; }
  bool operator!=(const ll n) const { mint a(n); return this->x != a.x; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

mint m[101][4][4][4];

mint cnt(int n,int a,int b,int c) {
    if(m[n][a][b][c] != linf) return m[n][a][b][c];
    mint ret = 0;
    rep(i,4) ret += cnt(n-1,i,a,b);
    if(c == 2) {
        if((a == 0 && b == 1) || (a == 1 && b == 0)) ret = 0;
        else if(a == 1 || b == 1) ret -= cnt(n-1,0,a,b);
    } else if(c == 1) {
        if(a == 0 && b == 2) ret = 0;
    }
    m[n][a][b][c] = ret;
    return ret;
}

int main() {
    int n;
    cin >> n;
    rep(i,101) rep(j,4) rep(k,4) rep(l,4) {
        if(i > 3) m[i][j][k][l] = linf;
        else m[i][j][k][l] = 1;
    }
    m[3][0][1][2] = 0;
    m[3][1][0][2] = 0;
    m[3][0][2][1] = 0;
    mint ans = 0;
    rep(i,4) rep(j,4) rep(k,4) {
                ans += cnt(n,i,j,k);
            }
    cout << ans.x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
std::vector<int>A['   '];int N,M,S['   '],B,L,R,I,X;void U(int z,int u){while(z<=N)S[z]+=u,z+=z&-z;}main(){std::cin>>M>>N;for(I=1;I<=M;I++)std::cin>>L>>R,A[R-L+1].push_back(L);for(L=1;L<=N;L++){B=M;for(I=L;I<=N;I+=L){X=I;while(X)B+=S[X],X-=X&-X;}for(int u:A[L])U(u,1),U(u+L,-1),M--;std::cout<<B<<"\n";}}

Measured memory_bytes: 53760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD = 1000000007LL;

void solve(long long N, std::string S){
    map<char, ll> cnt;
    for(int i = 0; i < (int)N; ++i) cnt[S[i]] += 1;
    ll ans = 1;
    for(auto i: cnt){
        //cout << i.first << " " << i.second << endl;;
        (ans *= (i.second + 1)) %= MOD;
    }
    cout << (ans - 1 + MOD) % MOD << endl;
    //cout << (ans - 1) % MOD << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 512
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define mod 1000000007

// int n; 

bool vis[100009];
vector<int> g[100009];

void solve(int x) {
	vis[x] = true;
	for(auto adj: g[x]){
		if(!vis[adj])
			solve(adj);
	}
}

int main(){

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

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

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

	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) {
			ans ++;
			solve(i);
		}
	}

	cout << ans - 1 <<  endl;

	return 0;
}

Measured memory_bytes: 9704
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        for(int i = 0; i < n; i++){
            s[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int t,mid,r,l,cnt=0;
        for(int i = 0; i < q; i++){
            t = sc.nextInt();
            l = 0;
            r = n - 1;
            while ( l <= r ){
                mid = (l + r) / 2;
                if(s[mid] == t) {
                    cnt++;
                    break;
                }
                else if (s[mid] > t) {
                    r = mid - 1;
                }
                else {
                    l = mid + 1;
                }
            }
        }
        System.out.printf("%d%n",cnt);
    }
}



Measured memory_bytes: 81024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include<bitset>
#include <utility>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=1e5+5;
const int MAX_N=MAX;
const ll MOD=998244353;
const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}
int n;
int cnt[MAX],an;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int tem;scanf("%d",&tem);if(tem)cnt[tem-1]++;
        cnt[tem]++;cnt[tem+1]++;
    }
    for(int i=0;i<=100000;i++)an=max(an,cnt[i]);
    printf("%d\n",an);
    return 0;
}


Measured memory_bytes: 640
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

lim = pow(10,18)

if A.count(0):
	print(0)
	exit()

ans = 1
for a in A:
	ans *= a
	if ans > lim:
		print(-1)
		exit()
print(ans)


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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    int N,K,Q;
    int res=1e9+1;

    cin >> N >> K >> Q;
    lint A[2000],B[2001];
    for(int i=0;i<N;i++){
        cin >> A[i];
        B[i]=A[i];
    }
    B[N]=0;

    sort(B,B+N+1);
    for(int t=0;t<=N;t++){
        multiset<int> avail;
        vector<int> cut;
        for(int i=0;i<=N;i++){
            if(i<N && A[i]>B[t]){
                cut.push_back(A[i]);
            }else{
                if(cut.size()>=K){
                    sort(cut.begin(),cut.end());
                    for(int j=0;j<=cut.size()-K;j++) avail.insert(cut[j]);
                }
                cut.clear();
            }
        }
        //cout << avail.size() << endl;
        if(avail.size()>=Q){
            int mi=*avail.begin();
            auto it=avail.begin();
            for(int i=1;i<Q;i++) ++it;

            res=min(res,*it-mi);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(){
  char s[21]={0};
  int i;
  scanf("%s",s);
  for(i=strlen(s)-1;i>=0;i--)printf("%c",s[i]);
  if(s[0]!=0)printf("\n");
  return 0;
}

Measured memory_bytes: 524
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new ABC045().doIt(); //DFS
		new ABC046().doIt();
	}
	class ABC045{
		long ans = 0;
		void doIt(){
			String str = sc.next();
			int length = str.length();
			dfs(str,length,0,0);
			System.out.println(ans);
		}
		void dfs(String str,int length,int Pos,long sum) {
			for(int i = Pos+1;i <= length;i++) {
				long num = Long.parseLong(str.substring(Pos, i));
				dfs(str,length,i,sum + num);
			}
			if(Pos == length) {
				ans = ans + sum;
			}
		}
	}
	class ABC046{
		void doIt(){
			int n = sc.nextInt();
			long T = 1;
			long A = 1;
			for(int i = 0;i < n;i++) {
				long Tn = sc.nextLong();
				long An = sc.nextLong();
				
				long subA = A / An;
				long subT = T / Tn;
				if(A % An > 0)subA++;
				if(T % Tn > 0)subT++;
				A = Math.max(subA, subT)*An;
				T = Math.max(subA, subT)*Tn;
				
			}
			long ans = T + A;
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 27820
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        }
        int count=0;
        for (int i=1;i*i<=n;i++) {
            if (i*i==n) {
                count++;
            }
            for (int j=i;i*i+j*j<=n;j++) {
                if (i*i+j*j==n) {
                    count++;
                }
                for (int k=j;i*i+j*j+k*k<=n;k++) {
                    if (i*i+j*j+k*k==n) {
                        count++;
                    }
                    for (int l=k;i*i+j*j+k*k+l*l<=n;l++) {
                        if (i*i+j*j+k*k+l*l==n) {
                            count++;
                        }
                    }
                }
            }
        }
        cout<<count<<endl;
    }
}


Measured memory_bytes: 3068
N = int(raw_input())
train = [map(int, raw_input().split(' ')) for _ in range(N-1)]

for i in range(N-1):
    c1, s1, f1 = train[i]
    time = s1 + c1
    for j in range(i+1, N-1):
        c2, s2, f2 = train[j]
        next_dept = max(s2, time)
        if next_dept != s2 and time % f2 != 0:
            next_dept += f2 - time % f2
        time = next_dept + c2
    print time
print 0


Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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 main(){
    int N;
    cin>>N;
    vector<int> a(N);
    vector<int> color(9,0);
    rep(i,N) cin>>a.at(i);
    rep(i,N){
        if(1<=a.at(i) && a.at(i)<400){
            color.at(0)++;
        }
        if(400<=a.at(i) && a.at(i)<800){
            color.at(1)++;
        }
        if(800<=a.at(i) && a.at(i)<1200){
            color.at(2)++;
        }
        if(1200<=a.at(i) && a.at(i)<1600){
            color.at(3)++;
        }
        if(1600<=a.at(i) && a.at(i)<2000){
            color.at(4)++;
        }
        if(2000<=a.at(i) && a.at(i)<2400){
            color.at(5)++;
        }
        if(2400<=a.at(i) && a.at(i)<2800){
            color.at(6)++;
        }
        if(2800<=a.at(i) && a.at(i)<3200){
            color.at(7)++;
        }
        if(3200<=a.at(i)){
            color.at(8)++;
        }
    }
    int ans_min=0;
    rep(i,8){
        if(color.at(i)) ans_min++;
    }
    if(ans_min==0) cout<<1<<" "<<color.at(8)<<endl;
    else cout<<ans_min<<" "<<ans_min+color.at(8)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int n,k;
    cin>>n>>k;
    vector<long long>h(n);
    for(int i=0; i<n; i++){
            cin>>h[i];
    }
    sort(h.rbegin(),h.rend());
    long long int sum=0;
    for(int i=k; i<n; i++){
            sum+=h[i];
    }
    cout<< sum <<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define ll long long
#define ls o<<1
#define rs o<<1|1
const int N=200000+10,M=2000+10,inf=0x3f3f3f3f;
const ll P=1e9+7;
int n,a[N],b[N];
ll ans=0,inv2=500000004,fac[9000],ifac[9000],f[4500][4500];
template<class t>void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}

void Mod(ll &x){x=(x>=P)?x-P:x;}
ll C(int x,int y){return (fac[x]*ifac[y]%P)*ifac[x-y]%P;}
ll qpow(ll x,ll y){
	ll ret=1ll;
	while(y){
		if(y&1) ret=ret*x%P;
		x=x*x%P,y>>=1;
	}
	return ret;
}

int main(){
	rd(n);
	for(int i=1;i<=n;++i) rd(a[i]),rd(b[i]),++f[M-a[i]][M-b[i]];
	for(int i=1;i<=(M<<1);++i)
		for(int j=1;j<=(M<<1);++j)
			f[i][j]+=f[i-1][j],Mod(f[i][j]),f[i][j]+=f[i][j-1],Mod(f[i][j]);
	fac[0]=fac[1]=1ll;
	for(int i=2;i<=(M<<2);++i) fac[i]=fac[i-1]*(ll)i%P;
	ifac[M<<2]=qpow(fac[M<<2],P-2);
	for(int i=(M<<2);i;--i) ifac[i-1]=ifac[i]*i%P;
	for(int i=1;i<=n;++i) ans+=f[M+a[i]][M+b[i]],Mod(ans),ans+=(P-C(((a[i]+b[i])<<1),(a[i]<<1))),Mod(ans);
	printf("%lld",ans*inv2%P);
    return 0; 
}

Measured memory_bytes: 145792
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 105;
int a[N];
void solve(){
	int n;
	cin >> n;
	int s = 0;
	fr(i, 1, n){
		cin >> a[i];
		s += a[i];
	}
	s /= n;
	int ans = 1e18, cur = 0;
	fr(i, 1, n){
		cur += (a[i] - s) * (a[i] - s);
	}
	ans = min(ans, cur);
	s++;
	cur = 0;
	fr(i, 1, n){
		cur += (a[i] - s) * (a[i] - s);
	}
	ans = min(ans, cur);
	cout << ans;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

ll a[200005];

int main(){
	int n;
	cin>>n;
	memset(a,0,sizeof(a));
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll res = 0;
	for(int i=1;i<n;i++){
		if(a[i-1] > a[i]){
			res += (1LL * (a[i-1]-a[i]));
//			cout<<res<<endl;
			a[i] += (1LL * (a[i-1]-a[i]));
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 5180
N = int(input())
x = list(map(int,input().split()))
d = [x[i+1]-x[i] for i in range(N-1)]

MOD = 10**9 + 7
def inv(a):
	b = MOD
	u = 1
	v = 0
	while b > 0:
		t = a // b
		a -= t*b
		a,b = b,a
		u -= t*v
		u,v = v,u
	u %= MOD
	return u

facts = [1]
for i in range(1, N+1):
	facts.append((facts[-1] * i) % MOD)

ans = 0
bunshi = 1
bunbo = 1
for i in range(1, N):
	keisu = (facts[N-1] * bunshi * inv(bunbo)) % MOD
	ans = (ans + keisu * d[i-1]) % MOD
	bunshi = (bunshi * (i+1) + bunbo) % MOD
	bunbo = (bunbo * (i+1)) % MOD
print(ans)

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

using namespace std;

const int md = 998244353;

inline void add(int &x, int y) {
  x += y;
  if (x >= md) x -= md;
}

inline void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += md;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (int i = 0; i < k; i++) {
    cin >> seg[i].first >> seg[i].second;
  }
  vector<int> dp(n);
  vector<int> pref(n);
  dp[0] = 1;
  pref[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i >= seg[j].first) {
        add(dp[i], pref[i - seg[j].first]);
      }
      if (i >= seg[j].second + 1) {
        sub(dp[i], pref[i - 1 - seg[j].second]);
      }
    }
    pref[i] = pref[i - 1];
    add(pref[i], dp[i]);
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 4840
#%%
import bisect

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]


for i in range(q):
    st = x[i]
    #print('----------------')
    #print(st)

    #s_t
    sr = bisect.bisect_left(s, st)
    sl = sr - 1
    ans_s = 10**20
    for j in [sr, sl]:
        if 0 <= j <= a-1:
            tmp = abs(st - s[j])
            tr = bisect.bisect_left(t, s[j])
            tl = tr - 1
            for k in [tr, tl]:
                if 0 <= k <= b-1:
                    #print(tmp+abs(s[j] - t[k]))
                    ans_s = min(ans_s, tmp+abs(s[j] - t[k]))
    #print(' ')
    #t_s
    tr = bisect.bisect_left(t, st)
    tl = tr - 1
    ans_t = 10**20
    for j in [tr, tl]:
        if 0 <= j <= b-1:
            tmp = abs(st - t[j])
            sr = bisect.bisect_left(s, t[j])
            sl = sr - 1
            for k in [sr, sl]:
                if 0 <= k <= a-1:
                    #print(tmp+abs(s[k] - t[j]))
                    ans_t = min(ans_t, tmp+abs(s[k] - t[j]))
    
    print(min(ans_s, ans_t))
    #print('---------------------')

Measured memory_bytes: 101356
#include <bits/stdc++.h>
using namespace std;
 //ハーシャット数
int ruijyo(int x, int a){
  if (a == 1) {
    return x;
  }
  else{
    for (int i = 0; i < a - 1; i++) {
      x *= 10;
    }
  return x;
  }
}
    
int main() {
  int n;
  cin >> n;
  int len = 0;
  for (int i = 1; i < 20; i++){
    if (n < ruijyo(10, i)) {
      len = i;
      break;
    }
  }
  int amari = n;
  int tmp = n;
  int sum = 0;
  for (int i = 0; i < len - 1; i++) {
    tmp /= (ruijyo(10, len - 1 - i));
    sum += tmp;
    //cout << sum << endl;
    amari %= (ruijyo(10, len - 1 - i));
    tmp = amari;
  }
  sum += tmp;
  //cout << sum << endl;
  if (n % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    
 


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

int main() {
  long N, K, ans;
  scanf("%ld %ld", &N, &K);

  ans = N%K;

  if(ans < K-ans){
    printf("%ld", ans);
  }else{
    printf("%ld", K-ans);
  }
}

Measured memory_bytes: 256
def affine(x, a, b):
    result = []
    for i in range(len(x)):
        c = chr((a * (ord(x[i])-97) + b) % 26 + 97)
        result.append(c)

    return ''.join(result)


def decode_key(a, b):
    key = "abcdefghijklmnopqrstuvwxyz"
    result = []
    for i in range(len(key)):
        result.append(affine(key[i], a, b))
    return ''.join(result)


a = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]
n = int(input())
for i in range(n):
    ai = 0
    b = 0
    line = input()
    words = line.split()
    for i in range(26):
        for j in range(len(a)):
            if affine('that', a[j], i) in words:
                ai = j
                b = i
            if affine('this', a[j], i) in words:
                ai = j
                b = i
        if ai and b:
            break

    line = line.translate(str.maketrans(decode_key(a[ai], b), "abcdefghijklmnopqrstuvwxyz"))
    print(line)

Measured memory_bytes: 7672
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String x=sc.next();
    int n=x.length();
    String ch=x.substring(n-1);
    
    		
    if(ch.equals("s")) {
    	System.out.println(x+"es");
    }else {
    	System.out.println(x+"s");
    }
    }
}

Measured memory_bytes: 38512
import sys
from collections import Counter

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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    ev = 0
    od = 0
    for k, v in D.items():
        if v % 2 == 0:
            ev += 1
        else:
            od += 1
    if ev % 2 == 0:
        print(ev + od)
    else:
        print(ev + od - 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21968
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
ans = 0

for i in range(1, n+1):
    cur = i
    cnt = 0
    while cur < k:
        cnt += 1
        cur *= 2

    ans += (1/n) * (1/pow(2, cnt))

print(ans)

Measured memory_bytes: 39920
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll row[107],col[107];

int main() {
  ll N;cin >> N;
  cout << (N<105 ? 0 :(N<135 ? 1 :(N<165 ? 2 :(N<189 ? 3 :(N<195 ? 4 :5))))) << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
 int A_1, A_2, A_3;
 cin>>A_1;
 cin>>A_2;
 cin>>A_3;
 if(21<A_1+A_2+A_3){
   cout<<"bust";
 }else{
   cout<<"win";
 }

 return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
prev = -float('inf')
res = 0
for e in a:
    e -= 1
    res += b[e]
    if prev == e - 1:
        res += c[prev]
    prev = e
print(res)

Measured memory_bytes: 3064
while True:
    n = int(input())
    m = int(input())
    if m == 0:
        break
    dataset = [input().split() for _ in range(m)]
    list_ = {i+1: [] for i in range(n)}
    for data in dataset:
        idx_x, idx_y = map(int, data)
        list_[idx_x].append(idx_y)
        list_[idx_y].append(idx_x)

    ans = list_[1].copy()
    for i in list_[1]:
        ans += list_[i]
    print(len(set(ans))-1)

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

template<class T> inline T gcd(T a, T b) {
    if (b == 0) return a;
    return  gcd(b, a % b);
}

template<class T> inline T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

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

    ll a, b;
    cin >> a >> b;

    ll ans = lcm(a, b);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
const long double PI = 3.141592653589793238462643383279502884197;

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

	int N; cin >> N;

	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		int x; cin >> x;

		if ((i & 1) && (x & 1)) cnt++;
	}

	cout << cnt;

	return 0;
}

Measured memory_bytes: 3608
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]int, m)
	for i := range as {
		fmt.Scan(&as[i])
	}
	var sum int
	for i := range as {
		sum += as[i]
	}
	if n >= sum {
		fmt.Println(n - sum)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 2428
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

  private static void solve() {
    int[] a = na(3);
    List<String> list = new ArrayList<>();
    for (int j = 0; j < 3; j ++) {
      for (int i = 0; i < a[j]; i ++)
        list.add("" + (char)('a' + j));
    }

    while (list.size() > 1) {
      Collections.sort(list);
      int last = list.size() - 1;
      String s = list.get(0) + list.get(last);
      list.set(0, s);
      list.remove(last);
    }
    System.out.println(list.get(0));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), B(M);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (ll i = 0; i < M; i++)
  {
    cin >> B.at(i);
  }

  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  A.push_back(0), B.push_back(0);

  /*
  for (ll i = 0; i < N; i++)
  {
    cerr << A.at(i) << " ";
  }
  cerr << endl;
  for (ll i = 0; i < M; i++)
  {
    cerr << B.at(i) << " ";
  }
  cerr << endl;
  */

  ll a = 0, b = 0;
  ll ans = 1;
  for (ll i = 0, k = N * M; k > 0; i++, k--)
  {
    if (A.at(a) == k && B.at(b) == k)
    {
      a++, b++;
    }
    else
    {
      if (A.at(a) == k)
      {
        a++;
        ans *= b, ans %= MOD;
      }
      else if (B.at(b) == k)
      {
        b++;
        ans *= a, ans %= MOD;
      }
      else
      {
        ans *= a * b - i, ans %= MOD;
      }
    }
    //cerr << k << " " << a << " " << b << " " << ans << endl;
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int N;
    cin >> N;
    vector<int> P(N, 0);
    REP(i, N) { cin >> P[i]; }
    SORT(P);
    int ans = 0;
    REP(i, N) {
        ans += (i == N - 1) ? P[i] / 2 : P[i];
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;
using ll=long long;
using db=double;

typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<bool> vbl;

int inf=(1LL<<31)-1;
int MOD=1000000007;

#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define vvii(c,a,b) vector<vector<ii>> c(a,vector<ii>(b,0))
#define vvll(c,a,b) vector<vector<ll>> c(a,vector<ll>(b,0))
#define vvstr(c,a,b) vector<vector<string> c(a,vector<string>(b,0))
#define vvbol(c,a,b) vector<vector<bool>> c(a,vector<bool>(b,true))

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    int count=0;
    fi(0,s.size())
    {
        count+=s.at(i)-'0';
    }
    if(count%9==0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return(0);
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli N,A,C=0,B,D=0;
  cin >> A >> N;
  Vecpr P(A);
  rep(i,A)cin >> P[i].first >> P[i].second;
  Sort(P);
  rep(i,A){
    if(P[i].second>N){
      if(i==A-1)Out("TLE");
      continue;
    }
    else{
      Out(P[i].first);
      break;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        int sum = 0;
        for(int i = 0;i<n;i++){
            t[i] = sc.nextInt();
            sum += t[i];
        }
        int m = sc.nextInt();
        int[] p = new int[m];
        int[] x = new int[m];
        int[] ans = new int[m];
        for(int i = 0;i<m;i++){
            p[i] = sc.nextInt();
            x[i] = sc.nextInt();
        }
        for(int i = 0;i<m;i++){
            ans[i] = sum -t[p[i]-1]+x[i];
        }
        for(int i = 0;i<m;i++){
            System.out.println(ans[i]);
        }
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
ll ar[1000006];
void prime(){
      
       ar[0]=1;ar[1]=1;
       for( int i=2;i<=1000000;i++){
             if(ar[i]==0){
             for(int j=i*2;j<=1000000;j+=i)ar[j]=1;
           }
       }
}
bool check(ll n){
    for(int i=2;i<=1000000&&i<=n;i++){
       if(n%i==0)return 0;
    }
    return 1;
}
int main() {
    
         ios;
         prime();
        
      int a,b;
      ll n;
      cin>>n;
      vector<int>v;
      bool p=check(n);
       if(n==1){
        cout<<0;
        return 0;
       }
      if(p==1){
        cout<<1;
        return 0;
      }
      f(i,2,1000000){
        if(ar[i]==0 && n%i==0){ 
              int c=0;
              while(n%i==0){
                c++; n=n/i;
              }
              v.pb(c);
        }
      }
      ll ans=0;
      if(n>1)ans++;
      f(i,0,v.size()){
          ll x=(-1+sqrt(1+8*v[i]))/2;
          ans+=x;
      } 
      cout<<ans;
 }

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

int main(void){
	double x1,x2,x3,y1,y2,y3,xp,yp,a,b,c,d,r;
	int i,l,n;
	long s;
	
	scanf("%d",&n);
	
	for(;n>0;n--){
		
		scanf(" %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		
		//printf("%lf %lf %lf %lf %lf %lf\n",x1,y1,x2,y2,x3,y3);
		
		//(-x1+x2)*2xp+x1^2-x2^2+(-y1+y2)*2yp+y1^2-y2^2
		//(-x1+x3)*2xp+x1^2-x3^2+(-y1+y3)*2yp+y1^2-y3^2
		
		//y=a*x+b
		//y=c*x+d
		//この形に変換
		
		//printf("test\n");
		
		if(y1!=y2){
			a=(-x1+x2)/(y1-y2);
			
			//b=(pow(x1,2)-pow(x2,2)+pow(y1,2)-pow(y2,2))/(2*(y1-y2));
			
			b=0;
			b+=x1*x1-x2*x2+y1*y1-y2*y2;
			b/=2*(y1-y2);
		}
		
		else
		xp=(x1+x2)/2;
		
		
		//printf("test\n");
		
		if(y1!=y3){
			c=(-x1+x3)/(y1-y3);
			//d=(pow(x1,2)-pow(x3,2)+pow(y1,2)-pow(y3,2))/(2*(y1-y3));
			
			
			d=0;
			d+=x1*x1-x3*x3+y1*y1-y3*y3;
			d/=2*(y1-y3);
		}
		
		else
		xp=(x1+x3)/2;
		
		//printf("test\n");
		
		//printf("%lf %lf %lf %lf\n",a,b,c,d);
		if(y1!=y2 && y1!=y3)
		xp=(-b+d)/(a-c);
		if(y1!=y2)
		yp=a*xp+b;
		if(y1!=y3)
		yp=c*xp+d;
		
		r=sqrt(pow(x1-xp,2)+pow(y1-yp,2));
		
		s=xp*10000;
		s=s%10;
		if(s>=5)s=1;
		else s=0;
		if(s==1)xp+=0.001*xp/abs(xp);
		if(xp<0 && xp>-0.001)xp=0;
		
		s=yp*10000;
		s=s%10;
		if(s>=5)s=1;
		else s=0;
		if(s==1)yp+=0.001*yp/abs(yp);
		if(yp<0 && yp>-0.001)yp=0;
		
		s=xp*10000;
		s=s%10;
		if(s>=5)s=1;
		else s=0;
		if(s==1)r+=0.001;
		if(r<0 && r>-0.001)r=0;
		
		printf("%.3lf %.3lf %.3lf\n",xp,yp,r);
		
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int K, S, A;

	scanf("%d", &K);
	S = K / 2;
	A = S + 1;

	if (K % 2 == 0)
		printf("%d", S * S);

	else
		printf("%d", S * A);

	return 0;

	
}

Measured memory_bytes: 256