akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
#define ld long double 
#define float long double 
#define ll long long
#define int long long
#define vl vector<ll> 
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define MAXN 100009
#define CASET int ___T; scanf("%lld", &___T); for(int cs=1; cs <= ___T; cs++)
template<class T> bool umin(T& a, T b) { if(a > b){ a = b;return 1;}return 0;}
template<class T> bool umax(T& a, T b) { if(a < b){ a = b;return 1;}return 0;}
const int N = 200 * 1000 + 9;
const int  inf = 1e18;
const int mod=1e9+7;
int i,j,k;
void solve(){
  string s; cin >> s;
  
  int q;  scanf("%lld",&q);
  int lst_state = 0;
  string frn ="";
  while(q--){
    int t; scanf("%lld",&t);
    if(t == 1){
      lst_state = (lst_state + 1) % 2;
    }
    else if(t == 2){
       int p ; scanf("%lld",&p); 
       char c;  cin >> c;
       if(lst_state == 0){
             if(p == 1)  frn.pb(c);
             else s.pb(c);
       }
       else {
        if(p == 1) s.pb(c);
        else frn.pb(c);
       }
    }
  }
  reverse(all(frn));
  s = frn + s;
  if(lst_state == 1) reverse(all(s));
  cout << s << endl;


 return ;
}
    signed main(){
   
    //CASET
    solve();
    
   
    return 0;
  }

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll A,B,C;
	cin>>A>>B>>C;
    string ans = "No";
    if(A==B){
        if(B!=C){
            ans = "Yes";
        }
    }else{
        if(B==C){
            ans ="Yes";
        }else if(A==C){
            ans ="Yes";
        }
    }
    cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5+5;
ll n, a[nax], b[nax];
	
int main(){
	IOS
	cin >>n;
	for(int i=0;i<=n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	ll ans=0;
	for(int i=0;i<n;i++){
		ll depan=a[i+1], belakang=a[i], hiro=b[i];
		b[i]-=min(hiro, belakang);
		ans+=min(hiro, belakang);
		hiro=b[i];
		a[i+1]-=min(a[i+1], hiro);
		ans+=min(depan, hiro);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5220
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

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

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

 	ll n, m, c = 0, pp = 0;
 	cin >> n >> m;
 	ll x[n + 1], done[n + 1] = {0}, val[n + 1] = {0};
 	for(int i=0;i<m;i++)
 	{
 		ll p;
 		string a;
 		cin >> p >> a;
 		if(a == "AC")
 		{
 			if(done[p] == 0) 
 			{	
 				done[p] = 1;
 				c += 1;
 				pp += val[p];
 			}	
 		}
 		else
 		{
 			if(done[p] == 0)
 				val[p] += 1;
 		}
 	}   
 	cout << c << " " << pp << endl;
    return 0;
}

Measured memory_bytes: 1792
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long r) {
    return r ^^ 2;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long r;
    r = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(r);
    else {
        auto ans = solve(r);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


Measured memory_bytes: 256
'''
path = 'sub1_51.txt'
f=open(path)
data1 = f.read()
f.close()
N=data1.split()
'''
n,k=map(int,input().split())
A=list(map(int,input().split()))
'''
n=int(N[0])
k=int(N[1])
A=N[2:]
'''
A=[int(i)-1 for i in A]
B=[]
cnt=[0]*n
m=0
for i in range(2*10**5):
    B.append(m)
    cnt[m]+=1
    if cnt[m]>1:
        break
    m=A[m]
c=len(B)-(B.index(m)+1)
print(1+B[(max(k-B.index(m),0))%c + min(B.index(m),k)])
#Bは街の移動順序
#cはループの長さ

Measured memory_bytes: 30960
using System;

class Program
{
 static void Main(string[] args)
 {
   string str = Console.ReadLine();
   int[] nums = new int[4];
   int cnt = 0;
   int sum = 0;
   
   for( cnt = 0; cnt < 4; cnt++ )
   {
     nums[cnt] = int.Parse(str[cnt].ToString());
   }
   
   for( cnt = 0; cnt < 8; cnt++ )
   {
     sum = ( ( ( cnt & 0x04 ) == 0x00 ) ? nums[0] + nums[1] : nums[0] - nums[1] );
     sum = ( ( ( cnt & 0x02 ) == 0x00 ) ? sum + nums[2]: sum - nums[2] );
     sum = ( ( ( cnt & 0x01 ) == 0x00 ) ? sum + nums[3]: sum - nums[3] );
     
     if( sum == 7 )
     {
       break;
     }
   }
   
   Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7",
                     nums[0],
                     ( ( ( cnt & 0x04 ) == 0x00 ) ? "+": "-" ),
                     nums[1],
                     ( ( ( cnt & 0x02 ) == 0x00 ) ? "+": "-" ),
                     nums[2],
                     ( ( ( cnt & 0x01 ) == 0x00 ) ? "+": "-" ),
                     nums[3]
                    );
 }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define int long long


signed main(){
    int k;
    cin >>k;
    int a[k];
    for(int i=0;i<k;i++)cin>>a[i];
    int ng=1,ok=2;
    for(int i=k-1;i>=0;i--){
        ng=(1 + ng/a[i])*a[i]-1;
        ok =(1+ ok/a[i])*a[i]-1;
        if(ng>=ok)break;
    }
   if(ng<ok) cout <<ng+1<<' '<<ok;
   else cout <<-1;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

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 { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll n, x, y;
  cin >> n;
  vl e(n + 1, -1);
  rep(i, n + 1) {
    ll a;
    cin >> a;
    if(e[a] == -1) {
      e[a] = i;
    } else {
      x = e[a];
      y = n - i;
    }
  }
  combination c(n + 10);
  rep2(k, 1, n + 2) {
    if(k == 1)
      cout << n << '\n';
    else {
      mint ans = c(n + 1, k);
      ans -= c(x + y, k - 1);
      cout << ans << '\n';
    }
  }
}

Measured memory_bytes: 5524
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 rr;
    cin >> rr;
    if(rr < 1200)
    {
        cout << "ABC" << endl;
    }
    else if(rr < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
	return 0;
}


Measured memory_bytes: 3620
import java.util.ArrayList;
import java.util.Scanner;

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

		int[] prime = new int[130000];
		for (int i = 0; i < prime.length; i++) {
			prime[i] = 1;
		}
		
		for (int i = 2; i < (prime.length / 2); i++) {
			for (int j = 2; (i * j) < prime.length; j++) {
				prime[i * j] = 0;
			}
		}
		prime[0] = 0;
		prime[1] = 0;
		
		ArrayList<Integer> al = new ArrayList<Integer>();
		
		for (int i = 0; i < prime.length; i++) {
			if (prime[i] == 1) al.add(i);
		}
		
		int lines = Integer.parseInt(sc.nextLine());
		while (lines != 0) {
			int s = 0;
			for (int i = 0; i < lines; i++) {
				s = s + al.get(i);
			}
			
			System.out.println(s);
			
			lines = Integer.parseInt(sc.nextLine());
		}
	}
}

Measured memory_bytes: 27476
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(c) (c).begin(), (c).end()
#define USE1(...) template <typename __VA_ARGS__> inline
#define USE2(T, ...) USE1(T, typename __VA_ARGS__)
#define mypc(c) putchar_unlocked(c)

using ll = long long;
template<typename T> using vec = std::vector<T>;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE2(T=int,V=vec<T>)V reserved(int n){V v;v.reserve(n);return v;}
USE1(T=int)vec<T>in(int n){auto v=reserved<T>(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=std::pair<T,int>)vec<U>enume(const vec<T>&x,int s=0){int N=x.size();auto v=reserved<U>(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE2(T,U)void prif(bool b,T t,U f){if(b)pr(t);else pr(f);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}

using ll = long long;
const ll mod = LLONG_MAX;

const int inf = 1001001001;

int N,M,R,T;
int r[10];
int d[210][210];

void init(){
  memset(d,0x3f,sizeof(d));
}
int main(){
  cin>>N>>M>>R;

  init();
  rep(i,R){
    int t;cin>>t;t--;
    r[i]=t;
    T+=pow(2,r[i]);
  }
  rep(i,M){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    d[a][b]=c;
    d[b][a]=c;
  }
  rep(k,N)rep(i,N)rep(j,N){
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  }

  int res=INF;
  auto dp = ndvec(inf, 1 << R, R);


  for(int st=0;st<R;st++){
    dp[(1<<st)][st]=0;
  }
    for(int S=0;S<(1<<R);S++){
      for(int to=0;to<R;to++){
        if(S&(1<<to))continue;
        int nb=S|(1<<to);
        for(int last=0;last<R;last++){
          dp[nb][to]=min(dp[nb][to],dp[S][last]+d[r[last]][r[to]]);
        }
      }
    }
    pr(min_element(ALL(dp[(1 << R) - 1]))[0]);


}


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

int main(void){
	string s;
	cin>>s;
	if(s=="Sunny"){
		cout<<"Cloudy"<<endl;
	}
	else if(s=="Cloudy"){
		cout<<"Rainy"<<endl;
	}
	else if(s=="Rainy"){
		cout<<"Sunny"<<endl;
	}
	return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    char a,b;
    cin>>a>>b;
  	if(a==b)cout<<"H";
  	else cout<<"D";
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder.R167.D
{
    public static class Solver
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            WriteAnswer(tw, Parse(tr));
        }

        private static void WriteAnswer(TextWriter tw, int answer)
        {
            tw.WriteLine(answer);
        }

        private static int Parse(TextReader tr)
        {
            var w = tr.ReadLine().Split().Select(c => long.Parse(c)).ToArray();
            var k = w[1];
            var a = tr.ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
            
            return Calc(k, a);
        }

        public static int Calc(long k, int[] a)
        {
            var visitedList = new List<int>();
            var visited = new bool[a.Length];

            var current = 0;
            for (var i = 0L; i < k; ++i)
            {
                if (visited[current])
                {
                    var c = visitedList.IndexOf(current);
                    var r = visitedList.Count - c;
                    return visitedList[(int)(c + (k - c) % r)] + 1;
                }
                visitedList.Add(current);
                visited[current] = true;
                current = a[current];
            }
            return current + 1;
        }
    }
}


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


int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
char arr[n][n];
char arr1[m][m];
    for(int i=0; i<n; i++)
        scanf("%s",arr[i]);

    for(int i=0; i<m; i++)
        scanf("%s",arr1[i]);


    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            int cnt=0;
            for(int a=0; a<m; a++)
            {
                for(int b=0; b<m; b++)
                {
                    if(arr1[a][b]==arr[i+a][j+b])
                        cnt++;
                }

            }
            if(cnt==(m*m))
            {
                printf("Yes\n");
                return 0;
            }

        }
    }
    printf("No\n");

}

Measured memory_bytes: 256
def main():
    x,n = map(int,input().split())
    if n>0:
        p = list(map(int,input().split()))
    else:
        p = []
    d = [i for i in range(0,102)]
    for i in range(len(d)):
        if d[i] in p:
            d[i] = -1
    d = sorted(d)
    m = 10000
    ans = 0
    for i in range(len(d)):
        if d[i]==-1:
            continue
        if m>abs(d[i]-x):
            m = abs(d[i]-x)
            ans = d[i]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
from bisect import bisect_right

N = int(input())
HPs = [tuple(map(int, input().split())) for i in range(N)]

HPs.sort(key=lambda x: x[0] + x[1])

# i人目まで考慮して、j人積んだ場合の積まれている高さの最小値
# 計算量削減のため、dp[j]=∞であるjのうち、最小のj以外は省略する
INF = float('inf')
dp = [0] + [INF]
for H, P in HPs:
    iH = bisect_right(dp, H)
    dp0 = [0] + [hgt + P for hgt in dp[:iH]] + [INF] * (len(dp) - iH)
    dp = [x if x <= y else y for x, y in zip(dp0, dp)]

    if dp[-1] != INF:
        dp += [INF]

print(len(dp) - 2)


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[200000];
int main(){
	int n;cin>>n;
	rep(i,n)cin>>a[i];
	int cnt=0;
	rep(i,n-1){
		if(a[i+1]>a[i])cnt++;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3476
n=int(input())
k=n//100
m=n%100
a=[0,1,2,3,4,5]
i=5
cnt=0
while True:
    if cnt>k:
        print(0)
        exit()
    if m==0:
        print(1)
        exit()
    if m>=a[i]:
        #print(a[i])
        m-=a[i]
        cnt+=1
    else:
        i-=1

Measured memory_bytes: 3064
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  string a,b;
  cin>>a>>b;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i]){
      cout<<"No"<<"\n";  
      return 0;
    }
  }
  cout<<"Yes"<<"\n";  
  return 0; 
}

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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

 
/*CODE START HERE*/
int main() {
  int n;
  cin >> n;
  vii p(n);
  forn(i,n){
    int a;
    cin >> a;
     p.at(i) = make_pair(a,i);
  }
  sort ( p.begin() , p.end() ) ;
  forn ( i,n){
    int a,b;
    tie(a,b) = p.at(i);
    cout << b+1 << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 4036
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
using namespace std;

long long a[200005],b[200005];

int main(){
	long long n,flag = 0,l,r;
	scanf("%lld",&n);
	r = n;
	l = 1;
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = n;i >= 1;i = i - 2) b[l++] = a[i];
	for(int i = n - 1;i >= 1;i = i - 2) b[r--] = a[i];
	for(int i = 1;i <= n;i++){
		printf("%lld ", b[i]);
	}
}

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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    if (a.back() < accumulate(a.begin(), a.end(), -a.back())) cout << "Yes";
    else cout << "No";
}


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

// gcd ビルトインで__gcdがあるけど、それが使えないとき用
ll gcd(ll a, ll b) {
  if (b == 0) return a;

  if (a < b) return gcd(b, a);

  return gcd(b, a % b);
}

// lcm
ll lcm(ll x, ll y) {
  ll gcdn = gcd(x, y);
  return (x / gcdn) * y;
}

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

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

  ll ans = t[0];
  for (int i = 0; i < n; i++) {
    ans = lcm(ans, t[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n,m=map(int, input().split())
h = [list(map(str,input().split())) for _ in range(m)]
# print(h)
for i in range(m):
    h[i][0] = int(h[i][0])
l=set()
penalty = 0
import numpy as np
p = np.zeros(n)
for i in range(m):
    if h[i][0] not in l:
        if h[i][1] == 'AC':
            l.add(h[i][0])
            penalty += p[h[i][0]-1]
        else:
            p[h[i][0]-1] += 1
ansnum = len(l)

# for i in l:
#     penalty += p[i-1]

print(ansnum,int(penalty))

Measured memory_bytes: 50108
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)

int main() {
  int a, b;
  cin >> a >> b;

  int ans = max(a + b, max(a - b, a * b));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 L, R, d;
  cin >> L >> R >> d;
  i64 ans = 0;
  for (i64 i = L; i <= R; i++)
    if (i % d == 0)
      ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
#include <stdio.h>

int main(void)
{
	int participate,question,y,x,count,max = 0;
	scanf("%d %d",&participate,&question);
	int record[participate] [question];

	for (y = 0;y < participate;y++) {
		count = 0;
		for (x = 0;x < question;x++) {
			scanf("%d",&record[y][x]);
			if (record[y][x] == 1)
				count++;
		}
		if (max < count)
			max = count;
	}
	
	printf("%d\n",max);
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<string> S(N);

    REP(i, N){
        cin >> S[i];
    }

    vector<ll> A(5, 0);
    REP(i, N){
        if(S[i][0] == 'M') A[0]++;
        if(S[i][0] == 'A') A[1]++;
        if(S[i][0] == 'R') A[2]++;
        if(S[i][0] == 'C') A[3]++;
        if(S[i][0] == 'H') A[4]++;
    }

    ll ans = 0;
    for(ll i=0; i<3; i++){
        for(ll j=i+1; j<4; j++){
            for(ll k=j+1; k<5; k++){
                ans += A[i]*A[j]*A[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6144
def main():
    n,k = map(int,input().split())

    mod = 10**9+7
    red = n-k+1
    red_cmb = [red]
    k_cmb = [1,k-1]
    for i in range(1,k):
        red_cmb.append(red_cmb[i-1]*(red-i)//(i+1))
    for i in range(2,k):
        k_cmb.append(k_cmb[i-1]*(k-i)//i)

    for i in range(k):
        print(red_cmb[i]*k_cmb[i]%mod)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

   int n, w;
   cin >> n >> w;
   vector <ll> wgt(n + 1), val(n + 1);
   for (int i = 0; i < n; i++) {
      cin >> wgt[i] >> val[i];
   }

   ll ans = 0;
   vector <vector <ll>> dp(n, vector <ll> (w + 1, -1));
   dp[0][0] = 0;
   dp[0][wgt[0]] = val[0];
   for (int i = 1; i < n; i++) {
      for (int j = 0; j <= w; j++) {
         dp[i][j] = dp[i - 1][j];
      }
      for (int j = 0; j <= w; j++) {
         if (j + wgt[i] <= w && dp[i - 1][j] != -1) {
            dp[i][j + wgt[i]] = max(dp[i - 1][j] + val[i], dp[i - 1][j + wgt[i]]);
         }
      }
   }

   for (int i = 0; i <= w; i++) {
      ans = max(ans, dp[n - 1][i]);
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int H, W, N;

int d(int x, int y){
    if(y == 0) return x;
    if(x == H) return H+y;
    if(y == W) return H+W+(H-x);
    if(x == 0) return H+W+H+(W-y);
    return -1;
}

int main(){
    cin >> H >> W >> N;
    map<int, int> mp;
    rep(i, N){
        int x[2], y[2], r[2];
        rep(i, 2){
            cin >> x[i] >> y[i];
            r[i] = d(x[i], y[i]);
        }
        if(r[0] > r[1]) swap(r[0], r[1]);
        if(r[0] == -1) continue;
        mp[r[0]] = i, mp[r[1]] = N+i;
    }
    stack<int> s;
    for(auto &e: mp){
        int i = e.second;
        if(i < N) s.push(i);
        else{
            i -= N;
            if(s.top() != i) {cout << "NO" << endl; return 0;}
            s.pop();
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 13132
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable : 4996)  // VSでscanfを使う．
#endif

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

  sort(d.begin(), d.end());

  int diff = 0;

  diff = d[n / 2] - d[n / 2 - 1];

  cout << diff << endl;

  return 0;
}



Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
    input = input.split("\n");
    var line1 = input[0].split(" ");
    var n = parseInt(line1[0]);
    var duration = parseInt(line1[1]);

    var line2 = input[1].split(" ");

    var arrSectionStart = [];
    var arrSectionEnd = [];
    var numSection = 0;

    var time = parseInt(line2[0]);

    var ans = 0;
    arrSectionStart[0] = 0;
    arrSectionEnd[0] = duration;

    for(var i=0;i<n;i++){
        time = parseInt(line2[i]);
//        console.log(time);
        
        if(time<=arrSectionEnd[numSection]){
            arrSectionEnd[numSection] = time + duration;
        } else {
            ans += arrSectionEnd[numSection] - arrSectionStart[numSection];
            numSection++;
            arrSectionStart[numSection] = time;
            arrSectionEnd[numSection] = time + duration;
        }
    }
    
    ans += arrSectionEnd[numSection] - arrSectionStart[numSection];
    
    console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
		cnt = N;
		p = s = vector<int>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

int N,M;
int main(){
    while(cin >> N >> M && N>0){
        vector<int> a(M+1,0),b(M+1,0),w(M+1,0);
        vector<pair<int,int>> edges;
        for(int i=0;i<M;i++){
            cin >> a[i] >> b[i] >> w[i];
            edges.emplace_back(w[i],i);
        }
        sort(edges.begin(),edges.end());
        int inf = 1e9,ans = inf;
        for(int i=0;i<M;i++){
            UnionFind uf(N);
            int ma = 0;
            for(int j=i;j<M;j++){
                int id = edges[j].second;
                if(!uf.is_same_set(a[id],b[id])){
                    ma = w[id];
                    uf.unite(a[id],b[id]);
                }
            }
            if(uf.size(1)==N){
                ans = min(ans,ma-edges[i].first);
            }
        }
        cout << (ans!=inf? ans:-1) << endl;
    }   
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  vector<char> ans(3);
  vector<char> A(6);
  for(int i = 0;i<3;i++){
    cin >> ans.at(i);
    cout << ans.at(i);
    cin >> A.at(i) >> A.at(i) >> A.at(i);
  }

  cout << endl;
}

Measured memory_bytes: 256
/*package whatever //do not write package name here */

import java.io.*;

import java.util.*;
public class Main{
	public static void main (String[] args) {
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int m=s.nextInt();
	int a[]=new int[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{a[i]=s.nextInt();
	sum+=a[i];}
	Arrays.sort(a);
	if(a[n-m]>=(int)Math.ceil(sum/(4.0*m)))
	System.out.println("Yes");
	else
	System.out.println("No");
	}
}

Measured memory_bytes: 23636
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }

    let mut num = 0;
    for c in s.chars() {
        if c == '+' {
            num += 1;
        } else {
            num -= 1;
        }
    }
    println!("{}", num);
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(void){
	int n,d1,d2,count=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&d1,&d2);
		if(d1==d2){
			count++;
		}else{
			count=0;
		}
		if(count==3){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;

#define F first
#define S second
#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define show(x) cerr << "# " << #x << " = " << (x) << endl
//#define int ll

const int N = 2e6 + 1;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int szT = (1 << 17) - 1;
const double PI = acos(-1.0);
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};

string s;
int b, r;

int main () {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base :: sync_with_stdio(0);
    int n;
    cin >> n;
    cin >> s;
    for(int i = 0; i < sz(s); ++i) {
        if(s[i] == 'R') ++r;
        else ++b;
    }
    if(r > b) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder177
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            long[] A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            
            long sum = 0;

            foreach (long a in A)
            {
                sum += a;
            }

            long mod = 1000000007;

            long ans = 0;

            for (long i = 0; i < N -1; i++)
            {
                sum -= A[i];

                ans += (A[i] * (sum % mod));
                ans %= mod;
            }

            Console.WriteLine(ans % mod);
        }

    }
}


Measured memory_bytes: 47760
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))

s = sum(As) // 2

Xs = [None] * N
Xs[0] = s - sum(As[1::2])
for i in range(1, N):
    Xs[i] = As[i - 1] - Xs[i - 1]

Xs = [x * 2 for x in Xs]
print(*Xs)




Measured memory_bytes: 17680
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  vector<vector<int>> c(4, vector<int>(4));
  vector<vector<int>> a(4, vector<int>(4, 101));
  vector<vector<int>> b(4, vector<int>(4, 101));

  for (int i = 1; i < 4; i++) {
    for (int j = 1; j < 4; j++) {
      cin >> c[i][j];
    }
  }

  bool ans = true;
  for (int i = 1; i < 4; i++) {
    for (int j = 1; j < 4; j++) {
      for (int k = 1; k <= 3; k++) {
        int prev_a = a[i][j] == 101 ? c[i][k] - c[j][k] : a[i][j];
        int prev_b = b[i][j] == 101 ? c[k][i] - c[k][j] : b[i][j];
        a[i][j] = c[i][k] - c[j][k];
        b[i][j] = c[k][i] - c[k][j];

        if (prev_a != a[i][j] || prev_b != b[i][j]) {
          ans = false;
        }
      }
    }
  }

  if (ans) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
  return 0;
}


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

ll fac[MAX_N], inv[MAX_N], fiv[MAX_N]; //fiv:inv(fac(i))

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll invf(ll a) {
	return mod_pow(a, mod - 2);
}

void C_init(int n) {
	fac[0] = fac[1] = 1; inv[1] = 1;
	fiv[0] = fiv[1] = 1;
	rep(i, 2, n + 1) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fiv[i] = fiv[i - 1] * inv[i] % mod;
	}
}

ll C(int a, int b) { //assume a >= b
	if(a < b || a < 0 || b < 0) return 0;
	return fac[a] * fiv[b] % mod * fiv[a - b] % mod;
}

int N, X;
int A[MAX_N];

ll dp[210][100010];

void solve() {
	cin >> N >> X;
	C_init(N);
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);
	reverse(A, A + N);
	dp[0][X] = 1;
	rep(i, 0, N) {
		rep(j, 0, X + 1) {
			if(dp[i][j] == 0) continue;
			rep(k, i, N) {
				ADD(dp[k + 1][j % A[k]], dp[i][j] * C(N - i - 1, k - i) % mod * fac[k - i] % mod);
				// debug(i, j, k, j % A[k], dp[i][j], C(N - i - 1, k - i));
			}
		}
	}
	ll res = 0;
	rep(i, 0, X + 1) {
		// debug(i, dp[N][i]);
		ADD(res, dp[N][i] * i % mod);
	}
	cout << res << "\n";
}

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



Measured memory_bytes: 162048
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="SUN"){
    cout << 7 << endl;
  }
  if(s=="MON"){
    cout << 6 << endl;
  }
  if(s=="TUE"){
    cout << 5 << endl;
  }
  if(s=="WED"){
    cout << 4 << endl;
  }
  if(s=="THU"){
    cout << 3 << endl;
  }
  if(s=="FRI"){
    cout << 2 << endl;
  }
  if(s=="SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	A := make(SortBy, N)
	var sum int
	for i := 0; i < N; i++ {
		A[i], _ = strconv.Atoi(read())
		if A[i] < 0 {
			cnt++
		}
		sum += abs(A[i])
	}

	if cnt%2 == 0 {
		fmt.Println(sum)
	} else {
		sort.Sort(A)
		if 0 < A[0] {
			A[0] *= (-1)
		}
		fmt.Println(sum + A[0]*2)
	}
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; 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
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) < abs(a[j]) }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 3072
def A(x):
  if ord(x) - ord('a') >= 0:
    print('a')
  else:
    print('A')


def B(n, k, p_list):
  p_list = sorted(p_list)
  print(sum(p_list[:k]))


def main():
  # letter = input()
  # func(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   func(x)

  n, k = map(int, input().split())
  p_list = map(int, input().split())
  B(n, k, p_list)


if __name__ == '__main__':
  main()


Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
#include <functional>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    REP(i,t.size()){
        if(s==t){
            cout << "Yes" << '\n';
            return 0;
        }
        s += s[0];
        s.erase(0,1);
    }
    cout << "No" << '\n';
    return 0;
}

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

int main() {
    int H, W, i, j;
    
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        
        for(i = 0; i < H; i++) {
            for(j = 0; j < W; j++) {
                if (i ==  0 || i == H - 1 || j == 0 || j == W -1) {
                    printf("#");
                    continue;
                }
                printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
    
}


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

using namespace std;
using ll = long long;
const int maxn = 2e5 + 5;

vector<int> adj[maxn];
int timer = 0;
int start[maxn], endd[maxn], pre[2 * maxn + 5];

void dfs(int u, int p){
    start[u] = timer++;
    for (int v : adj[u]){
        if (v != p){
            dfs(v, u);
        }
    }
    endd[u] = timer++;
}


int main()
{
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, -1);
    while(q--){
        int vertex, val;
        cin >> vertex >> val;
        pre[start[vertex]] += val;
        pre[endd[vertex] + 1] -= val;
    }
    for (int i = 0; i <= 2 * n; i++){
        pre[i + 1] += pre[i];
    }
    for (int i = 1; i <= n; i++){
        cout << pre[start[i]] << " ";
    }
    return 0;
}


Measured memory_bytes: 25856
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();


    if (n == 1) {
      System.out.println("Hello World");
    }

    if (n == 2) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      System.out.println(a + b);
    }




  }
}


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

int main(){

	int H,W ;
	cin >> H >> W;
	
	for(int i = 0;i < (W + 2);i++){
		
		cout << '#';
      
	}
	cout << endl;
	

	for(int i = 0;i < H;i++){
		cout << '#';
		string a;
		cin >> a;
		cout << a ;
		cout << '#' << endl; 
	}

	for(int i = 0;i <(W + 2);i++){
		cout << '#';
	}
	cout << endl;
}

Measured memory_bytes: 256