akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
//
#include <bits/stdc++.h>
//
using namespace std;
//
#define krep(i,k,n)      for(int i=k;i<n;++i)
#define rep(i,n)         for(int i=0;i<n;++i)
#define toupp(s)         transform(s.begin(),s.end(),s.begin(),::toupper) // string
#define tolow(s)         transform(s.begin(),s.end(),s.begin(),::tolower) // string
#define pb(v)            push_back(v)
#define all(v)           v.begin(),v.end()
#define mp               make_pair
#define __sort(v)        sort(v.begin(),v.end()) // vector
#define __stable_sort(v) stable_sort(v.begin(),v.end()) // vector
#define __exists(c,v)    (find(all(c), (v)) != (c).end()) // vector
#define __unique(v)      __sort(v);v.erase(unique(v.begin(),v.end()),v.end()) // vector
#define __swap(a, b, tmp)  tmp=a;a=b;b=tmp;
#define __memset(a)      memset(a,0,sizeof(a));
//
#define dumpVar(v)       cerr<<setw(30)<<#v" = ["<<v<<"]"<<endl
#define dumpArr(v, n)    for(int i=0;i<n;++i){cerr<<v[i]<<", ";} cerr<<endl
#define dumpPair(p)      cerr<<"<"<<p.first<<", "<<p.second<<">"<<endl
//
typedef long long              ll;
typedef vector<string>         vs;
typedef vector<double>         vd;
typedef vector<int>            vi;
typedef pair<int, int>         pii;
typedef pair<double, double>   pdd;
//
int main ()
{
        ios::sync_with_stdio ( false );
        //
        /* code start */

        double N;
  cin >> N;

  if ( (int)N % 2 == 0 ){
    cout << fixed;
    cout << setprecision(10) << 0.5 << endl;
  }else{
    if (N == 1 ){
      cout << fixed;
      cout << setprecision(10) << 1.0 / N << endl;
    }else{
      cout << fixed;
      cout << setprecision(10) << ((N+1) / 2) / N << endl;
    }
  }

        /* code end   */
        //
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <stdio.h>

int main()
{
	unsigned long A, B;
	std::cin >> A >> B;
	unsigned long result = 0;

	++B;

	if ((B - (A & ~1UL)) % 4UL >= 2UL)
		result |= 1UL;
	for (unsigned long i = 1; i < 60; ++i) {
		unsigned long bit = 0;
		auto a = A % (1UL << (i+1));
		auto b = B % (1UL << (i+1));
		if (a >= (1UL << i))
			bit ^= ((a % (1UL << i)) & 1UL);
		if (b >= (1UL << i))
			bit ^= ((b % (1UL << i)) & 1UL);
		result |= (bit << i);
	}

	std::cout << result << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;


int main() {
int64_t a;
  cin>>a;
  int64_t cost[a];
  for(int i=0;i<a;i++)
  {
  int64_t b;
  cin>>b;
    cost[i]=b;
  }
  int64_t dp[a];
  dp[0]=0;
  dp[1]=abs(cost[1]-cost[0]);
  for(int j=2;j<a;j++)
  {
  dp[j]=min(dp[j-1]+abs(cost[j]-cost[j-1]),dp[j-2]+abs(cost[j]-cost[j-2]));
  }
  cout<<dp[a-1];
}
 

Measured memory_bytes: 1792
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H - 1 or j == 0 or j == W - 1:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()


Measured memory_bytes: 7008
import java.util.Scanner;

// 提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // int Nを受け取る
		int A = sc.nextInt(); // int Aを受け取る
		int B = sc.nextInt(); // int Bを受け取る
		sc.close(); // 標準入力を終了

		// 各桁の和が A 以上 B 以下であるものの総和
		int c = 0;

		for(int i = 1; i <= N; i++) {
			int j = sumDigits(i);
			if(j >= A && j <= B) {
				// 各桁の和が A 以上 B 以下
				c += i;
			}
		}
		System.out.println(c);
	}

	//sumDigits:負でないint nが与えられた場合、その桁の合計を再帰的に返す。
	public static int sumDigits(int n) {
		int sum = 0;
		//自然数の各桁の和を計算
		while (n != 0) {
			//sumDigitsは単独ではloopしないので、while loopを使う。
			int s = n % 10;
			sum += s;
			//再右端の桁を得るために%10を利用する。

			n = n / 10;
			//再右端の桁を取り除くためにn/=10を利用する。
		}

		return sum;//合計を返す
	}

}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,n,dif,min=1000000000,i,p,q;
    cin>>n>>d;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    if(d==1)
    {
        for(i=0; i<n; i++)
        {
            dif=abs(a[i]);
            if(min>dif)
            {
                min=dif;
            }
        }
        cout<<min<<endl;
        return 0;
    }
    for(i=0; i<n-d+1; i++)
    {
        if(a[i]<0&&a[i+d-1]<=0)
        {
            dif=0-a[i];
            //cout<<"1"<<endl;
        }
        else if(a[i]<0&&a[i+d-1]>0)
        {
            p=a[i+d-1];
            q=0-a[i];
            if(p>q)
            {
                dif=2*q+p;
            }
            else
            {
                dif=2*p+q;
            }
            //dif=a[i+d-1]+(0-a[i]);
            //cout<<"2"<<endl;
        }
        else if(a[i]>=0&&a[i+d-1]>0)
        {
            dif=a[i+d-1]-0;
            //cout<<"3"<<endl;
        }
        //cout<<dif<<endl;
        if(dif<min)
        {
            min=dif;
        }
    }
    cout<<min;
}


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;
typedef pair<int, int> P;

int mod = 1000000007;
int K;
ll ans;
vector<vector<int> > to(100005);

void dfs(int v, int f, int d){
    int n = 0;
    int s = to[v].size();
    int k = K-2;
    if(d == 0){
        k++;
        s++;
    }
    for (int i = 0; i < s-1; i++){
        ans *= k;
        ans %= mod;
        k--;
    }
    if(d == 0){
        s--;
    }
    for (int i = 0; i < s; i++){
        int x = to[v][i];
        if(x == f)continue;
        dfs(x, v, ++d);
    }
    return;
}

int main() {
    int N; cin >> N >> K;
    rep(i, N-1){
        int a, b; cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans = K;
    dfs(0, -1, 0);

    cout << ans << endl;

    return 0;
}

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


const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(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;
  }
};

int main(){
    int s;
    cin >> s;
    mint ans = 0;
    mint res = 1;
    for (int i = 1; i * 3 <= s; i++){
        ans += res;
        res *= s - 3 * i;
        res *= s - 3 * i - 1;
        res *= s - 3 * i - 2;
        res /= s - 2 * i - 1;
        res /= s - 2 * i - 2;
        res /= i;
    }
    cout << ans.x << endl;
}

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

using namespace std;
//#define int long long
#define float double
//const int INF = 100000000000000000;

signed main(void){
  int n;
  vector<int> a;
  int b = 0;
  for(int i = 0; i < 8; i++) a.push_back(0);
  cin >> n;
  for(int i = 0; i < n; i++){
    int a_;
    cin >> a_;
    if(a_ < 3200)a[a_/400] = 1;
    else b++;
  }
  int sum = 0;
  int min_,max_;
  for(int i = 0; i < 8; i++)sum+=a[i];
  min_ = max(sum, min(1,b));
  max_ = sum+b;
  cout << min_ << " " << max_ << "\r\n";


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
    int n;
    cin >> n;
    
    vector<long long int> a;
    for(int i = 0; i < n; i++){
        long long int x;
        cin >> x;
        a.push_back(x);
    }
    
    long long int check = *min_element(a.begin(), a.end());
    bool on = true;
    
    while(on){
        for(int i = 0; i < n; i++){
            if(a[i] % check != 0){
                check = a[i] % check;
                break;
            }
            if(i == n - 1){
                on = false;
                break;
            }
        }
    }
    
    cout << check;
}

Measured memory_bytes: 1400
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
using namespace std;
using ll=long long;
int cnt,element;
long long int arr[100000001];
vector<ll>vec;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    for(int i=1;i<=100;i++)
    {
       c=c-b;
       if(c<=0)
       {
           cout<<"Yes"<<endl;
           break;
       }
       a=a-d;
       if(a<=0)
       {
           cout<<"No"<<endl;
           break;
       }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'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'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v;

//ll f[101010], rf[101010];
ll f[202020], rf[202020];
ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    rf[0] = inv(f[0]);
    for(ll i=1;i<202020;i++){
      f[i] = (f[i - 1] * i) % MOD;
      rf[i] = inv(f[i]);
    }
}
 
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!
 
    ll bc = (b * c) % MOD;
 
    return (a * bc) % MOD;
}

int main(){
  init();
  ll n, m, k;
  cin >> n >> m >> k;
  
  ll ansx = 0;
  for (int i=1;i<n;i++) ansx += i*(n-i);
  ansx = (ansx*m*m)%MOD;
  
  ll ansy = 0;
  for (int i=1;i<m;i++) ansy += i*(m-i);
  ansy = (ansy*n*n)%MOD;
  
  ll ans = (ansx + ansy)*C(n*m-2,k-2)%MOD;
  //cout << ansx << " " << ansy << " " << C(n*m-2,k-2) << endl;
    
  cout << ans << endl;
}

Measured memory_bytes: 3456
import sys
from bisect import bisect_left, bisect_right

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# dp と bisect.insort
N = ir()
INF = 10 ** 12
dp = [INF] * (N+1)
for _ in range(N):
    a = ir()
    i = bisect_right(dp, -a)
    dp[i] = -a

print(bisect_left(dp, INF))
# 18

Measured memory_bytes: 6900
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <set>
using namespace std;




void solve()
{
	int n;
	cin >> n;

	string s;
	cin >> s;

	if (n & 1)
	{
		cout << "No";
		return;
	}

	for (int i = 0; i < n / 2; i++)
	{
		if (s[i] != s[i + n / 2])
		{
			cout << "No";
			return;
		}
	}

	cout << "Yes";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

int main(void){
    string s;
    cin >> s;
    if(s.length()%2==1){
        cout << "No" << endl;
        return 0;

    }
    rep(i,s.length()){
        if(i%2 ==0 && s[i] != 'h'){
            cout << "No" << endl;
            return 0;
        }
        if(i%2 ==1 && s[i] != 'i'){
            cout << "No" << endl;
            return 0;
        }

    }
    cout << "Yes" << endl;
    return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll c[200005],p[200005],hell=pow(10,9)+7;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,res=0;
    cin>>n;
    p[0]=1;
    for(ll i=1;i<200005;i++)
    p[i]=(2*p[i-1])%hell;
    for(ll i=0;i<n;i++)
    cin>>c[i];
    sort(c,c+n);
    for(ll i=0;i<n;i++){
        ll sum=(p[n-1]+((n-i-1)*p[n-2])%hell)%hell;
        sum*=c[i];
        sum%=hell;
        res+=sum;
        res%=hell;
    }
    res*=p[n];
    res%=hell;
    cout<<res;
}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(void)
{
    int A,B,C,cnt=0;
    cin>>A>>B>>C;
    if(A==B && B==C) cnt=0;
    else if(max(max(B,C),A)==A)
    {
        cnt=A-max(B,C);
        B+=cnt,C+=cnt;
        if(B>C) while(B>C) C+=2,cnt++;
        else if(C>B) while(C>B) B+=2,cnt++;
        if(C>B && A==B) cnt++;
        else if(B>C && A==C) cnt++;
    }
    else if(max(max(B,C),A)==B)
    {
        cnt=B-max(A,C);
        A+=cnt,C+=cnt;
        if(A>C) while(A>C) C+=2,cnt++;
        else if(C>A) while(C>A) A+=2,cnt++;
        if(C>A && A==B) cnt++;
        else if(A>C && C==B) cnt++;
    }
    else if(max(max(B,C),A)==C)
    {
        cnt=C-max(A,B);
        A+=cnt,B+=cnt;
        if(A>B) while(A>B) B+=2,cnt++;
        else if(B>A) while(B>A) A+=2,cnt++;
        if(B>A && A==C) cnt++;
        else if(A>B && C==B) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int l,r,d; cin >> l >> r >> d;
  int res = 0;
  for (int i = l; i <= r; ++i) {
    if(i % d == 0) res++;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3632
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N;
    cin>>N;
    vector<ll> C(N);
    REP(i,N) cin>>C[i];
    sort(ALL(C));
    ll ans=0;
    REP(i,N){
        ans+=(mod_pow(4,N-1,MOD)*(C[i]%MOD*(N+1-i)%MOD)%MOD)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(void){
  int d;cin>>d;
  const int POS[][2]={{0,-1},{1,0},{0,1},{-1,0}};
  while(d--){
    int n;cin>>n;
    vector<vector<char> > field(n+2);
    for(int i=0;i<=n+1;++i){
      field[i].reserve(n+2);
      for(int j=0;j<=n+1;++j)field[i][j]=(i==n+1||j==n+1)?1:0;
    }
    int x=0,y=n-1,p=0;
    for(;;){
    	if(x<0||y<0)break;
      int dx=POS[p][0],dy=POS[p][1];
      int px=POS[(p+4+1)%4][0],py=POS[(p+4+1)%4][1],qx=POS[(p+4-1)%4][0],qy=POS[(p+4-1)%4][1];
      field[y][x]=1;
      x+=dx,y+=dy;
      if(y==0&&x==0||(y+2*dy>=0&&x+2*dx>=0&&field[y+2*dy][x+2*dx]==1))p=(p+1)%4;
      if((y+dy+py>=0&&x+dx+px>=0&&field[y+dy+py][x+dx+px]==1)||(y+dy+qy>=0&&x+dx+qx>=0&&field[y+dy+qy][x+dx+qx]==1))
      	break;
    }
    if(n==2)field[1][1]=0;
    for(int i=0;i<n;++i){
      for(int j=0;j<n;++j)cout<<((field[i][j])?'#':' ');
      cout<<endl;
    }
    if(d)cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
import java.io.*;
import java.util.Calendar;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            
            String line; // ??\???????????????????????\???
            while ((line = br.readLine()) != null){
            	String[] date = line.split(" ",0);
                int month = Integer.parseInt(date[0]);
                int day = Integer.parseInt(date[1]);
            	if(month==0){
                break;
                }
            	System.out.println(getDay(month, day));
            }  
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static String getDay(int month, int day) {
    	Calendar cal = Calendar.getInstance();
        cal.set(2004, month - 1, day);
    
    switch (cal.get(Calendar.DAY_OF_WEEK)) { 
    case Calendar.SUNDAY:     // Calendar.SUNDAY:1 ???????????????????????????
    	return "Sunday";
    case Calendar.MONDAY:     // Calendar.MONDAY:2
    	return "Monday";
    case Calendar.TUESDAY:    // Calendar.TUESDAY:3
    	return "Tuesday";
    case Calendar.WEDNESDAY:  // Calendar.WEDNESDAY:4
    	return "Wednesday";
    case Calendar.THURSDAY:   // Calendar.THURSDAY:5
    	return "Thursday";
    case Calendar.FRIDAY:     // Calendar.FRIDAY:6
    	return "Friday";
    case Calendar.SATURDAY:   // Calendar.SATURDAY:7
    	return "Saturday";
}
	return null;
    }
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

vector<vector<ll>> cmb(2050, vector<ll>(2050));
void mkcmb(const int MX){
	rep(i,MX+1)  cmb[i][0] = 1;
	rep2(i,1,MX+1) rep2(j,1,i+1)
		cmb[i][j] = (cmb[i-1][j] + cmb[i-1][j-1])%MD;
}

ll ncr(ll n, ll k){
	if(k > n || n <0 || k <0) return 0;
	return cmb[n][k];
}
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	
	mkcmb(2045);
	rep2(i, 1, k+1){
		ll z1 = ncr(n-k+1, i) * ncr(k-1, i-1);
		cout << z1%MD <<"\n";
	}
	
	return 0;
}


Measured memory_bytes: 33152
def solve(string):
    m = 10**9 + 7
    a, b = 1, 2
    for l in string[1:]:
        a, b = ((3 * a + b) % m, 2 * b % m) if int(l) else (3 * a % m, b)
    return str((a + b) % m)


if __name__ == '__main__':
    print(solve(input()))


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

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

	if(n>=13){
		cout << a << endl;
	}
	else if (n>=6) {
		a = a / 2;
		cout << a << endl;
	}
	else cout << 0 << endl;
}

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

int main() {
  string S;
  cin >> S;
  int cnt = 700;
  for(int i=0;i<3;i++){
    if(S[i]=='o'){
      cnt += 100;
    }else{
    }
  }
  cout << cnt << endl;
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    for(auto&& i : s){
        if(i == 'R'){
            cnt++;
        }else{
            cnt = 0;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#define rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
#define MAX_C 100000
typedef long long ll;
using namespace std;

int main(){
        int n;
        cin >> n;
        vector< vector<int> > G(n, vector<int>(n,MAX_C+1));
        int u,k,v,c;
        rep(i,n){
                cin >> u >>k;
                rep(j,k){
                        cin >> v >> c;
                        G[u][v] = c;
                }
        }

        vector<ll> d(n, MAX_C * n);
        d[0]=0;
        bool update = true;
        while(update) {
                update  = false;
                rep(from,n) {
                        if(d[from] >= MAX_C * n) continue;

                        rep(to,n){
                                if(from == to || G[from][to] >= MAX_C + 1) continue;

                                if(d[to] > d[from] + G[from][to]) {
                                        update = true;
                                        d[to] = d[from] + G[from][to];
                                }

                        }
                }
        }
        rep(i,n){
                cout << i << " " << d[i] << endl;
        }

        return 0;
}



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

int main(int argc, char *argv[]) {
	int R = 0;
	std::cin >> R;

	std::string result;
	if (R < 1200) {
		result = "ABC";
	} else if (R < 2800) {
		result = "ARC";
	} else {
		result = "AGC";
	}

	std::cout << result << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.IOIOI", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		int m;
		scanf ("%d", &m );
		string s = "";
		cin >> s;
		string search = "";
		rep (i, n ){
			search += "IO";
		} // end rep
		search += 'I';
//		cerr << search << endl;
		int res = 0;
		rep (i, m ){
			if (s[i] == 'O' ) continue;
			if (s[i] == 'I' && i+1 < m && s[i+1] != 'O' ) continue;
			string sub = s.substr(i, 2*n+1 );
			if (sub == search ){
				res++;
			} // end if
		} // end rep
		printf ("%d\n", res );
	} // en drep
	
	return 0;
}

Measured memory_bytes: 2160
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(S: str):
    if S[2] == S[3] and S[4] == S[5]:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};



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

    ll a;
    double b;
    cin >> a >> b;
    ll bl = b * 100 + 0.001;
    a *= bl;
    a/=100;
    cout << a << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<32>(n);
    string s = ss.str();
    return s;
}
int main(){
    ll n; cin >> n;
    string s = to_bin_string(n);
    cout << s << endl;
    rep(i,32)cout << ((s[i] == '0')?1:0);
    cout << endl;
    rep(i,31)cout << s[i+1];
    cout << 0 << endl;
    cout << 0;
    rep(i,31)cout << s[i]; 
    cout << endl;
    return 0;
}


Measured memory_bytes: 3208
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
  private static class Solver {
    public int solve(int W, List<Integer> values, List<Integer> weight) {
      int maxVal = values.stream().max(Integer::compare).get() * values.size();
      long[] dp = new long[maxVal + 1];
      Arrays.fill(dp, Long.MAX_VALUE);
      dp[0] = 0;
      for (int i = 1; i <= values.size(); ++i) {
        for (int j = maxVal; j >=0; --j) {
          int v = values.get(i - 1);
          int w = weight.get(i - 1);
          if (j - v >= 0 && Long.MAX_VALUE != dp[j - v]) {
            dp[j] = Math.min(dp[j], dp[j - v] + w);
          }
        }
      }
      while (dp[maxVal] > W && maxVal > 0) {
        --maxVal;
      }
      return maxVal;
    }
  }

  private static final Pattern SPLIT = Pattern.compile("\\s");
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    List<Integer> weights = new ArrayList<>();
    List<Integer> values = new ArrayList<>();
    List<Integer> NW = Stream.of(SPLIT.split(scanner.nextLine())).map(Integer::valueOf)
        .collect(Collectors.toList());
    final int N = NW.get(0);
    final int W = NW.get(1);
    for (int i = 0; i < N; ++i) {
      List<Integer> collect = Stream.of(SPLIT.split(scanner.nextLine())).map(Integer::valueOf)
          .collect(Collectors.toList());
      values.add(collect.get(0));
      weights.add(collect.get(1));
    }
    System.out.println(new Solver().solve(W, values, weights));
  }
}

Measured memory_bytes: 33204
import java.util.*;
 
class Main {
    void solve(){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(), K = in.nextInt();
        int sum = 0;
        for(int i = 0; i < N; i++){
            int x = in.nextInt();
            sum += Math.min(Math.abs(x - K), x) * 2;
        }
        System.out.println(sum);

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

Measured memory_bytes: 22100
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
#define int long long
	vector<int> inputs;
	vector<int> checker;
	vector<int> gogo;
	int n;
	cin >> n;
	for (int q = 2; q <= 100000; ++q) {
		int ok = 1;
		for (int j = 0; j < checker.size(); ++j) {
			if (q % checker[j] == 0) {
				ok = 0;
				break;
			}
		}
		if (ok) {
			checker.push_back(q);
		}
	}
	REP(i, n) {
		int a;
		cin >> a;
		inputs.push_back(a);
		REP(j, checker.size()) {
			if (a % checker[j] == 0) {
				gogo.push_back(checker[j]);
				if(a != checker[j])
				gogo.push_back(a / checker[j]);
			}
		}
		if(a != 1)
		gogo.push_back(a);
	}
	sort(inputs.begin(), inputs.end());
	long long ans = 0;
	REP(i, gogo.size()) {
		long long now = 0;
		REP(q, inputs.size()) {
			if (inputs[q] % gogo[i] == 0) {
				now += inputs[q];
			}
		}
		ans = max(ans, now);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3280
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2*j - i
    if k < n and s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      ans -= 1
print(ans)

Measured memory_bytes: 9212
import itertools

n = int(input())
p = [[0 for i in range(2)] for j in range(n)]

for i in range(n):
  p[i][0],p[i][1] = map(int,input().split())
#print(p)

def dis(a,b):
  dis = (a[0]-b[0]) ** 2 + (a[1]-b[1]) **2
  return dis ** (1/2)


perm = [i for i in range(n)]
total = 0 
num = 0
for v in itertools.permutations(perm,n):
  path = 0
  for i in range(n-1):
    path += dis(p[v[i]],p[v[i+1]])
  num += 1
  total += path
print(total/num)


Measured memory_bytes: 9424
import java.util.*;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final long W = sc.nextLong();
		long wBase = 0;

		ArrayList<ArrayList<Long>> items = new ArrayList<>();

		for (int i = 0; i < 4; i++) {
			ArrayList<Long> al = new ArrayList<>();
			items.add(al);
		}

		for (int i = 0; i < N; i++) {
			long wi = sc.nextLong();
			long vi = sc.nextLong();
			if (i == 0) {
				wBase = wi;
			}
			assert (wi - wBase > 0 && wi - wBase < 4);
			int idx = (int) (wi - wBase);
			items.get(idx).add(vi);
		}
		for (int i = 0; i < items.size(); i++) {
			Collections.sort(items.get(i), (Long a, Long b) -> (int) (b - a));
			ArrayList<Long> list = new ArrayList<Long>(items.get(i).size() + 1);
			list.add(0L);
			long sum = 0;
			for (long v : items.get(i)) {
				sum += v;
				list.add(sum);
			}
			items.set(i, list);
		}

		long maxValue = 0;
		for (int i = 0; i < items.get(0).size(); i++) {
			for (int j = 0; j < items.get(1).size(); j++) {
				for (int k = 0; k < items.get(2).size(); k++) {
					long totalW = (long) wBase * i + (long) (wBase + 1) * j + (long) (wBase + 2) * k;
					if (totalW > W) {
						break;
					}
					int l = (int) ((W - totalW) / (wBase + 3));
					long totalV = items.get(0).get(i) + items.get(1).get(j) + items.get(2).get(k)
							+ items.get(3).get(Math.min(l, items.get(3).size() - 1));
					maxValue = Math.max(maxValue, totalV);
				}
			}
		}

		System.out.println(maxValue);
		sc.close();

	}

}

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

int main() {
	string S;
	string T;
	cin >> S;
	cin >> T;
	int sizet = T.length();
	int i = 0;
	string res = "No";
	while (i < sizet)
	{
		if (T == S) {
			res = "Yes";
			break;
		}
		else {
			T = T.substr(1, sizet - 1) + T.front();
			i++;
		}
	}
	cout << res << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, D;
    cin >> N >> D;
    mat X(N, vec(D));
    REP(i,0,N) REP(j,0,D) cin >> X[i][j];

    ll cnt = 0;
    REP(i,0,N-1) {
        REP(j,i+1,N) {
            ll d = 0;
            REP(k,0,D) d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            REP(k,0,160) {
                if(k*k == d) {
                    ++cnt;
                    break;
                }
            }
        }
    }
    PR(cnt);

    return 0;
}

/*



*/

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	vi a(3);
	for(int i=0; i<3; i++)cin >> a[i];
	sort(all(a));
	cout << a[2]-a[0]<< endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
# coding: utf-8
n = int(input())
h = list(map(int, input().split()))
counter = 0
while bool(h):
    for i in range(n):
        if not bool(h[0]): h = h[1:]; break
        h[i] -= 1
        try: 
            if h[i + 1] == 0: counter += 1; break
        except: counter += 1; break
print(counter)

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

#define ll long long

int main() {
    ll n,i,count=0;
    cin>>n;
    vector<string> v1(n);
    map<string,ll> map1;
    for(i=0;i<n;i++)
    {
        cin>>v1[i];
        sort(v1[i].begin(),v1[i].end());
        map1[v1[i]]++;
    }
    for(auto x: map1)
    {
        if(x.second)
        {
            //cout<<x.second;
            count+=x.second*(x.second-1)/2;
        }
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 13916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define MP make_pair
#define VI vector<int>
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5;
const ll MOD=1000000007;
const ll INF=(ll)1e18;

int main(){
    IOS();
    ll a,b;
    cin >> a >> b;
    cout << max(0LL,a - 2*b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;

  return 0;
}


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

int main(void){
    int n;
    std::cin >> n;

    if(n == 1){
        int ans;
        std::cin >> ans;
        std::cout << ans;
        return 0;
    }

    if(n == 2) {
        int a;
        int b;
        std::cin >> a;
        std::cin >> b;
        std::cout << (a+b) / 2.0 << std::endl;
        return 0;
    }

    std::vector<int> v(n);
    for(int i = 0; i < n; i++){
        std::cin >> v[i];   
    }
    std::sort(v.begin(), v.end());
    double mean = (v[0] + v[1]) / 2.0;
    for(int i = 2; i < n; i++){
        mean = (mean + v[i]) / 2.0;
    }

    std::cout << mean << std::endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(n):
  x, y = map(int, input().split())
  arr += [[x, y]]

flag = 0
for i in range(1, n-1):
  if arr[i-1][0] == arr[i-1][1] and arr[i][0] == arr[i][1] and arr[i+1][0] == arr[i+1][1]:
    flag = 1
    break
if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9204
import qualified Data.IntSet as S
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List

solve :: Int -> S.IntSet -> [(Int, Int)] -> Int
solve _ _ [] = 0
solve n s ((i, x):is) = (i-l)*(r-i)*x + solve n (i `S.insert` s) is
  where
    l = fromMaybe 0 $ S.lookupLT i s
    r = fromMaybe (n+1) $ S.lookupGT i s

main :: IO ()
main = do
  n <- readLn
  a <- sortOn snd . zip [1..] . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
  print $ solve n S.empty a

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

using namespace std;

int main() {
    long long n, ans = 1;
    cin >> n;
    vector<bool> prime(n + 1, true);
    vector<long long> trueprimer;
    for(long long i = 2; i <= sqrt(n); ++i){
        if(prime[i] == true){
            for(long long j = 2 * i; j <= n; j += i){
                prime[j] = false;
            }
        }
    }
    for(long long i = 2; i <= n; ++i){
        if(prime[i])trueprimer.push_back(i);
    }
    for(long long i = 0; i < trueprimer.size(); ++i){
        long long tmp = trueprimer[i];
        long long max = 0;
        while(tmp <= n){
            max = max + (n / tmp);
            tmp *= trueprimer[i];
        }
        ans = (ans * (max + 1)) % 1000000007;
    }
    cout << ans;
	return 0;

}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 1

if k == n:
    for i in range(n):
        ans *= a[i]
        ans %= mod
    print(ans)
    exit()
if max(a) < 0 and k%2 == 1:
    a.sort(reverse=True)
    for i in range(k):
        ans *= a[i]
        ans %= mod
    print(ans)
    exit()

a.sort(key=lambda x: abs(x))
cnt = 0
for i in range(1, k+1):
    ans *= a[-i]
    ans %= mod
    if a[-i] < 0:
        cnt += 1

if cnt%2 == 0:
    print(ans)
else:
    a_plus = None
    a_minus = None
    b_plus = None
    b_minus = None
    for i in range(k, 0, -1):
        if a[-i] >= 0 and a_plus == None:
            a_plus = a[-i]
        if a[-i] < 0 and a_minus == None:
            a_minus = a[-i]
    for i in range(k+1, n+1):
        if a[-i] >= 0 and b_plus == None:
            b_plus = a[-i]
        if a[-i] < 0 and b_minus == None:
            b_minus = a[-i]
    if a_plus == None or b_minus == None:
        ans *= pow(a_minus, mod-2, mod)
        ans %= mod
        ans *= b_plus
        ans %= mod
    elif a_minus == None or b_plus == None:
        ans *= pow(a_plus, mod-2, mod)
        ans %= mod
        ans *= b_minus
        ans %= mod
    else:
        if abs(a_plus*b_plus) > abs(a_minus*b_minus):
            ans *= pow(a_minus, mod-2, mod)
            ans %= mod
            ans *= b_plus
            ans %= mod
        else:
            ans *= pow(a_plus, mod-2, mod)
            ans %= mod
            ans *= b_minus
            ans %= mod
    print(ans)

Measured memory_bytes: 104428
N,M = map(int, input().split())
ans = {}
AC = 0
WA = 0

for i in range(M):
  num,stu = map(str, input().split())
  if num in ans:
    if ans[num][0] == 0:
      if stu == "AC":
        ans[num][0] = 1
      else:
        ans[num][1] += 1
  else:
      if stu == "AC":
        ans[num] = [1,0]
      else:
        ans[num] = [0,1]

  
for j in ans.values():
  if j[0] == 1:
    AC += 1
    WA += j[1]
    
print(str(AC)+" " +str(WA))
        

Measured memory_bytes: 25284
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			int n=sc.nextInt();
			if(n==0)
				break;
			int[] times=new int[n];
			for(int i=0; i<n; i++)
				times[i]=sc.nextInt();
			sort(times);
			long ans=0;
			long sum=0;
			for(int t : times){
				// println(sum+"");
				ans+=sum;
				sum+=t;
			}
			println(ans+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

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

namespace AtCoder.Abc
{
    internal class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputDecimalArray = Console.ReadLine().Split(' ').Select(i => decimal.Parse(i)).ToArray();

            var a = inputDecimalArray[0];
            var b = inputDecimalArray[1];

            string result = Math.Floor(a * b).ToString();

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 28276
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        
        // for (int i = 0; i <= 100; i++) {
        //     long center = i;
        //     long tmp = (long)Math.floor(a * center / b) - a * (long)Math.floor(center/b);
        //     // if (i != 4) continue;
        //     System.out.println(tmp);
        // }
        
        long x = 0;
        if (b > n+1) {
            x = b - 1 -(b-n-1);
        } else {
            x = b-1;
        }
        long tmp = a * x / b - a * (x / b);
        System.out.println(tmp);
        // System.out.println(x);
        // System.out.println((long)Math.floor(a * x / b));
        
        // 条件を満たす最小の値(最大が知りたい場合if(ok)のブロックを反転する)
        // long left = 0;
        // long right = 1000000000000l;
        
        // long ans = 0;
        // while (left < right) {
        //     long center = (left + right) / 2;
            
        //     boolean ok = true;
            
        //     // okがどうかの判定
        //     long tmp = Math.floor(a * center / b) - a * Math.floor(center/b);
            
        //     ans = Math.max(ans, tmp);
        //     if ()
            
        //     if (ok) {
        //         right = center;
        //     } else {
        //         left = center + 1;
        //     }
        // }
        
        // System.out.println(left);
    
    }
}


Measured memory_bytes: 35812
char out[1001000];
char buf[100];
sz,k;
H,W,A,B;
main()
{
	read(0,buf,100);
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		H=H*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		W=W*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		A=A*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		B=B*10+k-'0';
	}
	sz=0;
	for(int i=0;i<B;++i)
	{
		for(int j=0;j<A;++j)out[sz++]='0';
		for(int j=A;j<W;++j)out[sz++]='1';
		out[sz++]='\n';
	}
	for(int i=B;i<H;++i)
	{
		for(int j=0;j<A;++j)out[sz++]='1';
		for(int j=A;j<W;++j)out[sz++]='0';
		out[sz++]='\n';
	}
	write(1,out,sz);
}

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

int main(){
    int n, k;
    cin >> n>> k;
    if(2*k-1 <= n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;
const long mod = 1000000007;

struct UnionFind {
private:
	vector<long> prisize;//属するグラフの頂点数を返す。参照は根でよい。
public:
	vector<long> par;//親を返す
	UnionFind(long N) : prisize(N), par(N) {
		for (int i = 0; i < N; i++) par[i] = i;//全て根である状態
		for (int i = 0; i < N; i++) prisize[i] = 1;
	}

	long root(long i) {//根を返す
		if (par[i] == i) return i;
		return par[i] = root(par[i]); //根に直接繋ぎなおす
	}

	void unite(long x, long y) {//二つの木の統合(rxをryに繋ぐ)
		long rx = root(x);
		long ry = root(y);

		if (rx == ry) return;
		if (prisize[rx] < prisize[ry]) swap(rx, ry);
		par[rx] = ry;
		prisize[ry] += prisize[rx]; //ここ分解を想定していない & size[rx]は更新されない。
	}

	bool same(long x, long y) { return root(x) == root(y); }//根が等しいか
	long size(long i) { return prisize[root(i)]; }
};

int main() { 
	//逆から走査する(UnionFindなので)
	long N, M; cin >> N >> M;
    
	vector<long> F(M + 1);//崩落後の不便さ
	vector<pair<long, long>> bridge(M);//入力リスト
	F[M] = N * (N - 1) / 2;

	UnionFind tree(N);

	for (int i = 0; i < M; i++) {//入力
		long A, B; cin >> A >> B;
		A--; B--;
		bridge[i] = make_pair(A, B);
	}

	for (int i = M - 1; i >= 0; i--) {
		long A, B; 
		A = bridge[i].first;
		B = bridge[i].second;

		if (tree.same(A, B)) {
			F[i] = F[i + 1];
		}
		else {
			F[i] = F[i + 1] - (tree.size(A) * tree.size(B));
			tree.unite(A, B);
		}
	}

	for (int i = 1; i <= M; i++) cout << F[i] << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    string S, T; cin >> S >> T;
    ll ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3864
n=int(input())
l=[int(i) for i in input().split()]
mod=1000000007
suff=[0]*n
suff[-1]=l[n-1]
for i in range(n-2,-1,-1):
    suff[i]=suff[i+1]+l[i]
s=0
for i in range(n-1):
    s=(((suff[i+1]%mod)*l[i])%mod+s)%mod
print(s)

Measured memory_bytes: 31444