akhauriyash/Code-Regression huggingface dataset:
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=5*1e5+1000;
const int SIZE2=5010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
 
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////
void init(){
 
}
int A[SIZE],B[SIZE];

LL solve(){
	cin >> N;
	REP(i,N) cin >> A[i];
	int ans=0;
	FOR(i,0,N){
		B[A[i]]=B[A[i]-1]+1;
		maximize(ans,B[A[i]]);
	}	
	return N-ans;
}
signed main(){
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 18560
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,y;
    cin >> n >>y;
    rep(i,n+1){
        rep(j,n+1){
            if(i + j <= n){
                int k = n - i - j;
                if(10000*i + 5000*j + 1000*k == y){
                    cout << i << " " << j << " " << k << endl;
                    return 0;
                }
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    int X;
    cin >> X;

    queue<int> q;
    map<int, bool> m;
    q.push(0);
    m[0] = true;
    while(!q.empty()){
        int f = q.front();
        q.pop();
        for (int i = 100; i <= 105; i++){
            if ((f + i) == X){
                cout << 1 << endl;
                return 0;
            }
            else if ((f + i) < X && m[f+i] == false){
                m[f + i] = true;
                q.push(f + i);
            }
        }
    }
    cout << 0 << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int x = n;
  int sum = 0;
  while(n >= 1) {
    sum += n % 10;
    n /= 10;
  }
  if((x % sum) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		//降順にリストをソート
		Collections.sort(list, Collections.reverseOrder());

		//判定
		int max = list.get(0);
		int sum = 0;
		for(int i = 1; i < list.size(); i++) {
			sum += list.get(i);
		}
		if(max < sum) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

void Main() {
    // input
    int A[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }
    
    int N;
    cin >> N;
    for (int k = 0; k < N; k++) {
        int B;
        cin >> B;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (A[i][j] == B) {
                    A[i][j] = -1;
                }
            }
        }
    }

    if (A[0][0] == A[0][1] && A[0][1] == A[0][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[1][0] == A[1][1] && A[1][1] == A[1][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[2][0] == A[2][1] && A[2][1] == A[2][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[0][0] == A[1][0] && A[1][0] == A[2][0]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[0][1] == A[1][1] && A[1][1] == A[2][1]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[0][2] == A[1][2] && A[1][2] == A[2][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[0][0] == A[1][1] && A[1][1] == A[2][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (A[0][2] == A[1][1] && A[1][1] == A[2][0]) {
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	bool f = (S[2] == S[3] && S[4] == S[5]);
	string ans = (f)? "Yes" : "No";

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){	
	string a,b;
	int c,d=0;
	cin>>a>>b;
	a=a+b;
	c=stoi(a);
	for(int i=0;i<1000;i++){
		if(c==i*i){
			cout<<"Yes"<<endl;
		}
		if(i*i>=c && i*i==c){
			break;
		}
		if(i*i>=c && i*i!=c){
			d++;
			break;
			
		}
	}
	if(d==1){
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
from heapq import *

x,y,z,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

q=[]
li=[]
heappush(q,((a[0]+b[0]+c[0]) * (-1),0,0,0))

for i in range(k):
  node=heappop(q)
  
  print(node[0]*-1)
  if node[1]+1 != x:
    node_a = ((a[node[1]+1]+b[node[2]]+c[node[3]])*(-1), node[1]+1, node[2], node[3])
    if node_a not in q:
      heappush(q,node_a)
  
  if node[2]+1 != y:
    node_b = ((a[node[1]]+b[node[2]+1]+c[node[3]])*(-1), node[1], node[2]+1, node[3])
    if node_b not in q:
      heappush(q,node_b)
  
  if node[3]+1 != z:
    node_c = ((a[node[1]]+b[node[2]]+c[node[3]+1])*(-1), node[1], node[2], node[3]+1)
    if node_c not in q:
      heappush(q,node_c)

Measured memory_bytes: 3956
N, A, B = gets.split.map(&:to_i)
M = 10**9 + 7

@f = (1 .. B).each_with_object([1]){|n, o| o << (o.last*n % M)}
@df = N.downto(N - B + 1).each_with_object([1]){|n, o| o << (o.last*n % M)}

def mpow(x, n)
  ret = 1
  while n > 0
    if n.even?
      x = x * x % M
      n >>= 1
    else
      ret = ret * x % M
      n -= 1
    end
  end
  ret
end

def c(n, k)
  @df[k] * mpow(@f[k], M - 2) % M
end

puts (mpow(2, N) - 1 - c(N, A) - c(N, B) + M) % M

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Endl endl
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    vb used(8, false);
    vi data(n);
    rep(i, n) cin >> data[i];
    sort(all(data));
    int free = 0;

    rep(i, n) {
        int tmp = data[i];
        if (tmp < 3200) {
            used[tmp/400] = true;
        } else {
            free++;
        }
    }
    int ans = 0;
    rep(i, 8) {
        if (used[i]) {
            ans++;
        }
    }

    cout << max(ans, (int)1) << " ";
    cout << ans + free << endl;


    return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll T[2];
ll A[2],B[2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T[0]>>T[1];
	cin>>A[0]>>A[1];
	cin>>B[0]>>B[1];
	
	ll X=T[0]*A[0]+T[1]*A[1];
	ll Y=T[0]*B[0]+T[1]*B[1];
	
	if(X==Y) {
		cout<<"infinity"<<endl;
		return;
	}
	
	if(A[0]>B[0] && X>Y) return _P("0\n");
	if(A[0]<B[0] && X<Y) return _P("0\n");
	
	ll P=abs(A[0]-B[0]);
	ll D=abs(X-Y);
	ll Z=P*T[0];
	if(Z%D==0) {
		cout<<Z/D*2<<endl;
	}
	else {
		cout<<1+Z/D*2<<endl;
	}
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,L;
    long long i,j=0;
    cin>>N>>L;
    string vec[N];
    for(i=0;i<N;i++ ){
    cin>>vec[i];
    }
    sort(vec,vec+N);
    for(i=0;i<N;i++)
    cout<<vec[i];
    }


Measured memory_bytes: 256
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

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

typedef long long int ll;
#define endl '\n'
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define point pair <double, double>
#define debug(x) cerr << #x << " is " << x << endl;

const int INF = 1e15 + 0;
//const int mod = 1e9 + 7;
const int mod = 998244353;
const int N = 3e3 + 5;
int dp[N][N], P[N][N];

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

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

  int n, sum; cin >> n >> sum;
  int data[n+5];
  for(int i = 1; i <= n; i++) {
    cin >> data[i];
    dp[i][data[i]] = i;
  }
 
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= sum; j++){
         if((j-data[i]) >= 0){
           dp[i][j] += P[i-1][j-data[i]];
           dp[i][j] %= mod;
         }
         P[i][j] = (dp[i][j] + P[i-1][j]) % mod;
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; i++){
    int temp = (dp[i][sum]*(n-i+1)) % mod; 
    ans += temp; ans %= mod;
  }
  cout << ans << '\n';
}



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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

bool _is_prime(long long int a) {
    if (a < 2)
        return false;
    else if (a == 2)
        return true;

    if (a % 2 == 0)
        return false;

    for (long long int i = 3; i * i <= a; i += 2) {
        if (a % i == 0)
            return false;
    }
    return true;
}

template <typename T>
vector<T> _divisor(T a) {
    vector<T> res;
    res.push_back(a);
    for (T i = 1; i * i <= a; i++) {
        if (a % i == 0) {
            res.push_back(i);
            if (i != 1 && i * i != a)
                res.push_back(a / i);
        }
    }
    return res;
}

template <typename T>
T _gcd(T a, T b) {
    return b ? _gcd(b, a % b) : a;
}

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

    long long a, b;
    cin >> a >> b;

    vll va, vb;
    va = _divisor(a);
    vb = _divisor(b);

    vll vc;
    for (int i = 0; i < va.size(); i++) {
        for (int j = 0; j < vb.size(); j++) {
            if (va[i] == vb[j]) {
                vc.push_back(va[i]);
            }
        }
    }

    sort(vc.begin(), vc.end());
    long long cnt = 1;

    for (int i = 1; i < vc.size(); i++) {
        if (_is_prime(vc[i])) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,k,a[300][300]={},b[300]={},sum=0;
  char c[300][300]={};
  cin >> h >> w >> k;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> c[i][j];
    }
  }
  for(int i=0; i<h; i++) {
    sum=0;
    for(int j=0; j<w; j++) {
      if(c[i][j]=='.') {
        sum++;
      }
    }
    if(sum==w) {
      b[i]++;
    }
  }
  int cnt=1;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(c[i][j]=='#') {
        a[i][j]=cnt;
        cnt++;
      }
    }
  }
  int x;
  for(int i=0; i<h; i++) {
    if(x&&!b[i]) {
      x++;
    }
    for(int j=0; j<w; j++) {
      if(a[i][j]!=0) {
        x=a[i][j];
      }
      else {
        a[i][j]=x;
      }
    }
  }
  int y;
  for(int i=h-1; i>=0; i--) {
    if(y&&!b[i]) {
      y--;
    }
    for(int j=w-1; j>=0; j--) {
      if(a[i][j]!=0) {
        y=a[i][j];
      }
      else {
        a[i][j]=y;
      }
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(b[i]&&i!=0) {
        for(int k=0; k<w; k++) {
          a[i][k]=a[i-1][k];
        }
      }
    }
  }
  for(int i=h-1; i>=0; i--) {
    for(int j=w-1; j>=0; j--) {
      if(b[i]&&i!=h-1) {
        for(int k=w-1; k>=0; k--) {
          a[i][k]=a[i+1][k];
        }
      }
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include <iostream>
 
using namespace std;
 
int main()
{
	int change,money;

	while(1){
	cin>>money;
	if(money<1||money>1000){
		break;
	}else{
		int  coin,coin1,coin2,coin3,coin4,coin5,coin6;

		change=1000-money;

		coin1=change/500;
		coin2=change%500/100;
		coin3=change%500%100/50;
		coin4=change%500%100%50/10;
		coin5=change%500%100%50%10/5;
		coin6=change%500%100%50%10%5/1;

		coin=coin1+coin2+coin3+coin4+coin5+coin6;
		cout<<coin<<"\n";
	
		}
	}



    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int h,w,n;
  cin >> h >> w >> n;
  vector<vector<int>> mapp(h,vector<int>(w));
  int memo,now=0;
  
  rep(i,0,n){
    cin >> memo;
    rep(j,0,memo){
      mapp[now/w][now%w] = i+1;
      now++;
    }
  }
  
  rep(i,0,h){
    if(i%2==1) reverse(ALL(mapp[i]));
  }
  
  rep(i,0,h){
    rep(j,0,w){
      cout << mapp[i][j];
      if(j==w-1) cout << endl;
      else cout << ' ';
    }
  }
  
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
int n[5],i,j,temp;
for(i=0;i<5;i++)
scanf("%d",&n[i]);
for(i=0;i<5;i++)
for(j=4;j>i;j--)
if(n[j]<n[j-1]){
temp=n[j];
n[j]=n[j-1];
n[j-1]=temp;
}
for(i=4;i>0;i--)
printf("%d ",n[i]);
printf("%d\n",n[i]);
return 0;
}

Measured memory_bytes: 596
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};

pub fn solve<R: Read, W: Write>(input: R, output: W) {
    let mut reader = BufReader::new(input);
    let mut writer = BufWriter::new(output);

    let mut buf = String::new();
    reader.read_to_string(&mut buf).unwrap();
    let mut v = buf.split_whitespace().map(|s| s.parse::<i32>().unwrap());
    let k = v.next().unwrap();
    let s = v.next().unwrap();

    let mut cnt = 0;
    for x in 0..(k + 1) {
        for y in 0..(k + 1) {
            let z = s - x - y;
            if z >= 0 && z <= k {
                cnt += 1
            }
        }
    }

    writer.write(cnt.to_string().as_bytes()).unwrap();
    writer.write(b"\n").unwrap();
}

fn main() {
    solve(stdin(), stdout());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, cnt = 0, a[105];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        cnt += ((i & 1) && (a[i] & 1));
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 3744
#include<stdio.h>
int main()
{
    int i , j , k;
    scanf("%d %d",&i,&j);
    int f = (i+j)%2;
    if(f==0)
    {
        k = (i+j)/2;
        printf("%d\n",k);
    }
    else
        printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
INF = float("inf")

import math
import collections


def solve(N: int, a: "List[int]"):
    print(int(sum([math.log2(v & -v) for v in a])))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll f[200005], fi[200005];

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    sort(c.begin(), c.end(), greater<>());

    f[0] = 1;
    for (int i = 1; i <= n; ++i) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[n] = modpow(f[n], MOD - 2);
    for (int i = n; i > 0; --i) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ll tmp = (i == 0 ? 1 : (i + 2) * modpow(2, i - 1) % MOD);
        (tmp *= modpow(4, n - i - 1) * modpow(2, i + 1) % MOD * c[i] % MOD) %= MOD;
        (ans += tmp) %= MOD;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4992
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		long zero=0;
		long plus=0;
		long ma=0;
		ArrayList<Long> p=new ArrayList<>();
		ArrayList<Long> mai=new ArrayList<>();
		for(int i=0; i<n; i++){
			long a=sc.nextLong();
			if(a>0){
				plus++;
				p.add(a);
			}else if(a<0){
				ma++;
				mai.add(a);
			}else{
				zero++;
			}
		}
		long l=-1000000000000000000L;
		long r=1000000000000000001L;
		long mz=ma*plus+((long)(n-1)*n/2-(n-zero)*(n-zero-1)/2);
		if(ma*plus>=k){
			r=-1;
		}else if(mz>=k){
			System.out.println(0);
			return;
		}else{
			l=0;
		}
		Collections.sort(p);
		Collections.sort(mai);
		while(r-l>1){
			long m=(r+l)/2;
			long count=(m>0)?mz*2:0;
			int start=0;
			for(int i=0; i<p.size(); i++){
				int in=0;
				if(m>0){
					in=bug(p,m/p.get(p.size()-1-i),start);
					if(in>=p.size()-i){
						count--;
					}
				}else{
					in=bug(mai,(m-p.get(i)+1)/p.get(i),start);
				}
				start=in;
				count+=in;
			}
			start=0;
			for(int i=0; i<mai.size(); i++){
				int in=0;
				if(m>0){
					in=mai.size()-bug(mai,(m/mai.get(mai.size()-1-i))-1,start);
					if(in>=i+1){
						count--;
					}
					start=mai.size()-in;
				}else{
					in=p.size()-bug(p,(m+1)/mai.get(i),start);
					start=p.size()-in;
				}
				count+=in;
			}
			if(count/2<k){
				l=m;
			}else{
				r=m;
			}
		}
		System.out.println(r);
	}
	static int bug(ArrayList<Long> t,long s,int start){
		while(start<t.size() && t.get(start)<=s){
			start++;
		}
		return start;
	}
}


Measured memory_bytes: 96488
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (register ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 5e2 + 5 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 20000116 ;
const double eps = 1e-7 ;
template <class T = int> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, m, ans, tot;

ll f[maxn], g[maxn], sumc[maxn], h[maxn][maxn], pos[maxn], cnt, rnk[maxn], idx[maxn];

pair <ll, ll> c[maxn << 1];

signed main()
{
	scanf("%lld %lld", &n, &m);
	rep(i, 0, n + n - 1)
	{
		if(i < n) f[i] = ll(floor(sqrt(n * n - i * i - 1))) + 1;
		g[i] = min(ll(floor(sqrt(4 * n * n - i * i)) + 1), n + n);
	}
	rep(i, 0, n - 1) c[++ tot] = mp(f[i], 1 + (i << 2));
	rep(i, 0, n - 1) c[++ tot] = mp(g[i], 2 + (100000 << 2));
	rep(i, n, n + n - 1) c[++ tot] = mp(g[i], 3 + (10000 << 2));
	sort(c + 1, c + tot + 1);
	rep(i, 1, tot)
	{
		if((c[i].se & 3) == 1) pos[++ cnt] = i, rnk[i] = cnt, idx[i] = n + n + cnt;
		sumc[i] = sumc[i - 1] + ((c[i].se & 3) == 3);
	}
	rep(k, 0, n)
	{
		clr(h);
		h[0][0] = 1;
		rep(i, 1, n + n) rep(j, 0, k)
		{
			if((c[i].se & 3) == 3) (h[i][j] += h[i - 1][j] * (c[i].fi - (j + sumc[i] - 1)) % m) %= m;
			else
			{
				(h[i][j] += h[i - 1][j] * (c[idx[i]].fi - (n + k + (i - 1 - sumc[i] - j))) % m) %= m;
				if(j) (h[i][j] += h[i - 1][j - 1] * (c[i].fi - (j + sumc[i] - 1)) % m) %= m;
			}
		}
		// printf("sum : %lld\n", h[n + n][k]);
		(ans += (k & 1 ? m - 1 : 1) * h[n + n][k] % m) %= m;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> x(N);
  vector<double> y(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }
  vector<double> l((N * (N - 1)) / 2);
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double dx = pow(x[j] - x[i],2);
      double dy = pow(y[j] - y[i],2);
      l[count] = sqrt(dx + dy);
      count++;
    }
  }
  double av = 0;
  for (int i = 0; i < (N * (N - 1)) / 2; i++) {
    av += l[i] / ((N * (N - 1)) / 2);
  }
  cout << fixed << setprecision(120) << av * (N - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

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

int main(){
    int n, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i+=2){
        int cnt = 0;
        for(int y = 1; y <= i; ++y){
            if(i % y == 0) ++cnt;
        }
        if(cnt == 8){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	int n,m;
	int l;
	int min;
	int max;
	int f;
	scanf("%d",&n);
	
	m = n/100;
	l = n % 100;
	max = m * 5;
	if(max >= l){	f =  1;}
	else{	f = 0;	}

	printf("%d\n",f);


	return 0;
}



Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define debug cout<<"****************"<<endl
using namespace std;
typedef long long ll;
inline void ju() {
	freopen("***.in","r",stdin);
	freopen("***.out","w",stdout);
}
inline ll rd() {
	ll x=0,f=1; char c=getchar();
	while((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(c>='0'&&c<='9') {
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int N=1e5+10;
char s[N];
int main() {
	scanf("%s",s+1);
	bool f=0;
	for(char c='a';c<='z';++c) {
		int l=1,r=-1,t=0;
		for(int i=1;s[i];++i) {
			if(t<0) l=i,t=0;
			if(s[i]==c) ++t;
			else --t;
			if(t>0&&i>l) {
				r=i; break;
			}
		}
		if(r!=-1) {
			f=1;
			printf("%d %d\n",l,r);
			break;
		}
	}
	if(!f) puts("-1 -1");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N,ans;

int main() {


	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	FOR(i, 1, N+1) {
		ll y = N / i;
		ans += y*(y + 1)*i / 2;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    map<string,int> S;
    S["SUN"] = 7;
    S["MON"] = 6;
    S["TUE"] = 5;
    S["WED"] = 4;
    S["THU"] = 3;
    S["FRI"] = 2;
    S["SAT"] = 1;
    string s;
    cin>>s;
    cout<<S[s]<<endl;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())
count = 0
while count<K:
    if count%2==0:
        if A%2==0:
            A//=2
            B+=A
        else:
            A-=1
            A//=2
            B+=A
    else:
        if B%2==0:
            B//=2
            A+=B
        else:
            B-=1
            B//=2
            A+=B
    count+=1
print(A,B)

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

#define REP(i, n) for(int i = 0;i < (int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

int med(int N, vector<int> x) {
  if (N % 2 == 0) {
    return x[N / 2 - 1] + x[N / 2];
  } else {
    return x[(N - 1) / 2];
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  REP(i, N) {
    cin >> a[i] >> b[i];
  }
  sort(ALL(a));
  sort(ALL(b));
  cout << med(N, b) - med(N, a) + 1 << endl;
}

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

typedef long long ll;

int main()
{
  ll n, m, sum = 0;

  cin >> n;
  m = n;

  while(n != 0){
    sum += n % 10;
    n /= 10;
  }

  if(m % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <queue>
#include <utility>
#include <functional>
#include <sstream>
using namespace std;
#define ll long long
 
int main(void){
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){ 
            if(s[i+j]!=t[j]){ 
                ans = max(ans, j);
                break;
            }
            if(j == n-1)
                ans = n;
        }
    }
    cout << n*2-ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ss second
#define ff first 
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0)return (power((x*x)%M,n/2))%M;else return ((x%M)*power(x,n-1)%M);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
    for (ll i = 1; i <= n; i++){ 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll ncrmod(ll n, ll r, ll p){ 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
   return (ncrmod(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p;  
} 
ll modInverse(ll a,ll m) 
{ 
   ll m0 = m; 
   ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
       ll q = a / m; 
       ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
const ll m=1000000009;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double a,b,c;
cin>>a>>b>>c;
if((a/c)<=b){
cout<<"Yes";
}else{
cout<<"No\n";
}
return 0;
}

Measured memory_bytes: 3740
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean[] minColors = new boolean[8];
		boolean[] maxColors = new boolean[8];
		int countMaxRate = 0;
		for(int i = 0; i < n; i++){
			int score = in.nextInt();
			int rate = score / 400;
			if(rate < 8){
				minColors[rate] = true;
				maxColors[rate] = true;
			}else{
				countMaxRate++;
			}
		}
		for(int i = 0; i < countMaxRate; i++){
			boolean hasFound = false;
			for(int j = 0; j < 8; j++){
				if(minColors[j]){
					hasFound = true;
					break;
				}
			}
			if(!hasFound){
				minColors[0] = true;
				break;
			}
		}
		int min = getCount(minColors);
		int max = getCount(maxColors) + countMaxRate;
		System.out.println(min + " " + max);
		in.close();
	}
	int getCount(boolean[] a){
		int count = 0;
		for(boolean b : a){
			if(b) count++;
		}
		return count;
	}

}


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

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


int main() {
    int H,W;
    cin >> H >> W;
    bool C[H+2][W+2] = {};
    for(int i=1;i<=H;i++){
        string S;
        cin >> S;
        int j=1;
        for(char c : S){
            if(c == '#'){
                C[i][j] = true;
            }
            j++;
        }
    }
    int L[H+2][W+2] = {};
    int R[H+2][W+2] = {};
    int U[H+2][W+2] = {};
    int D[H+2][W+2] = {};

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(C[i][j]){
                L[i][j] = 0;
                U[i][j] = 0;
            }else{
                L[i][j] = L[i][j-1] + 1;
                U[i][j] = U[i-1][j] + 1;
            }
        }
    }
    for(int i=H;1<=i;i--){
        for(int j=W;1<=j;j--){
            if(C[i][j]){
                R[i][j] = 0;
                D[i][j] = 0;
            }else{
                R[i][j] = R[i][j+1] + 1;
                D[i][j] = D[i+1][j] + 1;
            }
        }
    }
    int M = 0;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            M = max(M,L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
        }
    }
    cout << M << endl;

    return 0;
} 

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

using namespace std;

int main(int argc, char* artv[])
{
    int N; cin >> N;

    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }

    for (int i = 0; i < N; i++) {
        cin >> C[i];
        V[i] -= C[i];
    }

    sort(V.begin(), V.end(), greater<int>());

    int total = 0;
    for (int i = 0; i < N; i++) {
        if (V[i] < 0) {
            break;
        }
        total += V[i];
    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll ksm(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		b/=2;
		a=a*a%mod;
	}
	return ans%mod;
}
int main()
{
	int n;
	ll s[10005];
	set<int> st;
	map<int,int> mp;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s[i];
	ll res=1;
	//cout<<ksm(2,3)<<endl;
	for(int i=0;i<n;i++)
	{
		int x=s[i];
		set<int> st1;
		map<int,int> mp1;
		for(int j=2;j*j<=s[i];j++)
		{
			if(x%j==0) st1.insert(j);
			while(x%j==0)
			{
				mp1[j]++;
				x/=j;
			}
		}
		if(x>1) st1.insert(x),mp1[x]++;
		for(auto v:st1)
		{
			st.insert(v);
			mp[v]=max(mp[v],mp1[v]);
		}
	}
	for(auto vv:st)
	{
	//	cout<<vv<<' '<<mp[vv]<<endl;
		res=(res*ksm(vv,mp[vv]))%mod;
	}
	ll ans=0;
//	cout<<res<<endl;
	for(int i=0;i<n;i++)
		ans=(ans+res*ksm(s[i],mod-2))%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>

int main(void){
	char **hand;
	int no[3], turn = 0;
	hand = malloc(sizeof(char*) * 3);
	for(int i = 0; i < 3; i++){
		no[i] = 0;
		hand[i] = malloc(sizeof(char) * 100);
		scanf("%s", hand[i]);
	}
	while(1){
		if(hand[turn][no[turn]] == '\0'){
			printf("%c\n", 'A' + turn);
			break;
		}
		turn = hand[turn][no[turn]++] - 'a';
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxm = 4012;

int f[maxm][maxm];

int m;
int mod = 1e9+7;
int ans = 0;
int x,y;
int g[maxm*2][maxm];
int maxx,maxy;
bool flag[maxm][maxm];

struct self
{
    int x,y;
    self(const int &xx, const int &yy)
    {
        x=xx;
        y=yy;
    }
};
queue<self> q;

void calc()
{
    q.push(self(2000-maxx,2000-maxy));
    flag[2000-maxx][2000-maxy]=1;
    while(!q.empty())
    {
        self u=q.front();q.pop();
        int x,y;
        x=u.x;
        y=u.y+1;
        if(x<=maxx+2000 && y<=maxy+2000)
        {
            f[x][y]=(f[x][y]+f[u.x][u.y])%mod;
            if(!flag[x][y])
            {
                flag[x][y]=1;
                q.push(self(x,y));
            }
        }
        x=u.x+1;
        y=u.y;
        if(x<=maxx+2000 && y<=maxy+2000)
        {
            f[x][y]=(f[x][y]+f[u.x][u.y])%mod;
            if(!flag[x][y])
            {
                flag[x][y]=1;
                q.push(self(x,y));
            }
        }
    }
}

long long rev(long long a)
{
    if(a==1)return 1;
    return rev(mod%a)*(mod-mod/a)%mod;
}

struct node
{
    int x,y;
}s[200011];

int main()
{
    g[1][0]=g[1][1]=1;
    for(int i=2;i<=8000;i++)
    {
        g[i][0]=1;
        for(int j=1;j<=min(i,4000);j++)
            g[i][j]=(g[i-1][j]+g[i-1][j-1])%mod;
    }

    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        s[i].x=x;s[i].y=y;
        f[2000-x][2000-y]++;
        maxx=max(maxx,x);
        maxy=max(maxy,y);
        ans=(ans+mod-g[x*2+y*2][x*2])%mod;
    }
    calc();
    for(int i=1;i<=m;i++)
    {
        ans=(ans+f[s[i].x+2000][s[i].y+2000])%mod;
    }
    cout<<ans*rev(2)%mod<<endl;
    return 0;
}


Measured memory_bytes: 188160
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<string> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,w ; cin >> n >> w ;
	vvll dp(n+1,vll(w+1,0)) ;
	for(int i=1;i<=n;i++){
		ll a,b ;
		cin >> a >> b ;
		for(int j=0;j<=w;j++){
			if(j<a) dp.at(i).at(j) = dp.at(i-1).at(j) ;
			else dp.at(i).at(j) = max(dp.at(i-1).at(j),dp.at(i-1).at(j-a)+b) ;
		}
	}
	cout << dp.at(n).at(w) << endl ;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define f first
#define s second
#define INF 1e9
using namespace std;
typedef pair <int,int> P;
int n;
string str[101];
 
int get_idx(string a){
  int i=0;
  while(str[i].substr(0,str[i].size()-1)!=a) i++;
  return i;
}
 
 
int dijkstra(){
  int D[101],used[101]={};
  for(int i=0;i<n;i++) D[i]=INF;
  priority_queue <P,vector<P>,greater<P> > Q;
  Q.push(P(0,0));
  D[0]=0;
  while(!Q.empty()){
    P t=Q.top();Q.pop();
    int pos=t.s,cost=t.f;
    if(used[pos])continue;
    if(pos==n) return cost; 
    used[pos]=1;
    string a;
    int i=0;
    while(str[pos][i]!=' '&&str[pos][i]) a+=str[pos][i++];
    if(a=="goto"){
      string lab;
      i++;
      while(str[pos][i]!=';') lab+=str[pos][i++];
      int nx=get_idx(lab);
      Q.push(P(cost,nx));
      D[nx]=min(D[nx],cost); //goto
 
      Q.push(P(cost+1,pos+1));
      D[pos+1]=min(D[pos+1],cost+1); //cut
    }
    else{
      Q.push(P(cost,pos+1));
      D[pos+1]=min(D[pos+1],cost);
    }
  }
  return -1;
}
 
int main(){
  cin>>n;
  getline(cin,str[0]);
  for(int i=0;i<n;i++) getline(cin,str[i]);
  cout << dijkstra()<<endl;
  return 0;
}

Measured memory_bytes: 1224
import math

def gcd(x, y):
    if x < y:
        x, y = y, x
    
    while y != 0:
        x, y = y, x % y
    return x
    
    '''
    if y == 0:
        return x
    
    return gcd(y, x % y)
    '''

if __name__ == '__main__':
    x, y = list(map(int, input().split(' ')))
    print(gcd(x, y))


Measured memory_bytes: 5668
#include<stdio.h>

int main(void)
{
    char num[1000];
    int sum = 0, i = 0;
    
    while(1){
        scanf("%s", &num);
        if(num[0] == '0'){
            break;
        }
        sum = 0;
        for(i=0;num[i] != '\0';i++){
            sum += num[i] - '0';
        }
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 536
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> S;
  int ret = 1;
  char now;
  cin >> now;
  char before = now;
  rep(i, N) {
    cin >> now;
    if(before!=now) {
      ++ret;
    }
    before = now;
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
# ALDS1_2_C.
# バブルソートと選択ソートの安定性。
from math import sqrt, floor

class card:
    def __init__(self, _str):
        # S3とかH8をもとに初期化。
        self.kind = _str  # 出力用。
        self.suit = _str[0]
        self.value = int(_str[1])

def cardinput():
    # カードの配列からオブジェクトの配列を生成。
    a = input().split()
    cards = []
    for i in range(len(a)):
        cards.append(card(a[i]))
    return cards

def show(a):
    # 配列の中身を出力する。
    _str = ""
    for i in range(len(a) - 1):
        _str += a[i].kind + " "
    _str += a[len(a) - 1].kind
    print(_str)

def bubble_sort(a):
    # aをバブルソートする(交換回数をreturnする)。
    count = 0
    for i in range(1, len(a)):
        k = i - 1
        while k >= 0:
            # a[i]を前の数と交換していき、前の方が小さかったら止める。
            if a[k].value > a[k + 1].value:
                a[k], a[k + 1] = a[k + 1], a[k]
                count += 1
            else: break
            k -= 1
    return count

def selection_sort(a):
    # 選択ソート。その番号以降の最小値を順繰りにもってくる。
    # 交換回数は少ないが比較回数の関係で結局O(n^2)かかる。
    count = 0
    for i in range(len(a)):
        # a[i]からa[len(a) - 1]のうちa[j]が最小っていうjを取る。
        # このときiとjが違うならカウントする。
        # というかa[i]とa[j]が違う時カウントでしたね。
        minj = i
        for j in range(i, len(a)):
            if a[j].value < a[minj].value: minj = j
        if a[i].value > a[minj].value: count += 1; a[i], a[minj] = a[minj], a[i]
    return count

def main():
    N = int(input())
    cards = cardinput()
    # バブルソートは安定。同じvalueなら団子のようにくっつくから。
    # 選択ソートは交換が飛び越えるので不安定。よって、
    # バブルの結果と比較すれば安定か不安定かが分かる。
    _copy = [cards[i] for i in range(N)]

    bubble_sort(cards)
    selection_sort(_copy)

    show(cards)
    print("Stable")
    show(_copy)

    is_stable = True
    for i in range(N):
        for j in range(i + 1, N):
            if _copy[i].value != _copy[j].value: continue
            if _copy[i].suit != cards[i].suit: is_stable = False; break
    if is_stable: print("Stable")
    else: print("Not stable")

if __name__ == "__main__":
    main()


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

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;
const int inf = 1e17+21;



int32_t main(){
    FAST;

    int a,b,c;  cin >> a >> b >> c;
    int k ; cin >> k;

    while(k--){
        int mx = max({a,b,c});
        if(mx == a) a *= 2;
        else if(mx == b) b *= 2;
        else if(mx == c) c *= 2;
    }

    cout << (a+b+c);

    return 0;
}


Measured memory_bytes: 256
h,w = list(map(int, input().split()))

board = []
board.append(['.'] * (w+2))
for i in range(h):
    board.append(list('.' + input() + '.'))
board.append(['.'] * (w+2))

for i in range(1,h+1):
    for j in range(1,w+1):
        left = board[i][j-1]
        upper = board[i-1][j]
        if left == '#' and upper == '#':
            print('Impossible')
            exit()
print('Possible')

Measured memory_bytes: 3064
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n) cin>>a[i];
    int x=a[0];
    int ctr=1;
    rep(i,1,n){
        if(x>=a[i]){
            // cout<<a[i]<<' ';
            ctr++;
        }
        x=min(x,a[i]);
    }
    // cout<<'\n';
    cout<<ctr;
}
    
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

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

#define watch(x) cout << (#x) << " = " << x << endl;
#define mkp make_pair
#define mkt make_tuple
#define pb push_back
#define ll long long
#define ld long double

using namespace std;

bitset<100010> dp;
int n, k;
int a[110];

int main(){
  	scanf("%d%d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	dp = 0;
	
	for(int i = 1; i <= k; i++){
		for(int j = 0; j < n; j++){
			if(a[j] <= i) dp[i] = dp[i] | (dp[i - a[j]] ^ 1);
		}
	}

	if(dp[k]) printf("First\n");
	else printf("Second\n");

	return 0;
}

Measured memory_bytes: 256