akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main (void){

    int a[4];
    int b[4];

    int i,j,k;
    int hits;
    int blows;

    while(scanf("%d",&a[0])!=EOF){
        for(i=1;i<4;i++){
            scanf("%d",&a[i]);
        }
        for(i=0;i<4;i++){
            scanf("%d",&b[i]);
        }

        hits=0;
        blows=0;

        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                //printf("#DEB b[%d]=%d a[%d]=%d\n",i,b[i],j,a[j]);
                if(b[i]==a[j]){
                    if(i==j){
                        //printf("#DEB0--%d,%d--\n",i,j);
                        hits++;
                    }else{
                        //printf("#DEB2--%d,%d--\n",i,j);
                        blows++;
                    }
                }
            }
        }

        printf("%d %d\n",hits,blows);
    }

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int count =0;
  for(int n=1;n<=N;n++){
    
  for(int i=1;i<=sqrt(n);i++){
    
    for(int j=1;j<=sqrt(n);j++){
      
      for(int k=1;k<=sqrt(n);k++){
        if(i*i+j*j+k*k+i*j+j*k+k*i>n)break;
        if(i*i+j*j+k*k+i*j+j*k+k*i==n)count++;
      }
    }
  }
    cout << count << endl;
    count = 0;
  }
}



Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main(){
    int a[3];
    rep(i, 0, 3) cin >> a[i];
    sort(a, a + 3);
    cout << a[0] + a[1] << endl;
}

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

int main(){
	int a,b,sum=0;
	// int x;
	scanf("%d",&a);
	b=a;
	//printf("%d",a);
	for(int i=0;;i++){
		if(a>=1){
			sum=sum+(a%10);
			a=a/10;
			//printf("%d",a);
			//printf("%d",sum);
			}
		else break;
		}
	//printf("%lld\n",sum);
	if(b%sum==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}



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

using namespace std;

#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll, ll>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
// #define fat 1000000007
#define fat 998244353
#define PI_2 1.57079632679489661923

ll power(ll base, ll exp, ll mod) // O(logn) time
{
    ll ans=1LL;
    while(exp){
        if(exp&1LL) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exp>>=1LL;
    }
    return ans%mod;
}

int main()
{
    ll tt = 1, n, m, k = 0, i, j, p, q;
    ll a, b, c, d, u, v, x, y, s;
    ll ans = 0;

    ll l = 0, r = 0;
    bool poss = true;

    boost;
    string sa, sb;


    // cin >> tt;  
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> n >> s;
        
        vi pow2(n + 1, 0);
        pow2[0] = 1;
        for(i = 1; i <= n; i++){
            pow2[i] = (2*pow2[i-1])%fat;
        }

        vi arr(n);
        loop(z, arr) cin >> z;
        sort(arr.B, arr.E);

        vi sum(s + 2, 0);
        
        ll inv2 = power(2, fat - 2, fat);

        for(i = 0; i < n; i++){
            for(j = s - arr[i]; j > 0; j--){
                sum[j + arr[i]] = (sum[j + arr[i]] + (sum[j]*inv2)%fat)%fat;
            }
            if(arr[i] <= s)
                sum[arr[i]] = (sum[arr[i]] + pow2[n-1])%fat;
        }
        cout << sum[s] << nl;
    }   

    return 0;
}

Measured memory_bytes: 3712
n, m=map(int,raw_input().split())
a = []
b = []

for i in range(n):
    a.append(map(int, raw_input().split()))
for i in range(m):
    b.append(input())
for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j]*b[j]
    print ans

Measured memory_bytes: 6616
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint A;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	int val=A[0];
	int head=1;
	ll ans=0;
	for(int tail=0;tail<N;tail++){
		while(head<N && (val+A[head])==(val^A[head])){
			val^=A[head];
			head++;
		}
		ans+=head-tail;
		val^=A[tail];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
    ll n; cin >> n;
    cout << n*(n-1)/2 << endl;
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    vec<int> dp0(2019, 0);
    // vec<int> dp1(2019, 0);

    dp0[0] = 1;
    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        vec<int> dp1(2019, 0);
        int s = S[i - 1] - '0';
        dp1[s] += 1;
        rep(j, 2019) {
            if (dp0[j] >= 1 && (i - 1 != 0)) {
                dp1[(j * 10 + s) % 2019] += dp0[j];
            }
        }
                ans += dp1[0];
        copy(all(dp1), dp0.begin());

    }
    cout << ans << endl;
}


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

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

const int dm = 1 << 19;
char dn[dm], * di = dn;

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


	int N = getint(), K = getint(), Q = getint();

	int P[100001];
	rep1(i, N) {
		P[i] = K - Q;
	}
	rep(i, Q) {
		P[getint()]++;
	}
	rep1(i, N) {
		if (P[i] > 0) {
			*di++ = 'Y';
			*di++ = 'e';
			*di++ = 's';
			*di++ = '\n';
		}
		else {
			*di++ = 'N';
			*di++ = 'o';
			*di++ = '\n';
		}
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1408
H,W=map(int,input().split())
def f(a,b):
  c=a//3
  d=(a-c)//2
  e=a-c-d
  return(b*(e-c))
def g(a,b):
  c=a//3
  d=b//2
  s1=b*c
  s2=(a-c)*d
  s3=(a-c)*(b-d)
  S1=(max(s1,s2,s3)-min(s1,s2,s3))
  e=a//3+1
  f=b//2
  s4=e*b
  s5=(a-e)*f
  s6=(a-e)*(b-f)
  S2=(max(s4,s5,s6)-min(s4,s5,s6))
  return min(S1,S2)

print(min(f(H,W),f(W,H),g(H,W),g(W,H)))  

Measured memory_bytes: 80300
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
const u32 P=998244353;
u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
u32 sum(u32 a, u32 b) {return inc(a, b);}
u32 dif(u32 a, u32 b) {return dec(a, b);}
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
	return ans;
}

const int N=5e5+5;
u32 fac[N], ifac[N];
u64 com(int n, int r) {
	return n<0||r<0||r>n?0:(u64)fac[n]*ifac[r]%P*ifac[n-r]%P;
}
u64 sol(int x, int y, int l) {
	return com(x+y, x)-com(x+y, x+l)+P;
}
int main() {
	int n=rd(), k=rd();
	u32 ans=0;
	fac[0]=1;
	for(int i=1; i<=k; ++i) fac[i]=(u64)fac[i-1]*i%P;
	ifac[k]=power(fac[k], P-2);
	for(int i=k; i--; ) ifac[i]=ifac[i+1]*(i+1llu)%P;
	for(int r=std::max(n, (k+1)/2); r<=k; ++r)
		ans=(ans+sol(r, k-r-(r==k-r), r-n+1))%P;
	printf("%u\n", ans);
	return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		
		for(int i = 0;i < n;i++) {
			a[i] = sc.nextInt();
			
		}
		
		for(int j = (n - 1);j >= 0;j--) {
			if(j == 0) {
				System.out.println(a[j]);
				
			}else {
				System.out.print(a[j] + " ");
			}
		}
				
	}
}


Measured memory_bytes: 26452
n = int(input())
rt = {}
clist = [0 for i in range(n)]
for i in range(n):
    id, k, *c = list(map(int, input().split()))
    for j in c:
        rt[j] = id
    clist[id] = c
for i in range(n):
    print("node %d: parent = "%i, end = "")
    p = [i]
    while 1:
        try:
            p.append(rt[p[-1]])
        except:
            break
    if len(p) == 1:
        print("-1, depth = 0, root,",clist[i])
    else:
        print("%d, depth ="%p[1] ,len(p) - 1, end = "")
        if clist[i] == []:
            print(", leaf, []")
        else:
            print(", internal node,",clist[i])


Measured memory_bytes: 23704
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<int> suzu;
    for(int i=0; i<N-1; i++){
        suzu.push_back(A[i+1]-A[i]);
    }
    sort(suzu.begin(),suzu.end());
    int ans = K;
    for(int i=0; i<N-K; i++){
        ans += suzu[i];
    }
    cout << ans << enld;
    return 0;
}


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

#define y1 dmytxdy
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

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

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int a[1000005];
char s[1000005];

int getans(int x){
	int tag=0,ret=0,now=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='?'){
			if(tag+a[i]+2<=x) tag+=2,now++;
			else now--;
		}
		else now+=s[i]=='1'?1:-1;
		chkmin(ret,now);
	}
	return ret;
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++) a[i]=a[i-1]+(s[i]=='1'?1:-1);
	for(int i=n-1;i>=0;i--) chkmax(a[i],a[i+1]);
	printf("%d\n",min(a[0]-getans(a[0]),a[0]+1-getans(a[0]+1)));
	return 0;
}

Measured memory_bytes: 8688
import bisect

def main():
    n = int(input())
    l = [[i,int(input())] for i in range(n)]
    l.sort(key=lambda x:x[1])
    res =0
    for i in range(n):
        if i % 2 != l[i][0] % 2:
            res += 1
    print(res // 2)


main()

Measured memory_bytes: 21352
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll gcd(ll a2,ll b2){
	ll t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}

int main() {

	int n,m;
	cin>>n>>m;
	int f[100001],f2[100001]={};
	f2[1]=1;

	rep(i,n)f[i+1]=1;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		if(f2[x]==1&&f[x]==1){
			f[y]++;
			f2[y]=1;
			f2[x]=0;
			f[x]--;
		}else if(f2[x]==1){
			f[x]--;
			f[y]++;
			f2[y]=1;
		}else{
			f[x]--;
			f[y]++;
		}
	}
	int t=0;
	rep(i,n){
		if(f2[i+1]==1)t++;
	}
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 1024
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S;
  cin >> S;
  const int64_t L = static_cast<int64_t>(S.length());
  vector<int64_t> counts(3, 0);
  for (int64_t i = 0; i < L; ++i) {
    ++counts[S.c_str()[i] - 'a'];
  }
  sort(counts.begin(), counts.end());
  bool is_okay = false;
  if (L % 3 == 0) {
    if (counts[0] == counts[1] && counts[1] == counts[2]) {
      is_okay = true;
    }
  } else if (L % 3 == 1) {
    if (counts[0] == counts[1] && counts[1] + 1 == counts[2]) {
      is_okay = true;
    }
  } else {
    if (counts[0] + 1 == counts[1] && counts[1] == counts[2]) {
      is_okay = true;
    }
  }
  if (is_okay) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll A, B, ans;
    scanf("%lld %lld", &A, &B);
    if ( A > 9 || B > 9 )   printf("-1\n");
    else printf("%lld\n",A*B);
    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	map<char, vector<int>> MP;
	for(int i=0; i<N; i++){
		string S;
		cin >> S;
		for(int j=0; j<S.size(); j++){
			char c = S[j];
			if(MP.count(c)==0){
				vector<int> v(N, 0);
				v[i]++;
				MP[c] = v;
			}
			else{
				MP[c][i]++;
			}
		}

	}
	for(auto itr = MP.begin(); itr != MP.end(); itr++){
		char c = itr->first;
		vector<int> v = itr->second;
		sort(v.begin(), v.end());
		int L = v[0];
		for(int i = 0; i < L; i++){
			printf("%c", c);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;
//--------------------

int main() {
	long res = 0;
	long N, X; cin >> N >> X;
	long L[1000]; for (int i = 1; i <= N; i++) cin >> L[i];
    long sum[1000];sum[0] = 0; for (int i = 1; i <= N ; i++) sum[i] = sum[i - 1] + L[i];
	long D = 0;
	while (X >= sum[D]) { res++; D++; if(D >= N + 1) break;}
	cout << res << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0560

"""
import sys
from sys import stdin
input = stdin.readline


def solve(M, N, K, field):
    dp_J = [[0] * (N+1) for _ in range(M+1)]
    dp_O = [[0] * (N+1) for _ in range(M+1)]
    dp_I = [[0] * (N+1) for _ in range(M+1)]
    for y in range(M):
        t_J = [0] * (N+1)
        t_O = [0] * (N+1)
        t_I = [0] * (N+1)
        for x in range(N):
            land = field[y][x]
            if land == 'J':
                t_J[x+1] = t_J[x] + 1
                t_O[x+1] = t_O[x]
                t_I[x+1] = t_I[x]
            elif land == 'O':
                t_J[x+1] = t_J[x]
                t_O[x+1] = t_O[x] + 1
                t_I[x+1] = t_I[x]
            else:
                t_J[x+1] = t_J[x]
                t_O[x+1] = t_O[x]
                t_I[x+1] = t_I[x] + 1

        for x in range(1, N+1):
            dp_J[y+1][x] = dp_J[y][x] + t_J[x]
            dp_O[y+1][x] = dp_O[y][x] + t_O[x]
            dp_I[y+1][x] = dp_I[y][x] + t_I[x]

    for _ in range(K):
        result = [0, 0, 0]
        y1, x1, y2, x2 = map(int, input().split())
        result[0] = dp_J[y2][x2] - dp_J[y1-1][x2] - dp_J[y2][x1-1] + dp_J[y1-1][x1-1]
        result[1] = dp_O[y2][x2] - dp_O[y1-1][x2] - dp_O[y2][x1-1] + dp_O[y1-1][x1-1]
        result[2] = dp_I[y2][x2] - dp_I[y1-1][x2] - dp_I[y2][x1-1] + dp_I[y1-1][x1-1]
        print(' '.join(map(str, result)))


def main(args):
    M, N = map(int, input().split())
    K = int(input())
    field = [input().strip() for _ in range(M)]
    solve(M, N, K, field)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 126288
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    h = [INT() for _ in range(n)]

    h.sort()

    lis = [h[i+k-1] - h[i] for i in range(n-k+1)]
    print(min(lis))

if  __name__=='__main__':
    main()

Measured memory_bytes: 13372
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n; cin >> n;
    string s,t; cin>>s>>t;
    string ans;
    
    rep(i,n){
        ans += s[i];
        ans += t[i];
    } 

    cout << ans << ln;
    return 0;
 }

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

const int mod = 1e9+7;
int main(){
int h,w;
  cin>>h>>w;
  char grid[h][w];
  ll dp[h][w];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    {cin>>grid[i][j];
     dp[i][j]=0;
    }
  bool b=true;
  for(int i=0;i<w;i++)
  {
    if(grid[0][i]=='#')
      b=false;
    if(b)
      dp[0][i]=1;
    else
      dp[0][i]=0;
   }
  b=true;
  for(int i=0;i<h;i++){
     if(grid[i][0]=='#')
       b=false;
    if(b)
      dp[i][0]=1;
    else
      dp[i][0]=0;
  }
  
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      if(grid[i][j]=='#')
        dp[i][j]=0;
      else
      dp[i][j] = ( dp[i-1][j]%mod + dp[i][j-1]%mod )%mod;
    }
  }
  
  cout<<dp[h-1][w-1]<<"\n";
  return 0;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0; // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) {
        for(int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM);
    }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for(int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1));
        sub_add(1, a, x);
        sub_add(0, b, x * (b - 1));
        sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for(int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) -
               sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for(int i = 1; i < (int)dat[0].size(); ++i)
            cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for(int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(),
         [&](int i, int j) { return rights[i] < rights[j]; });

    BIT<int> bit(N + 5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for(auto i : ids) {
        for(; r < rights[i]; ++r) {
            bit.add(prev[a[r]] + 2, r + 2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i] + 1, lefts[i] + 2);
        res[i] = max(res[i], tmp);
    }
    for(int i = 0; i < Q; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 21724
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    int n, x, k;
    ll arr[105], sum=0;
    cin >> n >> x;
    for(int i=1; i<=n; i++){
        cin >> arr[i];
        sum+=arr[i];
    }
    if(x>sum){
        k=n-1;
    }
    else if(x<sum){
        sort(arr+1, arr+n+1);
        k=0;
        for(int i=1; i<=n; i++){
            if(x>=arr[i]){
                x-=arr[i];
                k++;
            }
        }
    }
    else{
        k=n;
    }
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int mod = 1000000007;

int main()
{
  int h,w,k;
  cin>>h>>w>>k;
  vector<string> s(h);
  rep(i,h)cin>>s[i];

int ans=INF;

  for (int i=0;i<(1<<h-1);i++){
    vector<int> S;
    for (int z = 0; z < h-1; ++z) {
            if (i & (1<<z)) { // 列挙に i が含まれるか
                S.push_back(z);
            }
    }
    int n=S.size();
    //cout<<n<<endl;
    vector<vector<int>> c(n+1,vector<int>(w));
    int now=0;
    rep(j,n){
      while (now<=S[j]){
        rep(K,w){
          c[j][K]+=s[now][K]-'0';
        //  cout<<now<<'n'<<endl;
        //  cout<<c[j][k]<<'c'<<endl;
             }
             now++;
      }
    }
    int j=n;
    while (now<h){
      rep(K,w){
        c[j][K]+=s[now][K]-'0';
      //  cout<<now<<'n'<<endl;
      //  cout<<c[j][k]<<'c'<<endl;
           }
           now++;
    }

//rep(z,w)cout<<c[0][z]<<endl;
//cout<<i<<endl<<endl;
int ans_now=0;
ans_now+=n;
vector<int> temp(n+1,0);
int mt=0;

rep(j,w){
  rep(z,n+1){
    temp[z]+=c[z][j];
    if (c[z][j]>k){
      ans_now=INF;break;
    }
  //  cout<<temp[z]<<'z'<<endl;
    mt=max(mt,temp[z]);
  }
  //cout<<endl;
  if (mt>k){
    ans_now++;
    rep(q,n+1)temp[q]=c[q][j];
    mt=0;
  }

}
//cout<<ans_now<<endl;
//cout<<i<<endl<<endl;
ans=min(ans,ans_now);



  }
  cout<<ans;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  
  
   long long  n;
    cin >> n;
    long long  ans = 0;
    long long  low;
    for (long long  i=0;i<n;i++){
        long long  tmp;
        cin >> tmp;
        if(i==0){
            low = tmp;
        }
        if(low > tmp){
            low = tmp;
        }
        if(low >= tmp){
            ans++;
        }
    }
    cout << ans << endl;
 
  
  
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
   double a[n+1];
   for(int i=1;i<=n;i++)
    cin>>a[i];
   
   double b[n+1][n+1];
 
    for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      b[i][j]=0.0;
      
   b[0][0]=1;
   double ans=0;
   for(int i=1;i<=n;i++)
   {
       for(int j=0;j<=i;j++)
       {
           if(j==0)
                b[i][j]=b[i-1][j]*(1-a[i]);
            
            else
                b[i][j]=b[i-1][j]*(1-a[i])+b[i-1][j-1]*a[i];
      
            if(i==n&&j>i/2)
             ans+=b[i][j];
       }
   }
   cout<<fixed<<setprecision(9)<<ans<<"\n";
}

Measured memory_bytes: 70656
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 1e6;
const int mod = 1e9+7;

int a,b,c;
map<int,int>m;
int main(void)
{
    cin >> a >> b >> c;
    m[a]++;m[b]++;m[c]++;
    if(m[a] == 2 || m[b] == 2){
        cout << "Yes";
    }
    else
        cout << "No";
    return 0;
}


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

int main() {
	long long H, W, D;
	string C = "RYGB";
	cin >> H >> W >> D;
	if (D % 2 == 0) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				long long U = i + j, V = i - j + W;
				if ((i + j) % 2 == 1) U++, V++;
				U /= 2, V /= 2;
				U %= D, V %= D;
				cout << C[(U < D / 2) * 2 + (V < D / 2)];
			}
			cout << endl;
		}
	}
	else {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << C[(i + j) % 2];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 512
#define M 100
char m[M][M],s[M][M][M],r[M],*z;
cmp(char *p,char *q){
  int r=0;
  for(;*p=='0';p++);
  for(;*q=='0';q++);
  if(r=strlen(p)-strlen(q))return r;
  return strcmp(p,q);
}
main(w,h,i,j,k,l){
	for(;scanf("%d%d",&w,&h),w;puts(z)){
		memset(m,0xff,sizeof(m));
		memset(s,0,sizeof(s));
		memset(r,0,sizeof(r));
		for(j=1;j<=h;j++)scanf("%s",m[j]+1);
		for(i=1;i<=w+1;i++)for(j=1;j<=h;j++)if(m[j][i]<'0'||'9'<m[j][i])m[j][i]=-1;
		for(i=1;i<=w;i++)
			for(j=1;j<=h;j++){
				if(m[j][i]==-1)continue;
				if(cmp(s[j][i-1],s[j-1][i])>0)strcpy(s[j][i],s[j][i-1]),s[j][i][strlen(s[j][i])]=m[j][i];
				else strcpy(s[j][i],s[j-1][i]),s[j][i][strlen(s[j][i])]=m[j][i];
				if(cmp(s[j][i],r)>0)strcpy(r,s[j][i]);
			}
		for(z=r;*z=='0';z++);
	}
return 0;}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010;
int n;
char s[maxn];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n-8;i++)printf("%c",s[i]);
}

Measured memory_bytes: 256
#include <cstdio>
#include <unordered_map>

using namespace std;

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

    unordered_map<long long, int> mp;
    long long a, ans = 0, sum = 0;
    ++mp[0];
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &a);
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    printf("%lld\n", ans);
}
/*
累積和が等しい2点間の、連続する部分列の和は０になる。
ある累積和がn個存在するとき、n個の中から2点を選ぶ組み合わせはnC2通り。

累積和１が３回現れる場合。
1回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 0 <- 初回の累積和はカウントされない
    ++mp[sum];  // mp[1] = 1

2回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 1 <- 累積和１が２回出たのでansがカウントされる。2C2=1通り
    ++mp[sum];  // mp[1] = 2 <- 累積和１が２点に存在する

3回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 2 <- 累積和１が３回出たのでansがカウントされる。3C2=3通り
    ++mp[sum];  // mp[1] = 3 <- 累積和１が３点に存在する
*/


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HI;
typedef priority_queue<int, vector<int>, greater<int> > HDI;

const int N = 100010, M = 1010;

int n, m;
PII a[N];
HI heap;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++ ) scanf("%d%d", &a[i].F, &a[i].S);
	sort(a, a + n);
	
	LL res = 0;
	for (int i = 0, cur = m - 1; cur >= 0; cur -- )
	{
		while (i < n && cur + a[i].F <= m)
		{
			heap.push(a[i].S);
			i ++ ;
		}
		if (heap.size())
		{
			res += heap.top();
			heap.pop();
		}
	}
	
	printf("%lld\n", res);
    return 0;
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    int a, b, k;
    cin >> a >> b >> k;
    set<int> st;
    for (int i = a; i <= b; ++i)
    {
        if (abs(i - a) < k || abs(i - b) < k)
            cout << i << endl;
    }
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
using namespace std;
using VI = vector<long>;
constexpr long MOD = 1e9 + 7;

int k;
int get_d(int x) {
    return 2 * min(x, abs(k - x));
}

int main() {
    int n;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += get_d(x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void print(int n, int a[]);
void print(int n, int a[]);

int n;
int a[1024];

void InsertionSort(int n, int a[]){
    for(int i = 0; i < n; i++){
        int v = a[i];
        int j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        print(n, a);
        if(i != n-1){
            cout << endl;
        }
    }
    
}

void print(int n, int a[]){
    for(int i = 0; i < n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1];
}
int main() {
   
    cin >> n; 
    //int arr[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    InsertionSort(n, a);
    //print(n, a);
    cout << endl;
    

}


Measured memory_bytes: 3104
# coding: utf-8
import copy
N = int(input())
A = list(map(int,input().split()))

S = [0] * (N+1)

for i in range(N):
    S[A[i]] += 1
    ans_ = 0
for i in range(1,N+1):
    s = S[i]
    ans_ += s*(s-1)//2
for i in range(N):
    ans = copy.copy(ans_)
    a = S[A[i]]
    if a > 1:
        ans -= a*(a-1)//2
        ans += (a-1)*(a-2)//2
    print(ans)
    

Measured memory_bytes: 26908
N = int(input())
T, A = map(int,input().split(" "))
H =  list(map(int,input().split(" ")))

out = None
num = None

for i in range(N):
    avg = T - H[i]*0.006
    if num == None:
        out = i
        num = abs(A - avg)
        continue

    if num > abs(A - avg):
        out = i
        num = abs(A - avg)

print(out+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,hsum=0,ans=0;cin>>n>>k;
  lvector H(n,0);rep(i,n) cin>>H[i];
  sort(ALL(H));
  rep(i,n-k) ans+=H[i];
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
from sys import exit
s=input()
x,y=map(int,input().split())

t=[[s[0],1]]
for i in range(1,len(s)):
    if t[-1][0]==s[i]:
        t[-1][1]+=1
    else:
        t.append([s[i],1])

a,b=[],[]
turn=True
#初めまっすぐの場合
if t[0][0]=="F":
    x-=t[0][1]
    t.pop(0)
for i in t:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")


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

		int X = sc.nextInt();

		// 平方根
		double tmp = Math.sqrt(X);
		int tmp2 = (int)tmp;
		double ans = Math.pow(tmp2, 2) ;

		// 立方根
		tmp = Math.cbrt(X);
		tmp2 = (int)tmp;
		double ans2 = Math.pow(tmp2, 3);

		// 5乗根
		tmp = Math.pow(X, 1.0 / 5.0);
		tmp2 = (int)tmp;
		double ans3 = Math.pow(tmp2, 5);

		if (ans >= ans2){
			if (ans >= ans3){
				System.out.println((int)ans);
			}else{
				System.out.println((int)ans3);
			}
		}else{
			if(ans2 >= ans3){
				System.out.println((int)ans2);
			}else{
				System.out.println((int)ans3);
			}

		}
	}
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
long long int mod=1000000007;
int main(){
	long long int n;
	cin>>n;
	long long int ans=1;
	for(long long int i=0;i<n;i++){
		ans*=10;
		ans%=mod;
	}
	long long int ans2=1;
	for(long long int i=0;i<n;i++){
		ans2*=9;
		ans2%=mod;
	}
	long long int ans3=1;
	for(long long int i=0;i<n;i++){
		ans3*=8;
		ans3%=mod;
	}
	ans%=mod;
    ans=(ans+mod)%mod;
    ans2%=mod;
    ans2=(ans2+mod)%mod;
    ans3%=mod;
    ans3=(ans3+mod)%mod;
    long long int ans4=((ans%mod)-(2*ans2%mod)+(ans3%mod)%mod);
    ans4%=mod;
    ans4=(ans4+mod)%mod;
	cout<<ans4<<endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int x;
int main(){
	x=read();
	cout<<x+x*x+x*x*x<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)

typedef long long ll;

#define gc getchar()
inline int read(){char c,p=0;int w;
	while(!isdigit(c=gc))if(c=='-')p=1;w=c&15;
	while(isdigit(c=gc))w=w*10+(c&15);return p?-w:w;
}

template<typename T,typename U>inline bool smin(T&x,const U&y){return y<x?x=y,1:0;}
template<typename T,typename U>inline bool smax(T&x,const U&y){return x<y?x=y,1:0;}
const int N=5e5+5;
int n,a[N],b[N],c[N];
std::multiset<int>s;
int main(){
	n=read();
	if(n==1)return puts("0"),0;
	REP(i,1,n)a[i]=read();
	std::sort(a+1,a+1+n);
	REP(i,1,n)b[i]=a[i];
	int m=std::unique(b+1,b+1+n)-b-1;
	REP(i,1,n)++c[std::lower_bound(b+1,b+1+m,a[i])-b];	
	int ans=0;
	for(ll u=1ll<<32;u;u>>=1){
		for(int i=1;i<=m;++i)if(c[i]){
			--c[i];	
			int x=std::lower_bound(b+1,b+1+m,u-b[i])-b;
			if(x<=m&&b[x]==u-b[i]&&c[x]){
				++c[i];
				if(x^i){
					int t=std::min(c[i],c[x]);
					ans+=t;c[i]-=t,c[x]-=t;
				}else{
					ans+=c[i]>>1;
					c[i]&=1;
				}
				continue;
			}
			++c[i];		
		}
	}
	std::cout<<ans;
	return 0;
}


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

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

int input[52],n,summ;
int ans[52];
int used[52];
int cnt[14];

bool dfs(int cc,int sum) {
    if(cc == n) return true;
    rep(i,14) {
        if(cnt[i] == 0) continue;
        if((sum-i)%i == 0) {
            cnt[i]--;
            ans[cc] = i;
            if(dfs(cc+1,sum-i)) return true;
            ans[cc] = -1;
            cnt[i]++;
        }
    }
    return false;
}

int main() {
    while(cin>>n, n) {
        summ = 0;
        memset(ans, 0, sizeof(ans));
        memset(cnt, 0, sizeof(cnt));
        memset(used, -1, sizeof(used));
        rep(i,n) {
            cin>>input[i];
            summ += input[i];
            cnt[input[i]]++;
        }
        rep(i,52) used[i] = -1;

        if(dfs(0,summ)) {
            for(int i=n-1; i>0; --i)  cout<<ans[i]<<" ";
            cout<<ans[0]<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 868
N, M, X = map(int, input().split())
A = map(int, input().split()) 

setA = set(A) 
s1 = range(0, X)
s2 = range(X, N+1)
a1 = set(s1) & (setA)
a2 = set(s2) & (setA)
cost1 = len(a1)
cost2 = len(a2)

if cost1 >= cost2:
    print(cost2)
else:
    print(cost1)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n;
pair<ll,pair<int,int> >c[200001];
int ch[100001][2];
int cnt[4];
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n ;i++){
		int a,b;cin >> a >> b;
		c[i*2-1]={a,{i,0}};
		c[i*2]={b,{i,1}};
	}
	sort(c+1,c+2*n+1);
	ll sum=0;
	for(int i=1; i<=n ;i++){
		ch[c[i].se.fi][c[i].se.se]=1;
		sum+=c[i].fi;
	}
	for(int i=1; i<=n ;i++){
		cnt[ch[i][0]*2+ch[i][1]]++;
	}
	if(cnt[3]!=0 || cnt[2]==n || cnt[2]==0) return cout << sum << endl,0;
	ch[c[n].se.fi][c[n].se.se]=0;ch[c[n+1].se.fi][c[n+1].se.se]=1;
	cnt[0]=cnt[1]=cnt[2]=cnt[3]=0;
	for(int i=1; i<=n ;i++){
		cnt[ch[i][0]*2+ch[i][1]]++;
	}
	if(cnt[3]!=0 || cnt[2]==n || cnt[2]==0) cout << sum-c[n].fi+c[n+1].fi << endl;
	else cout << min(sum-c[n].fi+c[n+2].fi,sum-c[n-1].fi+c[n+1].fi) << endl;
}

Measured memory_bytes: 4224
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        h:usize,w:usize,
        a:[Chars;h],
    }
    let mut c = vec![vec!['#'; w + 2]; h + 2];

    for i in 0..h {
        for j in 0..w {
            c[i + 1][j + 1] = a[i][j];
        }
    }
    for x in c.iter() {
        for y in x.iter() {
            print!("{}", y);
        }
        println!();
    }
}


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


int main() {
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	int j = 1;
	while(a > 0 && c > 0) {
		if(j%2==0)
			a-=d;
		else
			c-=b;
		//cout<<a<<", "<<c<<endl;
		j++;
	}
	if(a <= 0)
		cout<<"No";
	else
		cout<<"Yes";
}




Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  string s;
  cin>>s;
  int n=s.size();
  if(s[n-1]=='s')
  s.append("es");
  else
  s.append("s");
  cout<<s;
    return 0;
}

Measured memory_bytes: 3596
<?php
list($r, $c) = explode(" ", trim(fgets(STDIN)));
for ($i = 0; $i < $r; $i++) {
	$row[$i] = explode(" ", trim(fgets(STDIN)));
	echo implode(" ", $row[$i]);
	echo " ".array_sum($row[$i])."\n";
	if ($i == $r-1) {
		$all_sum = 0;
		for ($j = 0; $j < $c; $j++) {
			$column_sum = 0;
			for ($k = 0; $k < $r; $k++) {
				$column_sum += $row[$k][$j];
				$all_sum += $row[$k][$j];
			}
			echo $column_sum." ";
			if ($j == $c-1) echo $all_sum."\n";
		}	
	}
}

Measured memory_bytes: 16992
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h> 
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  ll ans=0;
  ll x=tx-sx,y=ty-sy;
  rep(i,y)cout << 'U';
  rep(i,x+1)cout << 'R';
  rep(i,y+1)cout << 'D';
  rep(i,x+1)cout << 'L';
  cout << 'U';
  cout << 'L';
  rep(i,y+1)cout << 'U';
  rep(i,x+1)cout << 'R';
  rep(i,y+1)cout << 'D';
  rep(i,x)cout << 'L';
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const int INF = 1001001001;
int main(){
  int n,m,x;
  int ans= INF;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m));
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  //bit全探索　2^12 = 4096通りなので余裕で間に合う
  rep(s,1<<n){     // n=12とすると  1<<n = （最小だと）{1 0 0 0 0 0 0 0 0 0 0 0 0 } 　rep(s,1<<12)は12冊の本を買う部分集合を全列挙する(?)
    int cost=0;
    bool hantei=true;
    vector<int> understand(m);
    rep(i,n){
      if(s>>i&1){        // s={0 1 0 1 0 1 0 1 0 1 0 1},i=2とするとシフトした後は　S = {0 0 0 1 0 1 0 1 0 1 0 1}　これと{0 0 0 0 0 0 0 0 0 0 0 1}のand比較,つまりi番目が0か1か判別できる
      cost += c[i];
      rep(j,m){
        understand[j] += a[i][j];
      }
    }
  }
    rep(i,m){
      if(understand[i] < x) hantei=false;
    }
    if(hantei) ans = min(ans,cost);
  }
  if(ans != INF) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
    int N, K, i;
    scanf("%d %d",&N, &K);
    long A[N];
    for(i=0; i<N; i++) {
        scanf("%ld", &A[i]);
    }

    for(i=0; i<(N-K); i++) {
        if(A[i] < A[i+K]) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int main(void) {
    int n, cnt, ans, i;
    scanf("%d", &n);
    int h[n];
    cnt = 0; ans = 0;

    for (i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }

    for (i = 0; i < n - 1; i++) {
        if (h[i] >= h[i+1]) {
            cnt++;
            if (ans < cnt) ans = cnt;
        } else {
            cnt = 0;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long C, std::vector<long long> x, std::vector<long long> v){
    vector<pair<LL, int> > rightCost, leftCost;

    LL temp = 0;
    REP(i, N) {
        temp += v[i];
        if(temp - x[i] * 2 <= 0) continue;
        leftCost.PB(MP(temp - x[i] * 2, i));
    }
    
    temp = 0;
    RREP(i, N-1) {
        temp += v[i];
        if(temp - (C - x[i]) * 2 <= 0) continue;
        rightCost.PB(MP(temp - (C - x[i]) * 2, i));
    }

    sort(ALL(leftCost), greater<pair<LL, int> >());
    sort(ALL(rightCost), greater<pair<LL, int> >());

    LL ans = 0;
    int nextIdx = 0;
    temp = 0;
    REP(i, N) {
        temp += v[i];
        LL nowCost = temp - x[i];
        
        REP2(j, nextIdx, rightCost.size()) {
            if(rightCost[j].second <= i) {
                nextIdx++;
                continue;
            }

            nowCost += rightCost[j].first;
            break;
        }

        ans = max(ans, nowCost);
    }

    nextIdx = 0;
    temp = 0;
    RREP(i, N-1) {
        temp += v[i];
        LL nowCost = temp - (C - x[i]);
        
        REP2(j, nextIdx, leftCost.size()) {
            if(i <= leftCost[j].second) {
                nextIdx++;
                continue;
            }

            nowCost += leftCost[j].first;
            break;
        }

        ans = max(ans, nowCost);
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long C;
    scanf("%lld",&C);
    std::vector<long long> x(N);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, C, std::move(x), std::move(v));
    return 0;
}


Measured memory_bytes: 6384
#include <stdio.h>

int main(){
  long n,q,a,b,c,num[100001]={0};
  long i,j,result=0,all=0;
  
  //input n&a
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a);
    num[a]++;
  }
  
  //pre calc all
  for(i=1;i<=100000;i++){
    all+=(i*num[i]);
  }
  
  //q round start
  scanf("%ld",&q);
  
  result=all;
  for(i=0;i<q;i++){
    scanf("%ld %ld",&b,&c);
    
    result-=b*num[b];
    result+=c*num[b];
    
    num[c]+=num[b];
    num[b]=0;
    
    //print out
    printf("%ld\n",result);
  }
  
}

Measured memory_bytes: 2488