akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
	val mod = 1000000007

	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val k = scanner.nextLong()

	val map = IntArray(2001){i -> 0}

	var cnt = 0L
	var max = 0
	for (i in 0..n-1){
		val a = scanner.nextInt()
		for (j in a+1..2000) cnt+=map[j]
		map[a]++
		max = Math.max(max, a)
	}
	cnt = (cnt*k)%mod
	var tmp = 0L
	for (i in max downTo 1){
		cnt = (cnt+tmp*map[i]*(((k-1)*k/2)%mod))%mod
		tmp += map[i]
	}

	println(cnt)
}

Measured memory_bytes: 33784
#include<stdio.h>
int main()
{
    int i,j,cnt=0,cmt=0,sum=0;
    int n;
    scanf("%d",&n);
    int ar[n];
    int a,b,c;
    scanf("%d %d",&a,&b);
    for(i=0; i<n; i++)
    {
        scanf("%d",&ar[i]);
    }
    for(i=0; i<n; i++)
    {
            for(j=1; j<=a; j++)
            {
                if(ar[i]*j+1<=a){
                   cmt++;
                }
                else{
                    cnt++;
                    break;
                }


            }

        }
     printf("%d\n",cnt+cmt+b+n-cnt);
    return 0;
}














Measured memory_bytes: 1708
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int lot[] = new int[w];

		String bar;
		String s[];
		int a;
		int b;
		int save;

		for (int i = 0; i < w; i++){
			lot[i] = i + 1;
		}

		for (int i = 0; i < n; i++){
			bar = sc.next();
			s = bar.split(",");
			a = Integer.parseInt(s[0]);
			b = Integer.parseInt(s[1]);

			save = lot[b-1];
			lot[b-1] = lot[a-1];
			lot[a-1] = save;
		}

		for (int i = 0; i < w; i++){
		System.out.println("" + lot[i]);
		}

	}
}

Measured memory_bytes: 17200
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int A,B,C;

int main()
{
   cout << fixed << setprecision(10);
   cin >> A >> B >> C;
   int ans = 0;
   if (A==B) {
      if (A!=C) {
         ans = 1;
      }
   } else if (B==C) {
      if (A!=B) {
         ans = 1;
      }
   } else if (A==C) {
      if (A!=B) {
         ans = 1;
      }
   }
   if (ans) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }
   return 0;
}



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

using namespace std;

typedef long long ll;

int main(){
    int n; cin >> n;
    ll answer = 0;
    vector<int> as(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> as.at(i);
    }

    map<int, int> mp;
    for(int i = 0; i < n; ++i)
    {
        mp[as.at(i)]++;
    }

    for(int i = 0; i < n; ++i)
    {
        if(mp[as.at(i)] < as.at(i))
        {
            answer += mp[as.at(i)];
            mp[as.at(i)] = 0;
        }
        else if(mp[as.at(i)] > as.at(i))
        {
            answer += mp[as.at(i)] - as.at(i);
            mp[as.at(i)] = as.at(i);
        }
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 8200
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M = IL()
if N == M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 66156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;

template<class T> bool ckmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template <typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template <typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

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

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template <class X, class Y>
std::ostream & operator << (std::ostream & os, std::pair <X, Y> const& p) {
    return os << p.first << " " << p.second;
}

template <class Ch, class Tr, class Container>
std::basic_ostream <Ch, Tr> & operator << (std::basic_ostream <Ch, Tr>& os, Container const& x) {
    bool first = true;
    for(auto& y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class COneQuadrillionAndOneDalmatians {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll N;
        in >> N;
        string res;
        for (; --N >= 0; N /= 26) {
            res.pb('a' + N % 26);
        }
        reverse(all(res));
        out << res << '\n';
	}

	void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
	COneQuadrillionAndOneDalmatians solver;
    solver.setup();
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n, T;
    cin >> n >> T;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    ll ans = T*n;
    rep(i, n-1) {
        ans -= max(0LL, t[i]+T-t[i+1]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4688
object Main extends App {
    var l: String = readLine
    var line = l.toInt

      if(line == 25) {
    println("Christmas")
    } 
  if(line == 24) {
    println("Christmas Eve")
    }
  if(line == 23) {
    println("Christmas Eve Eve")
    }
  if(line == 22) {
    println("Christmas Eve Eve Eve")
    }
        	 
  
  
}


Measured memory_bytes: 25292
#judge stable or not stbale

def printout(array, n):
    output = ""
    for i in range(n - 1):
        output += str(array[i]) + " "
    output += str(array[N - 1])
    print(output)


def bubble_sort(array):
    for i in range(N):
        for j in reversed(range(i+1,N)):
            if (int(array[j-1][1]) > int(array[j][1])):
                #swap
                tmp = array[j]
                array[j] = array[j-1]
                array[j-1] = tmp
    return array


def linearsearch(subarray):
    # return index of minimum array element
    min = int(subarray[0][1])
    min_index = 0;
    for i in range(1,len(subarray)):
        if min > int(subarray[i][1]):
            min = int(subarray[i][1])
            min_index = i
    return min_index


def selection_sort(array):
    index,tmp = 0,0
    for i in range(N):
        index = linearsearch(array[i:]) + i

        if index != i:
            #swap
            tmp = array[index]
            array[index] = array[i]
            array[i] = tmp
    return array


N = int(input())
array = [i for i in input().split()]
array1 = bubble_sort(array[:])
array2 = selection_sort(array[:])
original_array = array[:]

printout(array1,N)
print("Stable")
printout(array2,N)
if array1 == array2:
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 5616
N = int(input())
Cities = [input().split() for j in range(N)]

for i in range(N):
    Cities[i][1] = int(Cities[i][1])
    Cities[i].append(i + 1)
Cities.sort(key=lambda x: (x[0], -x[1]))

ans = [str(b) for _, _, b in Cities]
print('\n'.join(ans))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

ll a[200000+5];
ll sum[200000+5];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i] = sum[i-1]+a[i];
	}

	int ptr1= 1,ptr2 = 3;
	ll ans = sum[n];
	for(int i =2;i<=n-2;i++){

		ll curdif = abs((sum[i]-sum[ptr1])-sum[ptr1]);
		while(ptr1+1<i){
			ll tcurdif = abs((sum[i]-sum[ptr1+1])-sum[ptr1+1]);
			if(tcurdif<curdif)ptr1++,curdif=tcurdif;
			else break;
		}
		curdif = abs((sum[ptr2]-sum[i])-(sum[n]-sum[ptr2]));
		while(ptr2+1<n){
			ll tcurdif = abs((sum[ptr2+1]-sum[i])-(sum[n]-sum[ptr2+1]));
			if(tcurdif<curdif)ptr2++,curdif=tcurdif;
			else break;
		}
		ll p = sum[ptr1],q= sum[i]-sum[ptr1],r= sum[ptr2]-sum[i],s=sum[n]-sum[ptr2];
		ll x = min(min(p,q),min(r,s));
		ll y = max(max(p,q),max(r,s));
		ll tans = y-x;
		if(tans<ans)ans = tans;
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a+b)%24<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define INF 1000000000;
#define NODE 10000;

using namespace std;
int A,B,N,M,T[100],P[100],X[100],ans,sum[100];
string S;
int abs(int x){
	if(x<0){
		return -x;
	}
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}
int max(int x,int y){
	if(x>y)return x;
	
	return y;
}

int main(){
	cin >>N;
	for(int i=0;i<N;i++){
		cin>>T[i];
		ans+=T[i];
	}
	cin >> M;
	for(int i=0;i<M;i++){
		cin>>P[i]>>X[i];
		P[i]--;
		sum[i]=ans;
	}

	for(int i=0;i<M;i++){
		sum[i]=sum[i]-T[P[i]]+X[i];
		cout<<sum[i]<<endl;
	}


	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

vector<bool > prime;

//primeListには素数は入ってません
void isPrime(ll N){
    prime[0] = false;
    prime[1] = false;

    //ルートN以下まで繰り返す
    for(ll i = 2; i < ceil(sqrt(N)) ; i++){
        //素数になりえないとき
        //cout << i << endl;
        if(!prime[i]) continue;
        
        //Nまでのi(素数)の倍数を斑入り落とす
        for(ll j = i * i; j <= N; j += i){
            prime[j] = false;
        }    
    }
}


//素因数分解した指数部の個数 x, y... の(x+1)(y+1)個
//ルジャンドルの定理
vector<pi> factorialPrimeFactor(ll num){

    //素因数と指数部の並び
    ll j = 0;
    vector<pi > PF;

    for(ll i = 2; i < prime.size(); i++){
        if(prime[i] == false) continue;
        if(i > num) break;
  
        PF.push_back(make_pair(i, 0));
        //cout << PF.size() << endl;
        ll cn = 1;
        while(!(pow(i, cn) > num)){
            //cout << i << " " << pow(i, cn) << endl;
            if(num / pow(i, cn) > 0){
                PF[j].second += num / pow(i, cn);
                cn++;
            }
        }
        j++;
    }

    return PF;
}

int main(){
    ll N = 0; cin >> N;

    prime.assign(N + 500, true);
    isPrime(N);

    vector<pi > t_ans = factorialPrimeFactor(N);
    
    ll ans = 1;

    /*
    for(ll i = 0; i < N + 2; i++){
        if(prime[i] == true){
            cout << i << endl;
        }
    }
    */

    for(ll i = 0; i < t_ans.size(); i++){
        //cout << t_ans[i].second << endl;
        ans *= t_ans[i].second + 1;
        ans %= MOD;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

//cost_map[vertex] pll -> <to, cost>
bool bellman_ford(ll s, vector<vector<pll>>& cost_map, vector<ll>& result){
    ll N = cost_map.size();
    vector<ll> d(N, MAXINF);
    d[s] = 0;
    REP(k, N){
        REP(i, N){
            if(d[i]==MAXINF)continue;
            for(auto&& v : cost_map[i]){
                if(d[v.fi] > d[i] + v.se){
                    d[v.fi] = d[i] + v.se;
                    if(k==N-1) return false;
                }
            }
        }
    }
    result = d;
    return true;
}

int result[1000][1000];
void warshall_floyd(vector<vector<pii>>& cost_map){
    int n = cost_map.size();
    //配列の準備
    REP(i, n)REP(j, n) result[i][j] = INF;
    REP(i, n) result[i][i] = 0;
    REP(i, n) for(auto&& cost : cost_map[i]) result[i][cost.first] = cost.second;
    //ワーシャルフロイド法による最短経路探索
    REP(i, n)REP(j, n)REP(k, n) chmin(result[j][k], result[j][i] + result[i][k]);
}

int main(void)
{
    int N,M,R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }
    SORT(r);
    vector<vector<pii>> cost_map(N);
    REP(i, M){
        int A,B,C;
        cin >> A >> B >> C;
        A--;B--;
        cost_map[A].emplace_back(B, C);
        cost_map[B].emplace_back(A, C);
    }

    warshall_floyd(cost_map);

    int ans = INF;
    do{
        int tmp_ans = 0;
        REP(i, R-1){
            tmp_ans += result[r[i]][r[i+1]];
        }
        chmin(ans, tmp_ans);
    }while(next_permutation(ALL(r)));

    pr(ans);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define mod (int)(1e9 + 7) 
using namespace std;
vector<int> g[(int)1e5 + 5];


int mul(int a, int b){
	return ((ll)a%mod * b%mod)%mod;
}
pair<int,int> dfs(int i, int parent){
	
	int black = 0; // at least one is black
	int white = 1; // all white
	for(int ch: g[i]){
		if(ch != parent){
			pair<int,int> p = dfs(ch, i);
			int meme = white;
			white = mul(white, p.second);
			black = (mul(meme, p.first)%mod + mul(black, (p.first + p.second)))%mod;
		}
	}
	return {white, (black%mod + white%mod)%mod};
	
}

int main(){
	int N;
	cin >> N;
	for(int i = 1; i <= N-1; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	pair<int,int> ans = dfs(1, -1);
	cout << (ans.first%mod + ans.second%mod)%mod << endl;
}


Measured memory_bytes: 15848
n = str(input())
if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
    print("hon")
elif n[-1]=='0' or n[-1]=='1' or n[-1]=='6' or n[-1]=='8':
    print("pon")
elif n[-1]=='3':
    print("bon")

Measured memory_bytes: 9024
import java.util.Scanner

import scala.io.StdIn
import scala.math._

object Main {
  def main(args: Array[String]): Unit ={
//    val N = StdIn.readLine.toInt

    val sc = new Scanner(System.in)
    val N = sc.nextInt
    val T = sc.nextInt
    val A = sc.nextInt
    val hs = List.fill(N)(sc.nextInt)


    def tempature(x: Int): Double = T - x * 0.006

    val tuple = hs.zipWithIndex.map{case (h,i) => (abs( tempature(h) - A),i)}

    // tupleの大小は、_1 => _2 となる
    println(tuple.min._2 + 1)
  }
}


Measured memory_bytes: 29504
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;



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

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

llong N, M;

const llong MOD = 1000000007;

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

	if (abs(N - M) >= 2) cout << 0;
	else {
		llong A = 1;
		if (N == M) {
			for (int i = 1; i <= N; i++) {
				A *= i;
				A %= MOD;
			}

			A = (2 * A * A) % MOD;

			cout << A;
		}

		else {

			llong A = 1;

			if (N < M) {
				swap(N, M);
			}

			for (int i = 1; i <= M; i++) {
				A *= i;
				A %= MOD;
			}

			A = (((A * A) % MOD) * N) % MOD ;
			cout << A;
		}
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010



int main(){
  int counter[110] = {};
  int n;

  cin >> n;
  
  for(int i=1;i<=n;i++){
    int t = i;
    for(int j=2;j*j<=t;j++){
      while(t%j == 0){
        counter[j]++;
        t /= j;
      }
    }
    counter[t]++;
  }
  
  int ans = 0;
  
  for(int i=2;i<=n;i++){
    ans += counter[i] >= 74;
    for(int j=2;j<=n;j++){
      // 25 * 3, 15 * 3
      if(i == j) continue;
      ans += counter[i] >= 4 && counter[j] >= 14;
      ans += counter[i] >= 2 && counter[j] >= 24;
      for(int k=i+1;k<=n;k++){
        // 5 * 5 * 3
        if(i == k || j == k) continue;
        ans += counter[i] >= 4 && counter[k] >= 4 && counter[j] >= 2;
      }
    }
  }

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




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    p = S.count('p')
    return len(S)//2 - p


def main():
    S = read_str()
    print(slv(''.join(S)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 67308
dic = {}
while 1:
    try:
        word, page = map(str, input().split())
        page = int(page)
        if word in dic:
            dic[word].append(page)
        else:
            dic[word] = [page]
    except:
        break

for d in sorted(dic):
    print(d)
    print(' '.join(map(str, sorted(dic[d]))))



Measured memory_bytes: 5612
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    deque<int> deq;
    char c = S[0];
    int cnt = 0;
    for(int i = 0;i < S.size();i++){
        if(c != S[i]){
            deq.push_back(cnt);
            c = S[i];
            cnt = 1;
        }else cnt++;
    }
    deq.push_back(cnt);

    int mini = S.size();
    while(deq.size() > 1){
        int f = deq.front(),b = deq.back();
        if(f < b){
            mini = min(mini, (int)S.size() - f);
            deq.pop_front();
            deq.front() += f;
        }else{
            mini = min(mini, (int)S.size() - b);
            deq.pop_back();
            deq.back() += b;
        }
    }
    cout << mini << endl;
}

Measured memory_bytes: 512
N = int(input())
hhh = list(map(int, input().split()))
for i in range(N - 2, -1, -1):
    if hhh[i] <= hhh[i + 1]:
        pass
    elif hhh[i] - hhh[i + 1] == 1:
        hhh[i] -= 1
    else:
        print('No')
        exit()
print('Yes')


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

int main()
{
    set <int> s;
    s.insert(1);
    for(int i = 2; i <= 31; i++)
        for(int j = i * i; j <= 1000; j *= i)
            s.insert(j);
    int x;
    cin >> x;
    auto it = s.upper_bound(x);
    it--;
    cout << *it;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			int hour = stdIn.nextInt();
			int minute = stdIn.nextInt();
			int second = stdIn.nextInt();
			if(hour == -1 & minute == -1 & second == -1){
				break;
			}
			int tape = 7200 - 3600 * hour - 60 * minute - 1 * second;
			int tape3Times = tape * 3;
			System.out.println(String.format("%1$02d:%2$02d:%3$02d",(tape/3600),(tape%3600)/60,((tape%3600)%60)/1));
			System.out.println(String.format("%1$02d:%2$02d:%3$02d",(tape3Times/3600),(tape3Times%3600)/60,((tape3Times%3600)%60)/1));
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h.begin(),h.end());
    int ans=1e9;
    for(int i=0;i<=n-k;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    string s, t;
    cin >> s >> t;

    vector<pair<int64_t, string>> dp(t.size());
    for (auto c : s) {
        int64_t len = 0;
        string last;
        decltype(dp) next(dp.size());
        for (auto i = 0L; i < dp.size(); ++i) {
            auto lencandidate = (i > 0 ? dp[i - 1].first : 0L) + 1;
            if (t[i] == c && len < lencandidate) {
                len = lencandidate;
                last = (i > 0 ? dp[i - 1].second : string{}) + c;
            }
            if (dp[i].first >= len) {
                next[i] = dp[i];
            } else {
                next[i].first = len;
                next[i].second = last;
            }
        }
        dp = move(next);
    }

    cout << dp.back().second << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll K, X;
    cin >> K >> X;
    if (500LL * K >= X)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
b = []
for i in range(n):
    line = list(map(int, input().split()))
    a.append(line[0])
    b.append(line[1])

participants = 0
a.sort()
b.sort()
b.reverse()

participants += n

participants += a[0] - 1

for i in range(n-1):
    minwidth = 0
    if (a[i+1] - a[i]) >= (b[i] - b[i + 1]):
        minwidth = (b[i] - b[i + 1])
    else:
        minwidth = (a[i+1] - a[i])
    participants += minwidth - 1

participants += b[n-1]

print(participants)

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;
	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;

	int ans = 0;
	while(b<=a){
		ans++;
		b*=2;
	}
	while(c<=b){
		ans++;
		c*=2;
	}
	dbg(ans);
	if(ans<=k) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
    while(true){
        int e;
        cin>>e;
        if(e == 0)break;
        int ans = 100000000;
        for(int z = 0;z*z*z<=e;z++){
            for(int y = 0;y*y<=e-z*z*z;y++){
                if(e-z*z*z-y*y>=0){
                    int x = e-z*z*z-y*y;
                    ans = min(ans,x+y+z);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define N 110
using namespace std;
ll fac[N*N],inv[N*N],f[2][N][N],g[N][N],mod,mul[N][N*N];
int n,m,k;
ll ksm(ll a,ll b=mod-2)
{
	if(b==0) return 1;
	if(b==1) return a;
	ll q=ksm(a,b>>1);
	if(b&1) return q*q%mod*a%mod;
	return q*q%mod;
}
int main()
{
	scanf("%d%d%d%lld",&n,&m,&k,&mod);
	for(int i=0;i<=k;i++)
	{
		mul[i][0]=1;
		for(int j=1;j<=n*m;j++) mul[i][j]=mul[i][j-1]*i%mod;
	}
	int nm=max(n,m);
	fac[0]=1;
	for(int i=1;i<=nm;i++) fac[i]=fac[i-1]*i%mod;
	inv[nm]=ksm(fac[nm]);
	for(int i=nm-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	int u=0,p=1;
	f[u][0][0]=1;
	for(int l=1;l<=k;l++)
	{
		u^=1,p^=1;
		memset(f[u],0,sizeof(f[u]));
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
			if(i&1) g[i][j]=inv[i]*mul[l-1][i*(m-j)]%mod*mul[k-l+1][i*j]%mod*(mod-1)%mod;
			else g[i][j]=inv[i]*mul[l-1][i*(m-j)]%mod*mul[k-l+1][i*j]%mod;
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				for(int k=0;k<=i;k++)
				(f[u][i][j]+=f[p][i-k][j]*g[k][j]%mod)%=mod;
		
		u^=1,p^=1;
		memset(f[u],0,sizeof(f[u]));
		for(int i=0;i<=m;i++)
			for(int j=0;j<=n;j++)
			if(i&1) g[i][j]=inv[i]*mul[l-1][i*(n-j)]%mod*mul[k-l+1][i*j]%mod*(mod-1)%mod;
			else g[i][j]=inv[i]*mul[l-1][i*(n-j)]%mod*mul[k-l+1][i*j]%mod;
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				for(int k=0;k<=j;k++)
				(f[u][i][j]+=f[p][i][j-k]*g[k][i]%mod)%=mod;
		
		u^=1,p^=1;
		memset(f[u],0,sizeof(f[u]));
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
			g[i][j]=inv[i]*mul[l][i*(m-j)]%mod*mul[k-l+1][i*j]%mod;
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				for(int k=0;k<=i;k++)
				(f[u][i][j]+=f[p][i-k][j]*g[k][j]%mod)%=mod;
		
		u^=1,p^=1;
		memset(f[u],0,sizeof(f[u]));
		for(int i=0;i<=m;i++)
			for(int j=0;j<=n;j++)
			g[i][j]=inv[i]*mul[l][i*(n-j)]%mod*mul[k-l+1][i*j]%mod;
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				for(int k=0;k<=j;k++)
				(f[u][i][j]+=f[p][i][j-k]*g[k][i]%mod)%=mod;
	}
	printf("%lld",f[u][n][m]*fac[n]%mod*fac[m]%mod);
	return 0;
}


Measured memory_bytes: 10496
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;


long long N, K;

mint dp[110][111000];
mint sdp[111000];
long long num[111000];

mint solve() {
    // 各レイヤーの数値の個数
    int iter = 0;
    for (int i = 1; i <= N;) {
        int j = N / i;
        if (i <= j) num[iter++] = 1, ++i; // 前半
        else num[iter++] = N/j - i + 1, i = N/j + 1; // 後半
    }

    // DP
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int k = 0; k < K; ++k) {
        memset(sdp, 0, sizeof(sdp));
        for (int j = 0; j <= iter; ++j) sdp[j+1] = sdp[j] + dp[k][j];
        for (int j = 0; j < iter; ++j) dp[k+1][j] = sdp[iter - j] * mint(num[j]);
    }

    // 集計
    mint res = 0;
    for (int j = 0; j <= iter; ++j) res += dp[K][j];
    return res;
}

int main() {
    cin >> N >> K;
    cout << solve() << endl;
}


Measured memory_bytes: 97024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,s;
char a[1000005];
int main()
{
	scanf("%d%s",&n,a);
	for(int i=0;i<n;i++)
	{
		if(a[i]=='I')s++;
		if(a[i]=='D')s--;
		m=max(s,m);
	}
	printf("%d\n",m);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

bool cmp(pair<long long int, int> x, pair<long long int, int> y) {
    if(x.first!=y.first) {
        return x.first>y.first;
    } else {
        return x.second>y.second;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long int> A(N);
    vector<long long int> sA(N+1, 0);
    for(int n=0; n<N; n++) {
        cin >> A[n];
    }
    sort(A.begin(), A.end());
    for(int n=0; n<N; n++) {
        sA[n+1] = sA[n]+A[n];
    }
    vector<pair<long long int, int> > vec(M);
    map<long long int, int> mp;
    for(int m=0; m<M; m++) {
        cin >> vec[m].second >> vec[m].first;
        mp[vec[m].first] = lower_bound(A.begin(), A.end(), vec[m].first)-A.begin();
    }
    sort(vec.begin(), vec.end(), cmp);
    
    long long int ans=0;
    int cur=0;
    for(int m=0; m<M; m++) {
        if(min(vec[m].second, max(0, mp[vec[m].first]-cur))) {
            ans += vec[m].first*(min(vec[m].second, max(0, mp[vec[m].first]-cur)));
            cur += min(vec[m].second, max(0, mp[vec[m].first]-cur));
        } else {
            break;
        }
    }
    ans += sA[N]-sA[cur];
    cout << ans << endl;

    return 0;
    
}

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

int used[300000];

int main(){
	int N;
	cin >> N;
	int A[(1<<N)+1];
	for(int i=0; i<(1<<N); i++){
		cin >> A[i];
	}
	A[1<<N] = -1;
	long long data[1<<N][2];
	data[0][0] = 0; data[0][1] = -1;
	for(int i=1; i<(1<<N); i++){
		vector<int> arr;
		arr.push_back(i);
		for(int j=0; j<N; j++){
			if(i & (1<<j)){
				int bit = i &~(1<<j);
				if(used[data[bit][0]] == 0){
					used[data[bit][0]] = 1;
					arr.push_back(data[bit][0]);
				}
				if(data[bit][1] != -1){
					if(used[data[bit][1]] == 0){
						arr.push_back(data[bit][1]);
						used[data[bit][1]] = 1;
					}
				}
			}
		}
		int ma = (1<<N), ma2 = (1<<N);
		for(int j=0; j<arr.size(); j++){
			if(A[ma] < A[arr[j]]) ma = arr[j];
		}
		for(int j=0; j<arr.size(); j++){
			if(arr[j] != ma){
				if(A[ma2] < A[arr[j]]) ma2 = arr[j];
			}
		}
		data[i][0] = ma, data[i][1] = ma2;
		for(int j=0; j<arr.size(); j++){
			used[arr[j]] = 0;
		}
	}
	int ans[1<<N];
	ans[0] = 0;
	for(int i=1; i<(1<<N); i++){
		ans[i] = max(ans[i-1], A[data[i][0]] + A[data[i][1]]);
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 10240
a,b = map(int,input().split())
i = 0
x = int(a/0.08)
while True:
    if int((x+i)*0.1) == b and int((x+i)*0.08) == a:
        ans = int(x+i)
        break
    elif int((x+i)*0.1) > b:
        ans = '-1'
        break
    else:
        i += 1
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> v(n+1);
    for (int i = 1; i <= n; i++) cin >> v[i];
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (v[v[i]] == i) cnt++;
    }
    cout << cnt / 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, A[(int)2e5];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
    }

    for (size_t i = 1; i < N; i++) {
        if (A[i - 1] > A[i]) {
            ans += A[i - 1] - A[i];
            A[i] = A[i - 1];
        }
    }

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

    return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

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



signed main(){
   string s;cin>>s;
   cerr<<s<<endl;
   if(s[5]=='1' || s[6]>='5')cout<<"TBD"<<endl;
   else cout<<"Heisei"<<endl;
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    string s;
    cin >> s;
    if (s.length() == 2)
    {
        cout << s << endl;
        return;
    }
    reverse(all(s));
    cout << s << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 1000000
#define SENTI 2000000000

struct Card{
  char p;
  int n;
};

struct Card L[MAX / 2 + 2];
struct Card R[MAX/ 2 + 2];

void Merge(struct Card *, int, int, int, int);
void mergeSort(struct Card *, int, int, int);

int Partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card x, key;

  x = A[r];
  i = p - 1;
  for(j = p ; j < r ; j++){
    if(A[j].n <= x.n){
      i++;
      key = A[i];
      A[i] = A[j];
      A[j] = key;
    }
  }
  key = A[i + 1];
  A[i + 1] = A[r];
  A[r] = key;
  return i+1;
}



void QuickSort(struct Card A[], int n, int p, int r){
  int x;

  if(p < r){
    x = Partition(A, n, p, r);
    QuickSort(A, n, p, x - 1);
    QuickSort(A, n, x + 1, r);
  }
}



int main(){
  int n, i, kati;
  int stable = 1;
  char P[10];
  struct Card A[MAX], B[MAX];

  scanf("%d",&n);
i=0;
  while(i < n){
    scanf("%s %d",P,&kati);
    A[i].p = B[i].p = P[0];
    A[i].n = B[i].n = kati;
    i++;
  }

  mergeSort(A,n,0,n);
  QuickSort(B,n,0,n-1);
i=0;
  while(i < n ){
    if(A[i].p != B[i].p) stable = 0;
    i++;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");
i=0;
  while( i < n ){
    printf("%c %d\n",B[i].p,B[i].n);
    i++;
  }

  return 0;
}

void Merge(struct Card A[], int n, int left, int mid, int right){
  int n1, n2, i, j, k;

  n1 = mid - left;
  n2 = right - mid;
  i=0;
  while(i < n1 ){
   L[i] = A[left + i];
   i++;
 }
 i=0;
  while(i < n2 ){
     R[i] = A[mid + i];
     i++;
   }
  L[n1].n = R[n2].n = SENTI;

  i = 0;
  j = 0;
  for(k = left ; k < right ; k++){
    if(L[i].n <= R[j].n) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int n, int left, int right){
  int m;
  if(left + 1 < right){
    m = (left + right) / 2;
    mergeSort(A, n, left, m);
    mergeSort(A, n, m, right);
    Merge(A, n, left, m, right);
  }
}



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

using namespace std;

int main(){

    int a,n,t;
    cin >> n >> t >> a;

    long d=10000000,h,tem,pos=0;
    for(int i=0;i<n;i++){
        cin >> h;
        tem=abs(a-(t-h*0.006))*1000;
        if(d>tem){
            d=tem;
            pos=i+1;
        }
    }
    cout << pos << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
//const ll MOD=1000000007LL;
const ll MOD=998244353;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

class BIT{
public:
	vector<ll> bit;
	ll M;
	// 1-index
	BIT(ll M):
		bit(vector<ll>(M+1, 0)), M(M) {}

	ll sum(ll i) {
		if (!i) return 0;
		return bit[i] + sum(i-(i&-i));
	}

	void add(ll i, ll x) {
		if (i > M) return;
		bit[i] += x;
		add(i+(i&-i), x);
	}
};

int main(){

	ll N,Q;
	cin >> N >> Q;
	BIT bit(N+3);
	FOR(i,0,N){
		ll a;
		cin >> a;
		bit.add(i+1,a);
	}


	FOR(q,0,Q){
		ll a,b,c;
		cin >> a >> b >> c;
		b++,c++;
		if(a){
			cout << bit.sum(c-1) - bit.sum(max(0LL,b-1)) << endl;
		}else{
			bit.add(b,c-1);
		}
	}
}



Measured memory_bytes: 8204
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
//ll const mod=998244353;
ll const mod = 1e9 + 7;
const ll MAX = 300000;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }
const ll LINF=1e18+1;

vi v,w;
vvl dp;
//////////////////////////////////////

void get_dp(){
  dp[0][0]=0;
  arep(i,1,1030){
    rep(j,100003){
      dp[i][j]=dp[i/2][j];
      if(j>=w[i])chmax(dp[i][j],dp[i/2][j-w[i]]+v[i]);
    }
  }
}

ll rec(int c,int L){
  if(L<0)return -LINF;
  if(c<=1024)return dp[c][L];
  return max(rec(c/2,L),rec(c/2,L-w[c])+v[c]);
}


int main() {
    int n;
    cin>>n;
    
    v.resize(max(n+1,1030),0);
    w.resize(max(n+1,1030),0);
    dp.resize(1030,vl(100005,0));

    rep(i,n){
      cin>>v[i+1]>>w[i+1];
    }
    get_dp();
    vl ans;
    int q;
    cin>>q;
    rep(i,q){
      int c,L;
      cin>>c>>L;
      ans.push_back(rec(c,L));
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 814568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String oldstr = scan.nextLine();
		scan.close();
		String newstr = "";
		//char substr[] = str.toCharArray();
		for(int i = 0; i < oldstr.length(); i++){
			String target = oldstr.substring(i, i + 1);
			if(target.equals(target.toLowerCase())){
				target = target.toUpperCase();
			}else if(target.equals(target.toUpperCase())){
				target = target.toLowerCase();
			}
			newstr += target;
		}
		System.out.println(newstr);
	}
}

Measured memory_bytes: 31948
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;

int main(){
    int N, A;
    cin >> N >> A;
    int X[N];
    rep(i,N){
        cin >> X[i];
    }
    int zero = 50 * 50;
    vector<vector<ll>> dp(N+1,vector<ll>(2*50*50+1,0));
    dp[0][0+zero] = 1;
    rep(i,N){
        repf(j,-50*i,50*i+1){
            dp[i + 1][j + X[i] - A+zero] += dp[i][j+zero];
            dp[i + 1][j+zero] += dp[i][j+zero];
        }
    }
    cout << dp[N][0+zero]-1 << endl;
}


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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  int n;
  cin>>n;
  int s = 0;
  for(int i = 0; i < n; ++i){
    int tmp;
    cin >> tmp;
    while((tmp&1) == 0){
      ++s;
      tmp /=2;
    }
  }
  cout<<s<<"\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) cout << mat[i][j] << " "; cout << endl; }

using namespace std;

typedef long long int ll;
typedef pair <int, char> ii;
typedef pair <int, ii> iiii;


int main(){
	
	ll n, a; cin >> n >> a;
	n = n%500;
	if(n<=a) puts("Yes");
	else puts("No");

	
}

Measured memory_bytes: 256