akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    string s; cin >> s;
    int n = s.size();
    deque<char> dq;
    for (int i = 0; i < n; ++i) {
        dq.push_back(s[i]);
    }
    int Q; cin >> Q;
    int num = 0;
    for (int _ = 0; _ < Q; ++_) {
        int t; cin >> t;
        if(t==1){
            ++num;
        }
        else{
            int f; char c;
            cin >> f >> c;
            if(f==1){
                if(num % 2 != 0){
//                    s += c;
                    dq.push_back(c);
                }
                else{
//                    s.insert(0, 1, c);
                    dq.push_front(c);
                }
            }
            else{
                if(num % 2 == 0){
//                    s += c;
                    dq.push_back(c);
                }
                else{
//                    s.insert(0, 1, c);
                    dq.push_front(c);
                }
            }
        }
    }
    if(num % 2 != 0) reverse(dq.begin(), dq.end());
    int m = dq.size();
    for (int i = 0; i < m; ++i) {
        cout << dq[i];
        if(i == m-1) cout << endl;
    }
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 896
#もっといい方法全然あると思われ
import copy
r, c = map(int, input().split())
a = [input().split() for i in range(r)]

M=copy.copy(a)
tmp = []
all = 0

for i in range(r):
    s_r = 0
    s_c = 0
    for j in range(c):
        s_r += int(a[i][j])

    M[i].append(s_r)

for i in range(c):
    s_c = 0
    for j in range(r):
        s_c += int(a[j][i])
    tmp.append(s_c)
    all += s_c
tmp.append(all)
M.append(tmp)

for i in range(r+1):
    for j in range(c+1):
        print(str(M[i][j]),end="")
        if j != c:
            print(" ",end="")
        
    print("")



Measured memory_bytes: 7872
#include<iostream>
int m=1e9+7;
int main(){int N,M;std::cin>>N>>M;long d[N+1],a=M-N+1;d[0]=1,d[1]=M-N;for(int i=2;i<=N;i++){d[i]=((M-N+i-1)*d[i-1]+(i-1)*d[i-2])%m;a=a*(M-i+2)%m;}std::cout<<a*d[N]%m;}


Measured memory_bytes: 7352
#include<bits/stdc++.h>
using namespace std;
long long n;
pair<long long,long long>a[200005];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].first,&a[i].second);
		if(a[i].first>a[i].second)swap(a[i].first,a[i].second);
	}
	sort(a+1,a+n+1);
	long long mnf=1e18,mns=1e18,mxf=-1e18,mxs=-1e18;
	for(int i=1;i<=n;i++)mnf=min(mnf,a[i].first);
	for(int i=1;i<=n;i++)mxf=max(mxf,a[i].first);
	for(int i=1;i<=n;i++)mns=min(mns,a[i].second);
	for(int i=1;i<=n;i++)mxs=max(mxs,a[i].second);
	long long ans=(mxf-mnf)*(mxs-mns),nw=1e18;
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,(mxs-mnf)*(mxf-min(nw,a[i].first)));
		nw=min(nw,a[i].second);
		mxf=max(mxf,a[i].second);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){rep(i,N+1){rep(j,M+1){if(arr[i][j]==INF)printf(" INF");\
	else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};
//--------------------------------------//
int n;
int a[2*100000];

ll o;
ll ans;

int main(){
	cin>>n;
	rep(i,n) {
		cin>>a[i];
		a[i]-=i;
	}
	sort(a,a+n);
	if(n%2==1) o=a[n/2];
	else o=(a[n/2-1]+a[n/2])/2;
	rep(j,n){
		ans+=abs(a[j]-o);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[200000];
	rep(i, N) A[i] = getint();

	ll AB[200000];
	ll keiAB = A[0], saA = A[0];
	int p = 0;

	for (int i = 1; i < N - 2; i++) {
		keiAB += A[i];
		saA -= A[i];
		while (p + 1 < i && saA + A[p + 1] + A[p + 1] < 0) {
			p++;
			saA += A[p] + A[p];
		}
		ll kari = min(abs(saA), saA + A[p + 1] + A[p + 1]);
		AB[i] = kari;
	}
	ll S = keiAB + A[N - 2] + A[N - 1];

	ll kotae = 1e18;
	ll keiCD = A[N - 1], saD = A[N - 1];
	p = N - 1;
	for (int i = N - 2; i >= 2; i--) {
		keiCD += A[i];
		saD -= A[i];
		while (p - 1 > i && saD + A[p - 1] + A[p - 1] < 0) {
			p--;
			saD += A[p] + A[p];
		}
		ll kari = min(abs(saD), saD + A[p - 1] + A[p - 1]);

		kotae = min(kotae, max(S - keiCD + AB[i - 1], keiCD + kari) - min(S - keiCD - AB[i - 1], keiCD - kari));
	}
	co(kotae / 2);

	Would you please return 0;
}

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

int main ()
{
    char s[10000] ;
    int i,len,j,cnt=0;

    scanf("%s",&s) ;

    len=strlen(s) ;

    for(i=0,j=(len-1);i<(len/2);i++,j--){
            if(s[i]!=s[j])cnt++;
    }
    printf("%d\n",cnt) ;

    return 0 ;
}


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

int main(void) {
    int attend_num, i;
    int cnt[4] = {0};
    char str[3];
    
    while(scanf("%d,%s", &attend_num, str) != EOF) {
        if(!(strcmp(str, "A")))
            cnt[0]++;
        else if(!(strcmp(str, "B")))
            cnt[1]++;
        else if(!(strcmp(str, "AB")))
            cnt[2]++;
        else if(!(strcmp(str, "O")))
            cnt[3]++;
    }
    
    for(i = 0; i < 4; i++) {
        printf("%d\n", cnt[i]);
    }
    
    return(0);
}

Measured memory_bytes: 596
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T chmin(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T chmax(T& l, T r) {
    return l = max(l, r);
}
// ============ template finished ============

bool isEdge(const int N, const int h, const int w) {
    return h == 0 || w == 0 || h == N - 1 || w == N - 1;
}

vector<vector<int>> build(const vector<vector<bool>>& filled) {
    const int N = filled.size();
    // if went to <h,w>, cost will be dist[h][w]
    vector<vector<int>> dist(N, vector<int>(N, INF));
    queue<pii> q;
    rep(h, N)rep(w, N) if (isEdge(N, h, w) && !filled[h][w]) {
        q.push({ h,w });
        dist[h][w] = 0;
    }
    rep(h, N)rep(w, N) if (isEdge(N, h, w) && filled[h][w]) {
        q.push({ h,w });
        dist[h][w] = 1;
    }

    while (!q.empty()) {
        int h, w;
        tie(h, w) = q.front(); q.pop();
        rep(d, 4) {
            int nh = h + dh[d], nw = w + dw[d];
            if (!isin(N, N, nh, nw))continue;
            int ndist = dist[h][w] + (filled[h][w] ? 1 : 0);
            if (dist[nh][nw] <= ndist)continue;
            dist[nh][nw] = dist[h][w] + 1;
            q.push({ nh,nw });
        }
    }
    return dist;
}

int main()
{
    int N;
    cin >> N;
    vector<int> P(N*N);
    rep(i, N*N) {
        cin >> P[i];
        P[i]--;
    }

    vector<int> ress;
    vector<vector<bool>> filled(N, vector<bool>(N, true));
    auto dist = build(filled);
    for (auto p : P) {
        int h = p / N, w = p % N;
        ress.push_back(dist[h][w] - 1);
        dist[h][w]--;
        filled[h][w] = false;

        queue<pii> q;
        rep(d, 4) {
            int nh = h + dh[d], nw = w + dw[d];
            if (isin(N, N, nh, nw))q.push({ nh,nw });
        }

        while (!q.empty()) {
            auto now = q.front(); q.pop();
            int score = INF;
            rep(d, 4) {
                int nh = now.first + dh[d], nw = now.second + dw[d];
                if (!isin(N, N, nh, nw))continue;
                score = min(score, dist[nh][nw] + (filled[now.first][now.second] ? 1 : 0));
            }
            if (score < dist[now.first][now.second]) {
                dist[now.first][now.second] = score;
                rep(d, 4) {
                    int nh = now.first + dh[d];
                    int nw = now.second + dw[d];
                    if (isin(N, N, nh, nw))q.push({ nh,nw });
                }
            }
        }
    }
    ll res = 0;
    for (auto num : ress)res += num;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6308
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// シミュレーション
		// 累積和の数え上げ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		String S = sc.next();

		// query
		int[][] lr = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			lr[i][0] = Integer.parseInt(sc.next());
			lr[i][1] = Integer.parseInt(sc.next());
		}

		solve(N, Q, S, lr);
	}

	static void solve(int n, int q, String s, int[][] lr) {
		int[] t = new int[n];
		for (int i = 0; i < n - 1; i++) {
			int add = s.substring(i, i + 2).equals("AC") ? 1 : 0;
			// 累積和でl-rの区間の出現数をカウントできるようにする
			t[i + 1] = t[i] + add;
		}

		for (int i = 0; i < q; i++) {
			int l = lr[i][0];
			int r = lr[i][1];

			System.out.println(t[r - 1] - t[l - 1]);
		}
	}
}


Measured memory_bytes: 70972
#include <bits/stdc++.h>
    using namespace std;
    //cin.ignore();	// better to use 2 times getline(cin,s);
    // g++ iterator.cpp -std=c++17
    //cout << (A + B == C ? "YES" : "NO") << endl;
    #define pb push_back
    #define mk make_pair
    #define vll vector<ll>
    #define mll map<ll,ll >
    #define mlli map<ll,ll>::iterator
    #define size size()
    #define endl "\n"
    #define ll long long int
    #define ld long double
    void fast(){
       	ios_base::sync_with_stdio(false);
       	cin.tie(NULL);
       	cout.tie(NULL);}
    
     int func(vector<int> &v)
     {
         int cnt=0;
         for(int i=0;i<v.size;i++)
         {
             cnt=cnt+(v[i]*pow(10,v.size-i-1));
         }
         return cnt;
     }
    int main(void)
    {
      fast();
      int a,b;
      int m,n;
      cin>>n>>m;
      vector<int>v(n,-1);
      if(n==1&&m==0){
          cout<<0<<endl;
          return 0;
      }
      for(int i=0;i<m;i++){
          cin>>a>>b;
          if(v[a-1]==-1){
              v[a-1]=b;
          }else if(v[a-1]!=-1&&v[a-1]!=b){
              cout<<-1<<endl;
              return 0;
          }
      }
      if(n==1&&m==0){
          cout<<0<<endl;
          return 0;
      }else if(n==1&&m!=0){
          cout<<v[0]<<endl;
          return 0;
      }
      if(v[0]==-1){
          v[0]=1;
      }else if(v[0]==0){
          cout<<-1<<endl;
          return 0;
      }
      for(int i=1;i<v.size;i++){
          if(v[i]==-1){
              v[i]=0;
          }
      }
      cout<<func(v)<<endl;
      return 0;
    }

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1)
    a=14;
  if(b==1)
    b=14;
  
  if(a>b)
    cout<<"Alice";
  else if(a<b)
    cout<<"Bob";
  else
    cout<<"Draw";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count =0;
  int t=0;
  if(s[0]=='A') count++;
  for(int i=2;i<s.size()-1;i++){
    if(s[i]=='C') t++;
  }
  if(t==1) count++;
  t=0;
  for(int i=0;i<s.size();i++){
    if(isupper(s[i])) t++;
  }
  if(t==2) count++;
  if(count==3){
    cout << "AC" << endl;
  }else{
    cout << "WA" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  int x, a;
  cin >> x >> a;
  if(x < a){
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }

}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    a,b,c = map(int, readline().split())

    if c - a - b > 0 and (c - a - b)**2 > 4*a*b:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        String[] s = new String[n];
        int c0 = 0;
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        for(int i = 0; i<n; i++) {
            s[i] = sc.next();
            switch (s[i]){
                case "AC":
                    c0++;
                    break;
                case "WA":
                    c1++;
                    break;
                case "TLE":
                    c2++;
                    break;
                case "RE":
                    c3++;
                    break;
            }
        }

        System.out.println("AC x " + c0);
        System.out.println("WA x " + c1);
        System.out.println("TLE x " + c2);
        System.out.println("RE x " + c3);
	}
}

Measured memory_bytes: 64216
import numpy as np
N = int(input())
L = np.zeros(87,np.int64)
L[0] = 2
L[1] = 1

def luca(n):
    if n == 0:
        return L[0]
    elif n == 1:
        return L[1]
    if L[n] != 0:
        return L[n]
    L[n] =luca(n-1) + luca(n-2)
    return L[n]
print(luca(N))

Measured memory_bytes: 14456
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string S;
  cin >> S;
  int Count,B,W;
  B = W = Count = 0;
  for(int i = 0; i < S.size();i++){
      if(i%2 == 0 && S[i] == '1') W++;
      else if(i%2 == 0 && S[i] == '0') B++;
  }
  if(W >= B){
      for(int i = 0; i < S.size(); i++){
          if(i%2 == 1 && S[i] != '0') Count++;
          else if(i%2 == 0 && S[i] != '1') Count++;
      }
  }
  else{
      for(int i = 0; i < S.size(); i++){
           if(i%2 == 1 && S[i] != '1') Count++;
           else if(i%2 == 0 && S[i] != '0') Count++;
        }
  }
  cout << Count << endl;
 }


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

#define ll long long

bool check(int a, int b, int c){
    if ((a < b && b < c) || (c < b && b < a)){
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n+1];

    for (int i = 1; i<=n; i++) cin >> a[i];

    int count = 0;
    for (int i = 2; i<= n-1; i++){
        if (check(a[i-1], a[i], a[i+1])) count++;
    }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
//#define endl "\n"
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	ll a,b,c; cin>>a>>b>>c;
	if(b*c >= a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const double PI = 3.14159265358979;

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

  double a, b, x;
  cin >> a >> b >> x;
  if(x/a > a*b/2.00){
    double teihen = a/2.000000000000;
    double depth = b - x/a/a;
    printf("%.10f\n", atan(depth/teihen)/PI*180.000);
  }else{
    double teihen = 2.00000000000*x/a/b;
    printf("%.10f\n", atan(b/teihen)/PI*180.000);
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b:i--)
//Binomial Coefficients
const long long c_max = 1000003;
const long long mod = 1e9+7;
long long fac[c_max], finv[c_max], inv[c_max];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < c_max; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
long long COM(long long comn, long long comk){
    if (comn < comk) return 0;
    if (comn < 0 || comk < 0) return 0;
    return fac[comn] * (finv[comk] * finv[comn - comk] % mod) % mod;
}
//Power
long long powmod(long long px, long long py, long long pmod){
	if(py == 0) return 1;
	if(py % 2 == 0) return powmod((px * px) % pmod, py / 2, pmod);
	else return (px * powmod(px, py - 1, pmod)) % pmod;
} 

int main() {
    // your code goes here
    COMinit();
    ll n,a,b,w,c=1,d=1;
    cin >> n >> a >> b;
    w=(powmod(2,n,mod)+mod-1)%mod;
    rep(i,0,a-1){
        c=(c*(n-i))%mod;
    }
    c=(c*finv[a])%mod;
    rep(i,0,b-1){
        d=(d*(n-i))%mod;
    }
    d=(d*finv[b])%mod;
    cout << (w+2*mod-c-d)%mod << endl;
    return 0;
}

Measured memory_bytes: 23680
[N,K]=map(int,input().split())
L=[]
for i in range(N):
        L.append(list(map(int,input().split())))
L.sort()
for i in range(N):
        K-=L[i][1]
        if K>=1:
                continue
        else:
                print(L[i][0])
                exit()



Measured memory_bytes: 27916
/**
 *      ABC 81 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-02 04:16:35
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s; cin >> s;
    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == '1'){
            ++count;
        }            
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s;
  cin>>s;
  if(s=="A") cout<<"T"<<endl;
  if(s=="T") cout<<"A"<<endl;
  if(s=="G") cout<<"C"<<endl;
  if(s=="C") cout<<"G"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    unsigned long long a[100001]={1,1};
    for(int i=2;i<=100000;i++){
        a[i]=a[i-1]*i%1000000007;
    }
 
    if(n==m){
        a[0]=a[n]*a[m]*2%1000000007;
        cout<<a[0];
    }else if(n-m==1 || m-n==1){
        a[0]=a[n]*a[m]%1000000007;
        cout<<a[0];
    }else
        cout<<0;
    
}

Measured memory_bytes: 1656
require 'pp'
N,d=gets.chomp.split(' ').map{|n| n.to_i}

# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end

Vacant = "Vacant"
Male = "Male"
Female = "Female"

def get_another_sex(sex)
	case sex
	when "Male"
		return "Female"
	when "Female"
		return "Male"
	end
end
# sex of from when no space
def find(from,to,sex)
	if(from==to)
		dputs "terminate. #{from}"
		return from
	end
	choise = 0
	offset = (to-from+1)/2
	is_even_num = ((to-from+1)%2==0)
	is_even_even_num = (((to-from+1)/2)%2==0)
	dputs is_even_num
	dputs is_even_even_num
	if(is_even_num)
		# b+n-1
		choise = from+offset-1
	else
		# b+n
		choise = from+offset
	end
	puts "#{choise}"
	STDOUT.flush
	res = gets.chomp
	if(res == Vacant)
		return choise
	elsif(is_even_num && is_even_even_num || !is_even_num && !is_even_even_num)
		# ex. 4 : 4 5 6 7 -> 5 must be another of sex 4
		# ex. 7 : 7 8 9 10 11 12 13 -> 10 another
		dputs "first case"
		case res
		when get_another_sex(sex)
			dputs "first first case"
			# space exists between choise+1 to to
			return find(choise+1, to, sex)
			dputs "first second case"
		when sex
			return find(from, choise-1, sex)
		else
			dputs res
			dputs " ?????"
		end
	else
		dputs "second case"
		case res
		when sex
			dputs "second first case"
			return find(choise+1, to, get_another_sex(sex))
		when get_another_sex(sex)
			dputs "second second case"
			return find(from, choise-1, sex)
		end
	end
end

puts "0"
STDOUT.flush
sex_init = gets.chomp
ans = find(1, N-1, get_another_sex(sex_init))
dputs "ans"
puts ans
STDOUT.flush


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

using namespace std;

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

    int k[m];
    int tmp;
    vector<int> switches[m];
    for(int i = 0; i < m; i++) {
        cin >> k[i];
        for(int j = 0; j < k[i]; j++) {
            cin >> tmp;
            tmp--;
            switches[i].push_back(tmp);
        }
    }

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

    int max_bit = 1 << n;
    int count = 0;
    for(int i = 0; i < max_bit; i++) {
        int l;
        for(l = 0; l < m; l++) {
            int sum = 0;
            for(int s = 0; s < k[l]; s++) {
                if(i & (1 << switches[l][s])) {
                    sum++;
                }
            }
            if(sum % 2 != p[l]) break;
        }
        if(l == m) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int c[10];

int main(void){
	          int i;

	          int n;
	          cin >> n;
	          int s=0;
	          for(i=1;i<=n;i++){
	        	  int a;
	        	  cin >> a;
	        	  if(a<=399) c[1]=1;
	        	  else if(a<=799) c[2]=1;
	        	  else if(a<=1199) c[3]=1;
	        	  else if(a<=1599) c[4]=1;
	        	  else if(a<=1999) c[5]=1;
	        	  else if(a<=2399) c[6]=1;
	        	  else if(a<=2799) c[7]=1;
	        	  else if(a<=3199) c[8]=1;
	        	  else{
	        		  s++;
	        	  }
	          }

	          int b=0;
	          for(i=1;i<=8;i++) b+=c[i];

	          cout << max(1,b) << ' ' << b+s << endl;

	          return 0;
}


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

int main(){
    int grid[14][14];
    int s[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
    int m[4][2]={{-1,-1},{-1,1},{1,-1},{1,1}};
    int l[4][2]={{0,-2},{0,2},{-2,0},{2,0}};
    int x, y, size;
    int i, j;
    int max=0;
    int blank=0;
    char comma;
    for(i=0;i<14;i++){
        for(j=0;j<14;j++){
            grid[i][j] = 0;
        }
    }
    while(cin >> x >> comma >> y >> comma >> size){
        x += 2;
        y += 2;
        grid[x][y] += 1;
        for(i=0;i<4;i++){
            grid[x+s[i][0]][y+s[i][1]] += 1;
        }
        if(size > 1){
            for(i=0;i<4;i++){
                grid[x+m[i][0]][y+m[i][1]] += 1;
            }
            if(size > 2){
                for(i=0;i<4;i++){
                    grid[x+l[i][0]][y+l[i][1]] += 1;
                }
            }
        }
    }
    for(i=2;i<12;i++){
        for(j=2;j<12;j++){
            if(grid[i][j] > max){
                max = grid[i][j];
            }else if(grid[i][j] == 0){
                blank += 1;
            }
        }
    }
    cout << blank << endl;
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 0
def main():
    n = int(input())
    xus = [input() for _ in range(n)]
    ans = 0
    for xu in xus:
        x, u = xu.split()
        if u == "JPY":
            ans += float(x)
        if u == "BTC":
            ans += float(x) * 380000.0

    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  for (int i = 0; i < k; i++)
  {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++)
    {
      int tmp;
      cin >> tmp;
      m[tmp]++;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (m[i] == 0)
      cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m, a, b;
vector<pair<ll, ll>> ab;

int main(){
	cin >> n >> m;
	for(ll i = 0; i < n; i++){
		cin >> a >> b;
		ab.push_back(make_pair(a, b));
	}
	
	sort(ab.begin(), ab.end());
	
	ll ans = 0;
	ll itr = 0;
	while(m > 0){
		ans += ab[itr].first*min(ab[itr].second, m);
		m -= min(ab[itr].second, m);
		itr++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
//typedef complex<double>P;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS*(abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑



ll n, k[200005], ans[200005];
vector<int>v;
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> k[i];
	}

	for (int i = n; i > 0; --i) {
		ll mon = 0;
		for (int j = 2 * i; j <= n; j += i) { mon += ans[j]; }
		if (mon % 2 != k[i]) {
			ans[i] = 1;
		}
	}

	for (int i = 1; i <= n; ++i) {
		if (ans[i]) { v.push_back(i); }
	}
	cout << v.size() << endl;
	for (auto i : v) { cout << i << " "; }
	cout << endl;
}

Measured memory_bytes: 5496
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;

class eratosthenes {
public:
	vector<int> prime_n;
	bool prime[500001];

	eratosthenes() {
		fill(prime, prime + 500001, true); //素数
		prime[0] = prime[1] = false;
		for (int i = 2; i < 500001; i++) {
			if (prime[i] == true) {
				prime_n.push_back(i);
				for (int j = 2; i * j < 500001; j++) {
					prime[i * j] = false;
				}
			}
		}
	}
};


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

	int cnt = 0;
	rep(i, 55555){
		if(p.prime_n[i] % 5 == 1){
			cout << p.prime_n[i] << " ";
			cnt++;
		}
		if(cnt == n) break;
	}
	cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    int gcd = a[0];
    rep(i, n-1)
    {
        gcd = GCD(gcd, a[i+1]);
    }
    
    cout << gcd << endl;
    
    return 0;
}

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

typedef long long ll;

int main() {
    ll N, M, A;
    cin >> N >> M;
    rep(i, M) {
        cin >> A;
        N -= A;
    }
    cout << max(-1LL, N) << "\n";
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const int INF_INT = 1 << 25;
const long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;


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



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

	ll n;
	cin>>n;
	ll m=1001;
	Matrix sum(m+1,Array(m+1,0));
	REP(i,n){
		ll x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		sum[x1][y1]++;
		sum[x1][y2]--;
		sum[x2][y1]--;
		sum[x2][y2]++;
		
	}

	REP(i,m){
		REP(j,m){
			sum[i+1][j]+=sum[i][j];
		}
	}

	REP(i,m){
		REP(j,m){
			sum[j][i+1]+=sum[j][i];
		}
	}

	ll ans=0;
	REP(i,m){
		REP(j,m){
			chmax(ans,sum[i][j]);
		}
	}
	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 10804
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	string s; cin>>s;
	int n = s.size();
	int val[n+1] = {0};
	int i=0, j=1;
	while(j<n){
		while(j<n && s[j]!='L'){
			j++;
		}
		val[j]++;
		val[j-1]++;
		// For(i, 0, n){
		// 	cout<<val[i]<<" ";
		// }
		while(i<j-1){
			if((i-j)%2){
				val[j-1]++;
			}else{
				val[j]++;
			}
			i++;
		}
		i=j+1;
		while(i<n && s[i]!='R'){
			if((i-j)%2){
				val[j-1]++;
			}else{
				val[j]++;
			}
			i++;
		}
		j=i+1;
	}

	For(i, 0, n){
		cout<<val[i]<<" ";
	}
	cout<<endl;
    return 0;
}
    



Measured memory_bytes: 1488
import sys
def input(): return sys.stdin.readline().strip()

i  = lambda: int(input())
li = lambda: list(map(int, input().split()))

N = i()
H = li()

ans = 0
count = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    count += 1
  else:
    if ans < count:
      ans = count
    count = 0

if ans < count:
    ans = count

print(ans)

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    rep(i, N - 2) {
        if (S.substr(i, 3) == "ABC") {
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*
import kotlin.system.exitProcess

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.nextLine()
    val arr = arrayOf("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
    for (char in arr) {
        if (!s.contains(char)) {
            println(char)
            exitProcess(0)
        }
    }
    println("None")
}




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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 5;
const int mod = (int) 1e9 + 7;

int n,k,sum,cnt;
int a[N],dp[5005];


bool check(int x) {
        memset(dp,0,sizeof(dp));
        dp[0] = 1;

        for (int i = 1; i <= n; i ++) {
                if(i == x)
                        continue;
                for (int j = k - a[i]; j >= 0; j --) {
                                dp[j + a[i]] |= dp[j];
                }
        }
        for (int i = max(k - a[x],0); i <= k - 1; i ++) {
                if(dp[i] == 1)
                        return true;
        }
        return false;
}
int main () {

        cin >> n >> k;

        for (int i = 1; i <= n; i ++) {
                cin >> a[i];
        }
        sort(a + 1,a + n + 1);

        int l = 0, r = n + 1;

        while(r - l > 1) {
                int m = (r + l) >> 1;
                if(check(m))
                        r = m;
                else
                        l = m;
        }
        cout << l << endl;
        return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>

using namespace std;

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

    int sum;
    for(int i = 0; i < (int)n.size(); ++i){
        sum += n[i] - '0';
    }
    
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;

    return 0;
}


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

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

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

	int s[2];
	int ans = 1e9;
	for(int j = 0; j < n; j++){
		s[0] = 0;
		s[1] = 0;
		for(int i = 0; i <= j; i++){
			s[0] += w[i];
		}
		for(int i = j + 1 ;i < n; i++){
			s[1] += w[i];
		}
		ans = min(ans, abs(s[0] - s[1]));
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


int main(){
    string s;   cin >> s;
    for(int i = 0; i < s.size(); i++){
        cout << "x";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for (int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n, d;
    ll x, y;
    ll res = 0;
    cin >> n >> d;
    REP(i, n) {
        cin >> x >> y;
        if (x*x + y*y <= d*d) {
            res += 1;
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
    int a,b,c,n,m,i,o,p,q,r,test[1000][3],num,chk[300];
    cin >> a >> b >> c;
    m = a+b+c;
    while(m!=0){
        for(i=0; i<m; i++){
            chk[i] = 2;
        }
        cin >> n;
        num = 0;
        for(i=0; i<n; i++){
            cin >> o >> p >> q >> r;
            o--;
            p--;
            q--;
            if(r==1){
                chk[o] = 1;
                chk[p] = 1;
                chk[q] = 1;
            }else{
                test[num][0] = o;
                test[num][1] = p;
                test[num][2] = q;
                num++;
            }
        }
        for(i=0; i<num; i++){
            o = test[i][0];
            p = test[i][1];
            q = test[i][2];
            if(chk[o]==2 && chk[p]==1 && chk[q]==1){
                chk[o] = 0;
            }else if(chk[o]==1 && chk[p]==2 && chk[q]==1){
                chk[p] = 0;
            }else if(chk[o]==1 && chk[p]==1 && chk[q]==2){
                chk[q] = 0;
            }
        }
        for(i=0; i<m; i++){
            cout << chk[i] << endl;
        }
        cin >> a >> b >> c;
        m = a+b+c;
    }
    return 0;
}

Measured memory_bytes: 1168
# ?´???°?????°?????¨?????????????????°??????

import sys
import math

prim_no = {2: True}                    # ????????°????´???°??§??????????????????????????????

def is_prime(no):
    if no == 2 or no == 1:
        return True
    
    if no % 2 == 0:
        return False

    if prim_no.get(no) is not None:
        return prim_no.get(no)

    max_check = int(math.sqrt(no))
    for i in range(3, max_check+1, 2):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

def main():
    prim_vals = {}                         # ????????°?????§????´???°????????°
    while True:
        num = sys.stdin.readline()
        if num is None or num.strip() == '':
            break

        num = int(num.strip())
        if prim_vals.get(num) is not None:
            cnt = prim_vals.get(num)
        else:
            if num == 1:
                cnt = 0
            else:
                cnt = 0

                if num % 2 == 0:
                    start_num = num -1
                else:
                    start_num = num
                    
                for i in range(start_num, 0, -2):
                    if prim_vals.get(i) is not None:
                        cnt += prim_vals.get(i)
                        break
                    
                    if is_prime(i):
                        cnt += 1
                        
                prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????

        print(cnt)

if __name__ == '__main__':
    main()
    #print(prim_no)

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    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;
  }
  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 d[100002];

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

    for(int i = 1; i < k+1; ++i) {
        mint x = k / i;
        d[i] = x.pow(n);
    }
    for(int i = k; i >= 1; --i) {
        for(int j = 2 * i; j < k+1; j = j + i){
            d[i] -= d[j];
        }
    }

    mint ans;
    for(int i = 1; i < k+1; ++i) {
        ans += d[i] * mint(i);
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 4364
#include <iostream>

using namespace std;

int n, data[101];

int solve(){
  for(int i=1;i<n;i++){
    int d = data[1] - data[0];
    if(i == 1) d = data[2] - data[0];
    int p = data[0];
    for(int j=1;j<n;j++){
      if(i == j) continue;
      if(data[j] - p != d) goto CONT;
      p = data[j];
    }
    return data[i];
    CONT:;
  }
  return data[0];
}

main(){
  while(cin >> n && n){
    n++;
    for(int i=0;i<n;i++){
      cin >> data[i];
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1160
n, m, l = gets.split.map(&:to_i)

a = []
n.times do 
	a << gets.split.map(&:to_i)
end

b = []
m.times do
	b << gets.split.map(&:to_i)
end

c = []

n.times do |i|
	c[i] = []
	l.times do |j|
		c[i][j] = 0
		m.times do |k|
			c[i][j] += a[i][k] * b[k][j]
		end
	end
end

puts c.map{|e| e*' '}

Measured memory_bytes: 6440
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  ll N,ans=1000;
  cin>>N;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  RREP(i,N-1){
    if(A[i]>A[i-1]){
      ans=ans/A[i-1]*A[i]+ans%A[i-1];
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 3572
import sys
def unzip(instd):
    for i in range(26):
        search = ""
        for idx in instd:
            if 97 <= ord(idx) <= 122:
                if ord(idx) + i <= 122:
                    search += chr(ord(idx) + i)
                else:
                    search += chr(ord(idx) + i - 26)
            else:
                search += idx
        if 'the' in search or 'this' in search or 'that' in search:
            return search


for line in sys.stdin:
    print(unzip(line.rstrip()))

Measured memory_bytes: 7424
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

typedef long long ll;

const int mod=1e9+7;
const int INF=INT_MAX;

int main(){
    int n;
    cin >> n;
    vector<pair<string,pair<int,int> > > sp(n);
    for(int i=0;i<n;i++){
        string S;
        int P;
        cin >> S >> P;
        sp[i]=mp(S,mp(P,i+1));
    }
    sort(sp.begin(),sp.end());
    for(int i=0;i<n;i++){
        vector< pair<int,int> > a;
        a.pb(sp[i].s);
        while(i<n-1&&sp[i].f==sp[i+1].f){
            a.pb(sp[i+1].s);
            i++;
        }

        if(a.size()){
            sort(a.begin(),a.end());
            reverse(a.begin(),a.end());
            for(int j=0;j<a.size();j++){
                cout << a[j].s << endl;
            }
        }

    }
    return 0;
}

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

int main() {
  vector<int> c(9);
  for (int i = 0; i < 9; i++) {
    cin >> c.at(i);
  }
  
  bool a = false;
  
  for (int i = 0; i <= 100; i++) {
    if (a == true) {
      break;
    }
    for (int j = 0; j <= 100; j++) {
      for (int k = 0; k <= 100; k++) {
        if (c.at(1) == i + c.at(4) - j) {
          if (c.at(2) == i + c.at(8) - k) {
            if (c.at(3) == j + c.at(0) - i) {
              if (c.at(5) == j + c.at(8) - k) {
                if (c.at(6) == k + c.at(0) - i) {
                  if (c.at(7) == k + c.at(4)- j) {
                    cout << "Yes" << endl;
                    a = true;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  if (a == false) {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256