akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define upper_index(v,a) (int)distance(v.begin(), upper_bound((v).begin(),(v).end(),a))
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 400005;
long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod=MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a,ll m=MOD) {
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b;
        swap(a,b);
        u-=t*v;
        swap(u,v);
    }
    u%=m;
    if(u<0) u+=m;
    return u;
}

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (ll i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i] =MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll COM(ll n, ll k){
    if (n<k)
        return 0;
    if (n<0 || k<0)
        return 0;
    return fac[n]*(finv[k]*finv[n - k]%MOD)%MOD;
}
int main(){ 
    COMinit();
    ll N;cin >> N;
    vector<ll> c(N); rep(i,N) cin >> c[i];
    sort(c.begin(),c.end());
    ll ans = 0;
    rep(i,N){
        ans += ((modpow(2,i)*c[i]) % MOD)*((modpow(2,N-1-i)+(N-1-i)*modpow(2,N-2-i) % MOD));
        ans %= MOD;
    }
    ans = ans * modpow(2,N);
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 11136
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    string S;
    cin>>S;
    ll N=S.length();
    FORI(i,0,N)
    {
        cout<<'x';
    }
    cout<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
typedef long long int64;
static const int MAXN = 2e5 + 4;

int n;
int a[MAXN];
int64 s[MAXN];

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

    int64 ans = 1LL << 61;
    for (int i = 1; i < n; ++i) ans = std::min(ans, std::abs(s[n] - s[i] * 2));
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
using namespace std;
int a[85];
int main(){
	int n,i;
	long long ans=1000,gp=0;
	bool sell=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]); 
	}
	for(i=1;i<=n;i++){
		if(a[i]<a[i+1]&&sell){
			sell=0;
			gp=ans/a[i];
			ans%=a[i];
		}
		if(a[i]>a[i+1]&&!sell){
			sell=1;
			ans+=gp*a[i];
			gp=0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1732
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	char s[15];
	scanf("%s",s+1);
	if(s[1] == 'Y' && s[2] == 'A' && s[3] == 'K' && s[4] == 'I') printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
"""
for y in range(1, 32):
  for x in range(1, 32):
    ok = False
    for i in range(1, 10000):
      if i%y==0 and i/y%2!=0 and i%x==0 and i/x%2!=0:
        ok = True
        break
    print "#" if ok else ".",
  print
"""

"""
x = 1
for i in range(32):
  print x
  x = x*2+1
"""

from fractions import *

def check(x, y, d):
  #print x, y, d
  if x==y==d+1:
    return True
  if x==d+1 or y==d+1:
    return False
  return check(x%(d+1), y%(d+1), d/2)

N, M = map(int, raw_input().split())
a = [int(t)/2 for t in  raw_input().split()]

g = a[0]
for i in range(1, N):
  if not check(g, a[i], 1073741823):
    print 0
    exit(0)
  g = g*a[i]/gcd(g, a[i])
  if g>M:
    print 0
    exit(0)
print (M+g)/(2*g)

"""
 2: 1  3  5  7  9 11 13 15 17
 4: 2  6 10 14 18 22 26 30 34
 6: 3  9 15 21 27 33
 8: 4 12 20 28 36 44
10: 5 15 25 35 45 
12: 6 18 

  1 2 3 4 5 6
1 o x o x o x
2 x o x x x o
3 o x o x o 
4 x x x o
5 o x o
6 x o
"""


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
void print_line(vector<ll> &line) {
    for (int i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

int main() {
    set<P> trump;

    int n;
    cin >> n;
    rep(i, n) {
        char suit;
        int rank;
        cin >> suit >> rank;
        trump.insert(P(suit, rank));
    }

    char suits[4] = {'S', 'H', 'C', 'D'};
    for (int i = 0; i < 4; i++) {
        char suit = suits[i];
        for (int j = 1; j <= 13; j++) {
            if (trump.find(P(suit, j)) == trump.end()) {
                printf("%c %d\n", suit, j);
            }
        }
    }

}


Measured memory_bytes: 3212
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  int ans = 0;
  for(int j = 1; j <= N; j+=2){
    int tmp = j;
    vector<int> div;
    for(int i = 2 ; i*i <= tmp; i++){
      if(tmp %i == 0){
        int cnt = 0;
        while(tmp%i == 0){
          cnt++;
          tmp/=i;
        }
        div.push_back(cnt);
      }
    }
    if(tmp!=1)div.push_back(1);
    int cntDiv = 1;
    for(int k : div){
      cntDiv *= (k+1);
    }
    if(cntDiv == 8) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
	int a,b;
	int area=0,c_length=0;
	scanf("%d %d",&a,&b);

	area=a*b;
	c_length=a*2+b*2;

	printf("%d %d\n",area,c_length);

	return 0;
}

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

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

  int counter = 0;

  for(int i = 0; i <= a; ++i){
    for(int j = 0; j <= b; ++j){
      for(int k = 0; k <= c; ++k){
        int total = 500 * i + 100 * j + 50 * k;
        if(total == num) ++counter;
        else continue;
      }
    }
  }

  cout << counter << endl;

  return 0;
  
}


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

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  for(int i=0; i<N; i++){
    cout << S.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define INF 100000000000000
using namespace std;

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

    printf("%d %d %.8lf\n", a/b, a%b, (double)a/b);
    return 0;
}




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

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n,a,b,c,an,bn;
ll fac[MAXn],inv[MAXn];
ll fpow(ll x,ll y){
    ll ret = 1;
    while (y) {
        if (y&1) ret = (ret*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return ret;
}
void init(){
    fac[0] = inv[0] = 1;
    REP1 (i,MAXn-1) fac[i] = (fac[i-1] * i) % MOD;
    REP1 (i,MAXn-1) inv[i] = fpow(fac[i],MOD-2);
    an = fpow(a,n);
    bn = fpow(b,n);
}
void mul(ll &x,ll y){
    x = (x*y)%MOD;
}
ll C(ll x,ll y){
    return fac[x] * inv[y] % MOD * inv[x-y] % MOD;
}
ll cal(ll x){
    ll ret = x;
    mul(ret,C(x-1,n-1));
    ll tmp = fpow(a+b,x);
    tmp = fpow(tmp,MOD-2);
    debug(tmp);
    mul(ret,tmp);
    debug(an,bn);
    tmp = ((an*fpow(b,x-n)%MOD) + (bn*fpow(a,x-n)%MOD))%MOD;
    mul(ret,tmp);
    debug(ret);
    return ret;
}
int main(){
    IOS();
    cin >> n >> a >> b >> c;
    init();
    ll ans = 0;
    for (ll i=n;i<=2*n-1;i++) ans = (ans + cal(i))%MOD;
    ans = ans * 100 % MOD;
    cout << ans * fpow(100-c,MOD-2) % MOD << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;
int main(){
    long int N, M;
    cin >> N >> M;\

    vector<pair<long int, long int>> P(N);

    for(int i = 0; i < N; i++){
        long int A, B;
        cin >> A >> B;
        P[i].first = A;
        P[i].second = B;
    }
     sort(P.begin(), P.end());

     long int money = 0;
     long int count = 0;
     for(int i = 0; i < N; i++){
         money += P[i].first * P[i].second;
         count += P[i].second;
         if(count >= M){
             money -= P[i].first * (count - M);
             break;
         }
     }
     cout << money;

}



Measured memory_bytes: 1792
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())

#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}c(200005);

int main(){
  int n,m,k;
  cin >> n>> m>> k;
  mint ans = 0;
  mint col = m;
  for (int x = n-1; x >= 0; --x) {
    mint now = col;
    now *= c(n-1,x);
    if (x <= k) ans += now;
    col *= m-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6244
#include <iostream>

using namespace std;

int main(){
    int a, b;
    while(cin >> a >> b){
        int c[] = {0, 300000, 200000, 100000};
        int res = 0;
        if(a <= 3) res += c[a];
        if(b <= 3) res += c[b];
        if(a+b == 2) res += 400000;
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int a[100];
	int b[100];
	int i, j;
	int min = 100;
	int max = -100;
	int kekka;
	int ans = 0;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (a[i] > max){
			max = a[i];
		}
		if (a[i] < min){
			min = a[i];
		}
	}
	
	for (j = 0; j < n; j++){
		b[j] = (min - a[j]) * (min - a[j]);
		ans += b[j];
	}
	
	for (i = min + 1; i <= max; i++){
		for (j = 0; j < n; j++){
			b[j] = (i - a[j]) * (i - a[j]);
			kekka += b[j];
		}
		if (kekka < ans){
			ans = kekka;
		}
		kekka = 0;
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 128
import bisect

n = int(input())
L = list(map(int,input().split()))
L = sorted(L)
ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        limit = L[i]+L[j]
        ans += bisect.bisect_left(L,limit) - (j+1)

print(ans)


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

using namespace std;


void energy_drink_collector()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> ab(n);
  for (int i = 0; i < n; ++i) cin >> ab[i].first >> ab[i].second;

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

  long long int total_fee = 0;
  for (int i = 0; i < n && m > 0; ++i)
  {
    total_fee += (long long int)ab[i].first * (long long int)min(m, ab[i].second);
    m -= min(m, ab[i].second);
  }

  cout << total_fee << "\n";
}


int main()
{
  energy_drink_collector();
}


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

using namespace std;

int a[105], tot[105];

int main(){
	int n; scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		tot[i] = tot[i-1] + a[i];
	}
	int mini = 1e9;
	for(int i=1; i<=n; i++){
		int tt1 = tot[i];
		int tt2 = tot[n] - tt1;
		mini = min(mini, abs(tt1 - tt2));
	}
	printf("%d\n",mini);
	return 0;
}

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

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

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

    vector<int> B(n + 1);
    for(int i = 0; i < n; i++){
        B[i + 1] += B[i] + A[i];
    }

    int ans = 1e9;
    for(int i = 1; i <= n; i++){
        int x = B[i] - B[0];
        int y = B[n] - B[i];
        ans = min(ans, abs(x - y));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        String s = sc.next();

        // 処理
        String out = "No";

        int n = s.length();

        //sは回文か
        if(isKaibun(s)) {
            //sは強い回文か
            if(
                isKaibun(s.substring(0, (n - 1)/2)) &&
                isKaibun(s.substring((n + 3)/2 - 1, n))
            ) {
                out = "Yes";
            }
        }

        // 出力
        System.out.println(out);
    }

    // 0 1 2 4
    public static boolean isKaibun(String s){
        int len = s.length();
        for (int i = 0; i <= (len - 1) / 2; i++){
            if (s.charAt(i) != s.charAt(len - i - 1)) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 22996
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

struct unionfind{
  vector<int> par;
  unionfind(int n):par(n,-1){}
  void init(int n){par.assign(n,-1);}
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(par[x]>par[y]) swap(x,y);
    par[x]+=par[y];
    par[y]=x;
    return true;
  }
  int size(int x){
    return -par[root(x)];
  }
};

int main(){
  ll n,m;
  cin >> n >> m;
  unionfind uf(n);
  vector<int> a(m);
  vector<int> b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  vector<ll> ans(m);
  ans[m-1]=n*(n-1)/2;
  for(int i=m-1;i>=1;i--){
    int mns;
    if(uf.issame(a[i],b[i])) mns=0;
    else mns=uf.size(a[i])*uf.size(b[i]);
    uf.merge(a[i],b[i]);
    ans[i-1]=ans[i]-mns;
  }
  rep(i,m){
    cout << ans[i] << endl;
  }
}

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

using namespace std;

const int INF=1e9+10;


int main()
{
    int V,E;
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin>>V>>E)
    {
        vector<vector<int> > mat(20,vector<int>(20));
        vector<vector<int> > dp(1<<V,vector<int>(V));
        for(int i=0;i<mat.size();i++)
        {
            fill(mat[i].begin(),mat[i].end(),INF);
        }
        for(int i=0;i<E;i++)
        {
            int s,t,d;
            cin>>s>>t>>d;
            mat[s][t]=d;

        }
        for(int i=0;i<dp.size();i++)
        {
            fill(dp[i].begin(),dp[i].end(),INF);
        }
        dp[0][0]=0;
        for(int i=0;i<(1<<V);i++)
        {
            for(int j=0;j<V;j++)
            {
                for(int k=0;k<V;k++)
                {
                    if(!(i>>k&1))
                    {
                        dp[i^(1<<k)][k]=min(dp[i][j]+mat[j][k],dp[i^(1<<k)][k]);
                    }
                }
            }
        }
        cout<<(dp[(1<<V)-1][0]==INF?-1:dp[(1<<V)-1][0])<<endl;
    }

    return 0;
}



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

int N, K;
vector<int> A;
vector<bool> dp;

int main(void) {
	cin >> N >> K;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	dp.resize(K + 1, false);
	for (int i = 1; i <= K; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i >= A[j]) {
				if (dp[i - A[j]] == false)
					dp[i] = true;
			}
		}
	}

	bool ans = dp[K];
	cout << (ans ? "First" : "Second") << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
string s;
vector<string> vs;
int table[] = { 5, 7, 5, 7, 7 };

int main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> s;
			vs.push_back(s);
		}
		REP(i, vs.size()){
			string s;
			int pos = i, co = 0;
			bool f = 1;
			while (f){
				s += vs[pos];
				if (s.size() == table[co]){
					co++;
					s.clear();
				}
				else if (s.size() > table[co]){
					co = 0;
					f = 0;
					s.clear();
				}
				if (co == 5){
					cout << i + 1 << endl;
					break;
				}
				if (pos == vs.size() - 1)f = 0;
				pos++;
			}
			if (f)break;
		}
		vs.clear();
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll x,y,z,k;
vl a;
vl b;
vl c;
priority_queue<vl> pq;
set<vl> visit;

int main(){
  cin >> x >> y >> z >> k;
  a = vl(x); b = vl(y); c = vl(z);
  for(ll i = 0;i < x;i++) cin >> a[i];
  for(ll i = 0;i < y;i++) cin >> b[i];
  for(ll i = 0;i < z;i++) cin >> c[i];
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  sort(c.rbegin(),c.rend());
  pq.push(vl({a[0]+b[0]+c[0],0 ,0, 0}));
  for(ll s = 0;s < k;s++){
    ll cost = pq.top()[0];
    ll i = pq.top()[1];
    ll j = pq.top()[2];
    ll k = pq.top()[3];
    // cerr << i << " " << j << " " << k << endl;
    pq.pop();
    if(visit.count(vl({i,j,k}))){
      s--;
      continue;
    }
    visit.insert(vl({i,j,k}));
    cout << cost << endl;
    if(i+1 < a.size()) pq.push(vl({a[i+1]+b[j]+c[k], i+1, j, k}));
    if(j+1 < b.size()) pq.push(vl({a[i]+b[j+1]+c[k], i, j+1, k}));
    if(k+1 < c.size()) pq.push(vl({a[i]+b[j]+c[k+1], i, j, k+1}));

  }



}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N,sum=0;
    cin>>N;
    vector <int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
        
    }
    sort(a.begin(),a.end());
    
    for(int i=0;i<N-1;i++){
        sum+=a[i+1]-a[i];
        
    }
    cout <<sum <<"\n";
    
    
    return 0;

}

Measured memory_bytes: 256
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)			for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

// #include "functions.h"

void om_shree_ganeshaya_namah(){
    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
}

int32_t main() {

    om_shree_ganeshaya_namah();

    in(n); in(k);
    vint arr(n);
    f(n) cin>>arr[i];
    sort(arr.begin(), arr.end());

    vint dp(k+1);

    for(int i=0; i<n; i++){
    	for(int j=arr[i]; j<=k; j++){
    		int ans=1;
    		for(int k=i; k>=0; k--){
    			ans&=dp[j-arr[k]];
    		}
    		dp[j] = !ans;
    	}
    }

    string ans = "Second";
    if(dp[k])
    	ans = "First";
    cout<<ans<<endl;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,h,a;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> h;
        if (a > h) {
            cout << "No" << endl;
            return 0;
        }
        a = max(a,h-1);
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll MOD = 1e9 + 7;

// ll C[2005][2005];
// ll dp[100005][13];

ll tousa(ll a, ll l, ll n) {
    return n*(a+l)/2;
}

int main(){
    ll ans=0;
    ll m,M;
    ll N,K;
    cin >> N >> K;
    for(int k=K; k<=N+1;k++){
        m = tousa(0,k-1,k);
        M = tousa(N-k+1,N,k);
        ans = (ans+M-m+1)%MOD;
    }
    cout << ans << endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if (s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){

	

    FAST
//	PRECISE

ll sats=0;
ll d;
cin>>d;
ve <ll> c(26);
FOR(i,0,26)
cin>>c[i];
ve <ve <ll>> v(d,ve <ll> (26));
FOR(i,0,d)
	FOR(j,0,26)
		cin>>v[i][j];
ve <ll> last(26);
FOR(i,0,d){
	ve <ll> tell(26);
	FOR(j,0,26){
		tell[j]=v[i][j]+c[j]*(i-last[j]);
		sats-=c[j]*(i-last[j]);
	}
	ll take=0;
	ll mi=tell[0];
	FOR(i,0,26){
		if(tell[i]>mi){
			take=i;mi=tell[i];
		}
	}
	cout<<take+1<<"\n";
	sats+=v[i][take];
	last[take]=i;
}
//cout<<sats;

return 0;
 }

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int a,b; cin>>a>>b;
  if((a+b)%3==0 || a%3==0 || b%3==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;

  return 0;
}
   
 
      
 
  
   
  
	
	  
	  
	  
	  
	  
	  
     
  
  
  
  
  

  

 
  


 

    
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int H, N;
  cin >> H >> N;
  int A[1003];
  int B[1003];
  int str = 0;
  for (int i = 0; i < N; i ++) {
    cin >> A[i] >> B[i];
    if (str < A[i]) str = A[i];
  }
  int hp[1000000];
  for (int i = 0; i <= H + str; i ++) hp[i] = 1e9;
  hp[0] = 0;
  for (int i = 0; i < H; i ++) {
    for (int j = 0; j < N; j ++) {
      if (hp[i + A[j]] > hp[i] + B[j]) {
        hp[i + A[j]] = hp[i] + B[j];
      }
    }
  }
  int ans = 1e9;
  for (int i = H; i <= H + str; i ++) {
    if (ans > hp[i]) ans = hp[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define SMAX 100000
#define PMAX 1000000
int minfactor[SMAX], pfactor[PMAX], pcount[PMAX];
void small_sieve(int l, int r);
void factorization(int n, int l, int r);
int main(void)
{
  int i, l, r, ans = 0;
  scanf("%d %d", &l, &r);
  small_sieve(l, r);
  minfactor[0] = minfactor[1] = -1;
  for (i = l; i <= r; i++) {
    factorization(i, l, r);
    if (minfactor[pcount[i-l]] == pcount[i-l]) ans++;
  }
  printf("%d\n", ans);
}

void small_sieve(int l, int r)
{
  int i, j;
  for (i = 0; i * i <= r; i++) minfactor[i] = i;
  for (i = l; i <= r; i++) pfactor[i-l] = 1;
  for (i = 2; i * i <= r; i++) {
    if (minfactor[i] == i) {
      for (j = i * i; (long long)j * j <= r; j += i) {
        if (minfactor[j] == j) minfactor[j] = i;
      }
      for (j = (l + i - 1) / i * i; j <= r; j += i) {
        int jtemp = j;
        while (jtemp % i == 0) {
          pcount[j-l]++;
          pfactor[j-l] *= i;
          jtemp /= i;
        }
      }
    }
  }
}

void factorization(int n, int l, int r)
{
  int ntemp = n;
  ntemp /= pfactor[n-l];
  if (ntemp > 1) {
    pcount[n-l]++;
    return;
  }
}


Measured memory_bytes: 9732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int h,w,i,j,k;
	ll a,b,c,ans=INFLL;
	cin >> h >> w;
	for(k=0; k<2; ++k){
		for(i=1; i<h; ++i){
			a = 1ll*i*(w/2);
			b = 1ll*i*(w-(w/2));
			c = 1ll*(h-i)*w;
			ans = min(ans,max({a,b,c})-min({a,b,c}));
			a = 1ll*(i/2)*w;
			b = 1ll*(i-i/2)*w;
			c = 1ll*(h-i)*w;
			ans = min(ans,max({a,b,c})-min({a,b,c}));
		}
		swap(h,w);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a = 0, b = 0, c = 0, d = 0;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  if( abs(c-a)<=d || abs(a-b)<=d && abs(b-c)<=d){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

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

    string S;
    std::cin >> S;

    for(int i=0;i<S.size();++i){
        if(i == 3){
            std::cout << '8';
        }else{
            std::cout << S[i];
        }
    }
    cout << endl;
}


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

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

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

	ll n,x=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		ll a;
		cin>>a;
		x=x^a;
	}
	if(!x)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;


	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ld n , d;
vector<vector<ld>> x;

ld dis(int a, int b){
    ld ret = 0.0;
    for(int i=0;i<d;i++){
        ret += (x.at(a).at(i) - x.at(b).at(i)) *  (x.at(a).at(i) - x.at(b).at(i));
    }
    return ret;
}

int main(){
    cin >> n >> d;
    x.resize(n,vector<ld>(d));
    rep(i,n) rep(j,d) cin >> x.at(i).at(j);

    ll ans = 0;

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(sqrt(dis(i,j)) == (int)(sqrt(dis(i,j)))) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
const int INF=1e9+7;
const double PI=3.141592653589793238462643383279;
//
int cnt=0;
int ans=0;
int main(){
  int N,M;
  set<int> S[8];
  cin>>N>>M;
  FOR(i,0,M){
    int A,B;
    cin>>A>>B;
    A--;
    B--;
    S[A].insert(B);
    S[B].insert(A);
  }
  VE V;
  FOR(i,1,N){
    V.PB(i);
  }
  cnt=1;
  if(S[0].find(V[0])!=S[0].end()){
    FOR(i,0,N-2){
      if(S[V[i]].find(V[i+1])!=S[V[i]].end()){
        cnt++;
      }else{
        break;
      }
    }
    if(cnt==N-1){
      ans++;
    }
  }
  while(next_permutation(V.begin(),V.end())){
    cnt=1;
    if(S[0].find(V[0])!=S[0].end()){
      FOR(i,0,N-2){
        if(S[V[i]].find(V[i+1])!=S[V[i]].end()){
          cnt++;
        }else{
          break;
        }
      }
      if(cnt==N-1){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M,K;
char s[310][310];
int A[310][310];

signed main(){
	cin>>N>>M>>K;
	REP(i,N){
		cin>>s[i];
	}
	int cnt=1;
	REP(i,N){
		REP(j,M){
			if(s[i][j]=='#'){
				A[i][j]=cnt;
				cnt++;
			}
		}
	}
	REP(i,N){
		REP(j,M-1){
			if(A[i][j+1]==0){
				A[i][j+1]=A[i][j];
			}
		}
		for(int j=M-1;1<=j;j--){
			if(A[i][j-1]==0){
				A[i][j-1]=A[i][j];
			}
		}
	}
	REP(i,M){
		REP(j,N-1){
			if(A[j+1][i]==0){
				A[j+1][i]=A[j][i];
			}
		}
		for(int j=N-1;1<=j;j--){
			if(A[j-1][i]==0){
				A[j-1][i]=A[j][i];
			}
		}
	}
	REP(i,N){
		REP(j,M){
			cout<<A[i][j];
			if(j<M-1){
				cout<<" ";
			}
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
long long a[10010];
int main()
{
	int n;
	cin>>n;
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		long long tem=0;
		while(a[i]>0)
		{
			if(a[i]%2==0)
			{
				a[i]/=2;
			   tem++;
			}
			else break;
		}
		ans+=tem;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int s;
  sc.scan(s);

  int[] a = new int[10000];


  a[0] = s;
  int i = 1;
  while (1) {
    if (a[i - 1] % 2 == 0) {
      a[i] = a[i - 1] / 2;
    } else {
      a[i] = (3 * a[i - 1]) + 1;
    }

    foreach_reverse (j; 0 .. i) {
      if (a[i] == a[j]) {
        writeln(i + 1);
        return;
      }
    }
    i++;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    int n, m;
  
    cin>>n>>m;
    if(n == 0 && m == 0) break;
    vector<int> A(n);
    cin>>A;
  
    int ans = -1;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	if(A[i] + A[j] <= m) ans = max(ans, A[i] + A[j]);
      }

    if(ans == -1) cout<<"NONE"<<endl;
    else cout<<ans<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3168
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    S = input()
    if len(S) == 3:
        S = S[::-1]
    print(S)


def main():
    solve()


if __name__ == '__main__':
    main()


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string S[6];
    for(int i=0; i<H; i++) cin >> S[i];

    int ans = 0;
    for(int a=0; a<(1<<H); a++) for(int b=0; b<(1<<W); b++){
        int cnt = 0;
        for(int i=0; i<H; i++) for(int j=0; j<W; j++) if(nth_bit(a, i) && nth_bit(b, j) && S[i][j] == '#') cnt++;
        if(cnt == K) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624