akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    string s;
    cin >> s;
    s[K-1] ^= 32;
    cout << s << endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

typedef unsigned long long ull;
const ull p=1000000007;

signed main(){
    int N,M;
    cin>>N>>M;
    string S;cin>>S;
    static ull power[333333],h[333333];
    power[0]=1;
    for(int i=0;i<S.size();i++){
        power[i+1]=power[i]*p;
        h[i+1]=h[i]*p+S[i];
    }

    int l=0,r=1;
    set<ull>hs;
    rep(i,M){
        string q;
        cin>>q;
        if(q=="L++")l++;
        else if(q=="L--")l--;
        else if(q=="R++")r++;
        else r--;
        hs.insert(h[r]-h[l]*power[r-l]);
    }
    cout<<hs.size()<<endl;
    return 0;
}

Measured memory_bytes: 21956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	int dp[n];
	dp[0]=0;
	dp[1] = abs(arr[1]-arr[0]);
	if(n<3){
	cout<< dp[n-1];
	return 0;
	}
	for(int i=2;i<n;i++)
	{
		int x = abs(arr[i]-arr[i-2]);

		int y = abs(arr[i]-arr[i-1]);
		//cout<<x<<" "<<y<<endl;
		dp[i] = min(dp[i-2]+x,dp[i-1]+y);
	}
	/*for(int i=0;i<n;i++)
	cout<<dp[i]<<" ";*/
	cout<<dp[n-1];
	return 0;
}

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

int main()
{
	string b;
	cin >> b;
	if(b== "A")
	{
		cout << "T"<< endl;
	}
	else if(b=="T")
	{
		cout << "A"<< endl;
	}
	else if(b=="C")
	{
		cout << "G"<< endl;
	}
	else if(b=="G")
	{
		cout << "C"<< endl;
	}
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    rr = []
    for _ in range(n):
        a,b = LI()
        t = a*b
        s = int(t ** 0.5)
        if t < 3:
            rr.append(0)
        elif a == b:
            if (a-1) * (b+1) < t:
                rr.append((a-1)*2)
            else:
                rr.append((a-1)*2-1)
        elif s*s == t:
            rr.append((s-1)*2-1)
        elif s*(s+1) < t:
            rr.append(s*2-1)
        else:
            rr.append((s-1)*2)


    return '\n'.join(map(str, rr))


print(main())




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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,b,n) for(int i=b;i<(n);++i)
#define each(e,v) for(auto &&e : v)

#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const double EPS = 1e-9;
const ll MOD = 1e+9 + 7;

template<typename A,typename B> inline void chmin(A &a,B b){ if(a>b) a=b; }
template<typename A,typename B> inline void chmax(A &a,B b){ if(a<b) a=b; }
template <typename T> inline void print(const T& x) { cout << x << endl; }

vector<int> dp;

int mod_popcount(int x){
    if(x==0) return 0;
    int count = 0;
    for(int i=0; i<32; ++i){
        if((x&(1<<i))!=0) ++count;
    }
    return x % count;
}

int main() {
    int n;
    string x;
    cin >> n >> x;

    int count = 0;
    for(int i=0; i<n; ++i){
        if(x[i]=='1') ++count;
    }

    dp = vector<int>(count+2,-1);
    dp[0] = 0;
    for(int i=0; i<=count+1; ++i){
        dp[i] = 1 + dp[mod_popcount(i)];
    }

    vector<int> vp0(n,0);
    vector<int> vp1(n,0);

    int x0 = 0;
    int x1 = 0;
    int p0 = 1;
    int p1 = 1;
    for(int i=x.size()-1; i>=0; --i){
        if(x[i]=='1'){
            x0 = count>1 ? (x0 + p0)%(count-1) : 0;
            x1 = (x1 + p1)%(count+1);
        }
        vp0[i] = p0;
        vp1[i] = p1;
        p0 = count>1 ? (p0*2)%(count-1) : 0;
        p1 = (p1*2)%(count+1);
    }

    for(int i=0; i<n; ++i){
        if(x[i] == '1'){
            if(count<=1){
                print(0);
                continue;
            }
            int a = (x0 + (count-1-vp0[i]))%(count-1);
            print(dp[a]);
        }else{
            int a = (x1 + vp1[i])%(count+1);
            print(dp[a]);
        }
    }

    return 0;
}


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

int main (void){
	int n,i,ans=0;
	char a[105],b[105],c[105];
	cin >> n >> a >> b >> c;
	for(i=0;i<n;i++){
		if(a[i]==b[i]&&b[i]==c[i]){
		} else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]) {
			ans+=2;
		} else {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
while(1):
    m,f,r = [int(i) for i in input().split()]
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print("F")
    else:
        t = m+f
        if t >= 80:
            print("A")
        elif 65 <= t < 80:
            print("B")
        elif 50 <= t < 65:
            print("C")
        elif 30 <= t < 50:
            if r >= 50:
                print("C")
            else:
                print("D")
        else:
            print("F")
        


Measured memory_bytes: 5604
n=int(input())

def factorization(n):
    global a
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

soinsu = factorization(n)
a = len(soinsu)
#print(soinsu)
#print(a)
ans = 0

for i in range(a):
    x = soinsu[i][1]
    for j in range(1,10**18):
        if x >= j:
            x = x-j
            ans += 1
        else:
            break

if n== 1:
    ans = 0


print (ans)



Measured memory_bytes: 9512
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>
#include <functional>

typedef long long lint;

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
lint* array(lint x) {
	lint *array = new lint[x];
	return array;
};
 lint** array2(lint x, lint y) {
	lint **array = new lint*[x];
	rep(i, x)array[i] = new lint[y];
	return array;
}
int main() {
	int f, m, r;
	char value;
	while (true) {
		cin >> f >> m >> r;
		if (f == -1 && m == -1 && r == -1)break;
		if (f == -1 || m == -1)value = 'F';
		else if (f + m >= 80)value = 'A';
		else if (f + m >= 65)value = 'B';
		else if (f + m >= 50)value = 'C';
		else if (f + m >= 30) {
			if (r >= 50)value = 'C';
			else value = 'D';
		}
		else value = 'F';
		cout << value << "\n";
	}
}


Measured memory_bytes: 3024
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll i,n,w;
ll a[N];
bool p;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,1,n + 1) cin>>a[i];
    p = 1;
    w = a[1];
    rep(i,2,n + 1){
        if(a[i] < w){
            p = 0;
            break;
        }
        w = max(w, a[i] - 1);
    }
    if(!p){
        p = 1;
        w = a[n];
        revrep(i,n - 1,1){
            if(a[i] - 1 > w){
                p = 0;
                break;
            }
            w = min(w, a[i]);
        }
        if(!p){
            p = 1;
            w = a[1] - 1;
            rep(i,2,n + 1){
                if(a[i] < w){
                    p = 0;
                    break;
                }
                w = max(w, a[i] - 1);
            }
            if(!p){
                w = a[n] - 1;
                p = 1;
                revrep(i,n - 1,1){
                    if(a[i] - 1 > w){
                        p = 0;
                        break;
                    }
                    w = min(w, a[i]);
                }
            }
        }
    }
    cout<<(p ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<tuple>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  sort(A.begin(), A.end());
  
  vector<tuple<int, int>> CB(M);
  for(int i=0;i<M;i++){
    cin >> get<1>(CB[i]) >> get<0>(CB[i]);
  }
  
  sort(CB.rbegin(), CB.rend());
  
  int now_j = 0;
  int now_remain = get<1>(CB[now_j]);
  for(int i=0;i<N;i++){
    if(A[i] > get<0>(CB[now_j])) break;
    A[i] = get<0>(CB[now_j]);
    now_remain--;
    if(now_remain <= 0){
      if(now_j >= M-1) break;
      now_j++;
      now_remain = get<1>(CB[now_j]);
    }
  }
  
  cout << accumulate(A.begin(), A.end(), (long long int)0) << "\n";
    
}


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

int main() {
	ios::sync_with_stdio(0),cin.tie(0);
	int a,b,c=0;
	cin>>a>>b;
	if(a>b)
		c=a*2-1;
	if(b>a)
		c=b*2-1;
	if(a==b)
		c=a+b;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 200010
#define MOD 1000000007
#define rep(i, x, y) for(int i = (x); i <= (y); i ++)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	} while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	} return x * f;
}
int fac[M], inv[M];
inline void init() {
	fac[0] = 1; rep(i, 1, 200000) fac[i] = 1ll * i * fac[i - 1] % MOD;
	inv[0] = inv[1] = 1;
	rep(i, 2, 200000) inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;
	rep(i, 2, 200000) inv[i] = 1ll * inv[i - 1] * inv[i] % MOD;
}
inline int C(int n, int m) {
	int a = n + m - 2, b = n - 1;
	//printf("%d %d\n", a, b);
	return 1ll * fac[a] * inv[b] % MOD * inv[a - b] % MOD;
}
int main() {
	int H = read(), W = read(), A = read(), B = read();
	init(); int res = 0;
	rep(i, 1, H - A) {
		//cout << res << endl;
		res += 1ll * C(i, B) * C(H - i + 1, W - B) % MOD;
		res %= MOD; //cout << res << endl;
	} cout << res;
	return 0;
}

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

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

  int c = 0;
  for(int i = a; i <= b; i++){
    int x1, x2, x4, x5;
    x1 = i / 10000;
    x2 = i % 10000 / 1000;
    x4 = i % 100 / 10;
    x5 = i % 10;
    if(x1 == x5 && x2 == x4)
      c++;
  }
  cout << c << endl;
}

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

const int INF  = 0x3f3f3f3f;
const int MAXN = 1e5+7;
int dp[MAXN];
int a[MAXN];
int main() {
        int n;
        while(cin>>n) {
                for(int i=0;i<n;++i)
                        cin>>a[i];
                int ans = 0;
                int num = 0;
                for(int i=1;i<n;++i) {
                        if(a[i]<=a[i-1])        num++;
                        else                    num = 0;
                        ans = max(ans,num);
                }
                cout<<ans<<endl;
        }
        return 0;
}




Measured memory_bytes: 640
s = input()
ans = "WA"
if s[0]=="A":
  if s[2:len(s)-1].count("C")==1:
    x = s.find("C")
    s2 = "a"+s[1:x]+"c"+s[x+1:]
    if s2==s.lower(): ans = "AC"
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;

void Students1A()
{
	int M, D;
	cin >> M >> D;
	int ct = 0;
	for (int i = 4; i <= M; ++i)
	{
		for (int j = 2; j < 10; ++j)
		{
			int d1 = j;
			int d2 = i / j;
			if (d1 * d2 == i && d2 < 10 && d2 > 1 && d1 * 10 + d2 <= D)
			{

				++ct;
			}
		}
	}
	cout << ct << endl;
}
int main()
{
	Students1A();
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ solve n

solve n = n^3

Measured memory_bytes: 508
#include<iostream>
#include<vector>
using namespace std;
bool flag=1;
int n;
long a[1<<17];
vector<int>G[1<<17];
long dfs(int u,int p)
{
	if(G[u].size()==1)return a[u];
	long sum=0;
	vector<long>x;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]==p)continue;
		long y=dfs(G[u][i],u);
		x.push_back(y);
		sum+=y;
	}
	long k=sum-a[u];
	long l=2*a[u]-sum;
	if(k<0||l<0)flag=0;
	long ss=0;
	for(int i=0;i<x.size();i++)
	{
		ss+=x[i]<k?x[i]:k;
	}
	if(ss<2*k)flag=0;
	return l;
}
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n-1;i++)
	{
		int x,y;cin>>x>>y;
		x--,y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	if(n==2)
	{
		cout<<(a[0]==a[1]?"YES":"NO")<<endl;
		return 0;
	}
	int root=0;
	for(int i=1;i<n;i++)
	{
		if(G[root].size()<G[i].size())
		{
			root=i;
		}
	}
	if(dfs(root,-1)!=0||!flag)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

Measured memory_bytes: 18176
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
  	double ans=1.0;
  	ans*=2;
  	ans*=3.14;
  	ans*=(n*1.0);
  	cout<<ps(ans,2)<<endl;
    return 0;
}

Measured memory_bytes: 3800
#include<cstdio>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll t[1000+5],a[1000+5];
ll n,p,q,m1,m2,k1,k2,e1,e2;
ll ans;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&t[i],&a[i]);//比例
	for(int i=1;i<=n;i++)
	{
		ll x=t[i],y=a[i];
		if(x<p||y<q)
		{
			k1=p-x,k2=q-y;
			e1=k1/x,e2=k2/y;
			if(e1*x!=k1) m1=e1+2;
			else m1=p/x;
				
			if(e2*y!=k2) m2=e2+2;
			else m2=q/y;
			x*=max(m1,m2);
			y*=max(m1,m2);
		}
		p=x;
		q=y;
		ans=x+y;
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < a.size(); i++) {
    bool rm = true;
    if (a[i][0] == '.') {
      for (int j = 1; j < a[i].size(); j++) {
        if (a[i][j] == '#') {
          rm = false;
          break;
        }
      }
      if (rm) {
        a.erase(a.begin() + i);
        i = -1;
        continue;
      }
    }
    for (int j = 0; j < a[0].size(); j++) {
      rm = true;
      if (a[0][j] == '.') {
        for (int z = 1; z < a.size(); z++) {
          if (a[z][j] == '#') {
            rm = false;
            break;
          }
        }
        if (rm) {
          for (int z = 0; z < a.size(); z++) {
            a[z].erase(j, 1);
          }
          i = -1;
          break;
        }
      }
    }
  }

  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << endl;
  }
}

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

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    a--;
    ll l = c * d / __gcd(c, d);
    ll sum1 = a - (a/c + a/d - a/l);
    ll sum2 = b - (b/c + b/d - b/l);
    ll ans = sum2 - sum1;
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 5e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll 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;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
int a[N];
int main() {
    scanf("%d",&n);
    int all = 1 << n;
    multiset<int> S;
    rep(i, 0, all) scanf("%d",a+i);
    rep(i, 0, all) S.insert(-a[i]);
    vi cur, nxt;
    cur.pb(*S.begin()); S.erase(S.begin());
    rep(i, 0, n) {
        nxt = cur;
        for(auto x:cur) {
            auto it = S.upper_bound(x);
            if(it == S.end()) return puts("No"), 0;
            nxt.pb(*it);
            S.erase(it);
        }
        cur = nxt;
    }
    puts("Yes");
    // 1 1 3 3 4 4 4 8
    return 0;
}


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

int n, k, dp[100004];
vector<int> stones;

int main() {
    cin>>n>>k;
    for(int i = 0; i < n; i++){
        int x; cin>>x; stones.push_back(x);
    }
    for(int i = 0; i <= k; i++){
        for(auto j : stones){
            if(i - j >= 0 and !dp[i-j]){
                dp[i] = 1;
            }
        }
    }
    puts(dp[k] ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void)
{
	int a[4], i, flag=0;
	char s[6];


	cin>>s;

	for(i=0; i<4; i++){
		a[i]=(int)(s[i]-'0');
	}
	if((a[0]==a[1]&&a[1]==a[2])||(a[1]==a[2]&&a[2]==a[3])){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
# /user/bin/python
# -*- coding: utf-8 -*-


N = int(input())
S = str(input())

ans = 0
for i in range(1,N):
  dct = {}
  for c in S[:i]:
    if c in S[i:]:
      if c not in dct:
        dct[c] = 1
      else:
        dct[c] += 1
  ans = max(ans, len(dct))
print(ans)  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

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

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  long long int a,b=0,aa=1,bb=3;
  cin>>a;
  if(a==1)
    cout<<1<<endl;
  else if(a==2)
    cout<<3<<endl;
  else{
    for(int i=2;i<a;i++){
      b=aa+bb;
      aa=bb;
      bb=b;
    }
    cout<<b<<endl;
  } 
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <functional>
#include <iostream>
#include <memory>
#include <set>
#include <string>
#include <vector>

using namespace std;

struct P
{
	int t;
	int x;
	int y;
};

int main() {
	int n;
	cin >> n;
	auto p = new P[n];
	for (int i = 0; i < n; i++) {
		cin >> p[i].t >> p[i].x >> p[i].y;
	}
	bool ok = true;
	auto current = P{ 0,0,0 };
	for (int i = 0; i < n; i++) {
		auto dt = p[i].t - current.t;
		auto dx = p[i].x - current.x;
		auto dy = p[i].y - current.y;
		if (dt < abs(dx) + abs(dy)) {
			ok = false;
			break;
		}
		if (dt % 2 != (abs(dx) + abs(dy)) % 2) {
			ok = false;
			break;
		}
		current = p[i];
	}
	cout << (ok ? "Yes" : "No") << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int S = 1;
  
  for (int i = 0; i < N; i++) {
    if ((2 * S) <= (S + K)) {
      S *= 2;
    }
    else {
      S += K;
    }
  }
  
  cout << S << endl;
}
  


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest


def resolve():
    h, w = map(int, input().split())
    sw = [list(input()) for _ in range(h)]

    for i in range(h):
        for j in range(w):
            np_sharp = False
            if sw[i][j] == '#':
                for add_i, add_j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_i = i + add_i
                    next_j = j + add_j

                    if next_i < 0 or next_j < 0 or h <= next_i or w <= next_j:
                        continue
                    else:
                        # 1つでも#があればOK
                        # すべて.だとNG
                        if sw[next_i][next_j] == '#':
                            np_sharp = True

                if not np_sharp:
                    print('No')
                    return
            else:
                continue

    print('Yes')



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
.#.
###
.#."""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##."""
        output = """Yes"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 5672
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    while(cin>>n){
        vi a(n);
        forn(i,n){
            int x,y; cin>>x>>y;
            a[i]=(x==y);
        }
    
        bool ok = 0;
        for(int i=0; i<n-3+1; ++i){
            ok|=(a[i]&a[i+1]&a[i+2]);
        }
        cout<<(ok ? "Yes\n" : "No\n");
    }
    return 0;
}

Measured memory_bytes: 3616
import sys
from random import randint
from datetime import datetime

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]

def randomize(n):
    return [ randint(1, 26) for _ in range(n) ]

def get_now():
    dt = datetime.now()
    return dt.second + dt.microsecond/1000000

def main():
    start = get_now()
    end = get_now()
    # 開催日数
    D = ii()
    # 満足度の下がりやすさ
    C = lmi()
    # 得られる満足度
    S = lmif(D)
    # 最後に開かれた日付
    last = [0]*26
    # 開催するコンテスト
    T = [ i%26+1 for i in range(D) ]

    def scoring():
        score = 0
        for i in range(D):
            score += S[i][T[i]-1]
            for j in range(26):
                score -= C[j] * (i - last[j])
        return score

    max_score = 0
    ans = T.copy()
    # a = 0
    while end - start < 1.95:
        idx, value = randint(0, D-1), randint(1, 26)
        old = T[idx]
        T[idx] = value
        score = scoring()
        if max_score < score:
            ans = T.copy()
            max_score = score
        else:
            T[idx] = old
        # if a % 10000 == 0:
        #     print(a, *T, score, max_score)
        # a += 1
        end = get_now()
    print(*ans, sep='\n')

main()


Measured memory_bytes: 9856
#include<bits/stdc++.h>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<ctime>
#include<cstdlib>
using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define c(n) cout << n << " ";
#define ci(n) cin >> n;
#define cn cout << "\n";
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n]; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
using namespace std;

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ic(n)
    if(n == 3)
    {
        cout << 2 << "\n" << 1 << " " << 3 << "\n" << 2 << " " << 3;
        return 0;
    }
    if(n % 2 == 0)
    {
        cout << n * (n - 2) / 2 << "\n";
        for(int i = 0; i < n; i++)
        {
            for(int j = i + 1; j < n; j++)
            {
                if(i + 1 + j + 1 != n + 1) cout << i + 1 << " " << j + 1 << "\n";
            }
        }
    }
    else
    {
        n--;
        cout << n * (n - 2) / 2 + n << "\n";
        for(int i = 0; i < n; i++)
        {
            for(int j = i + 1; j < n; j++)
            {
                if(i + 1 + j + 1 != n + 1) cout << i + 1 << " " << j + 1 << "\n";
            }
        }
        for(int i = 0; i < n; i++) cout << n + 1 << " " << i + 1 << "\n";
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	n := SingleInt()
	dp := make([]int, n+1)
	dp[0] = 0

	for i := 1; i <= n; i++ {
		dp[i] = 999999
		p := 1
		for p <= i {
			dp[i] = Min(dp[i], dp[i-p]+1)
			p *= 6
		}
		p = 1
		for p <= i {
			dp[i] = Min(dp[i], dp[i-p]+1)
			p *= 9
		}
	}

	fmt.Printf("%#v\n", dp[n])
}

func SingleInt() int {
	var n int
	fmt.Scan(&n)
	return n
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("function min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 1280
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

ansli=[]
ans=[]
for i in range(n):
  for j in range(a[i]):
    ansli.append(i+1)

for i in range(h):
  temp=ansli[0+i*w:(i+1)*w]
  if not i%2:
    ans.append(temp)
  else:
    ans.append(temp[::-1])

for i in ans:
  print(*i)

Measured memory_bytes: 3956
#include<stdio.h>

#define MAX_STR_SIZE (201)
#define MAX_DATASET_SIZE (10)

int main(void)
{
        char input_str[MAX_STR_SIZE] = { 0 };
        char work_str[MAX_STR_SIZE] = { 0 };
        char output_str[MAX_DATASET_SIZE][MAX_STR_SIZE] = { 0 };
        int shuffle_m, shuffle_h;
        int dataset_count, str_size, i;
        int input_back_start_index, output_back_start_index, output_index;

        for(dataset_count=0; dataset_count < MAX_DATASET_SIZE; dataset_count++){

                scanf("%s", input_str);

                if(input_str[0] == '-'){
                        break;
                }

                for(i=0; i < MAX_STR_SIZE; i++){
                        if(input_str[i] == '\0'){
                                str_size = i;
                                break;
                        }
                }

                scanf("%d", &shuffle_m);

                for(i=0; i < shuffle_m; i++){
                        scanf("%d", &shuffle_h);

                        input_back_start_index = shuffle_h;
                        output_back_start_index = str_size - shuffle_h;

                        //input_back -> output_front
                        for(output_index=0; output_index < output_back_start_index; output_index++){
                                work_str[output_index] = input_str[input_back_start_index + output_index];
                        }

                        //input_front -> output_back
                        for(output_index=output_back_start_index; output_index < str_size; output_index++){
                                work_str[output_index] = input_str[output_index - output_back_start_index];
                        }

                        for(output_index=0; output_index < str_size; output_index++){
                                input_str[output_index] = work_str[output_index];
                        }
                }

                for(i=0; i < MAX_STR_SIZE; i++){
                        output_str[dataset_count][i] = input_str[i];
                }
        }

        for(i=0; i < dataset_count; i++){
                printf("%s\n", output_str[i]);
        }


        return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

const int size = 1001;
const double inf = 1<<24;
int n;
int b[size];
int x[size], y[size];
double costs[size][size];
int con[size][size];
int con_cnt[size];

typedef pair <double, int> PDI;
typedef priority_queue <PDI, vector <PDI>, greater <PDI> > QUEUE;
double mc[size];
int prev[size];

void dijkstra_init() {
    for ( int i = 0; i < size; i++ ) {
        mc[i] = inf;
        prev[i] = -1;
    }
}

void dijkstra( int start, int goal ) {
    QUEUE Q;
    PDI start_node( 0.0, start );
    Q.push( start_node );
    mc[start] = 0.0;
    
    while ( !Q.empty() ) {
        PDI node = Q.top();
        Q.pop();

        double c = node.first;
        int v = node.second;

        if ( v == goal ) {
            vector <int> route;
            int t = v;
            route.push_back( v );
            while ( prev[t] != -1 ) {
                route.push_back( prev[t] );
                t = prev[t];
            }
            reverse( route.begin(), route.end() );
            for ( vector <int> ::iterator it = route.begin(); it != route.end(); it++ ) {
                cout << (*it) + 1;
                if ( it + 1 != route.end() ) {
                    cout << " ";
                } else {
                    cout << endl;
                }
            }
            return;
        }

        for ( int i = 0; i < con_cnt[v]; i++ ) {
            int next_v = con[v][i];
            double next_c = c + costs[v][next_v];
            if ( next_c >= mc[next_v] ) continue;
            mc[next_v] = next_c;
            prev[next_v] = v;
            PDI next_node( next_c, next_v );
            Q.push( next_node );
        }
    }

    cout << "NA" << endl;
}

int main() {
    while ( cin >> n && n ) {
        // init
        for ( int i = 0; i < n; i++ ) {
            con_cnt[i] = 0;
        }

        // input
        for ( int i = 0; i < n; i++ ) {
            int bindex;
            cin >> bindex;
            bindex--;
            cin >> x[bindex] >> y[bindex];
        }

        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                if ( i == j ) continue;
                costs[i][j] = hypot( x[i]-x[j], y[i]-y[j] );
                if ( costs[i][j] > 50.0 ) continue;
                con[i][con_cnt[i]++] = j;
            }
        }

        // proc
        int m;
        cin >> m;
        for ( int i = 0; i < m; i++ ) {
            int s, g;
            cin >> s >> g;
            dijkstra_init();
            dijkstra( s-1, g-1 );
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
void Google(ll tt){
    cout<<"Case #"<<tt<<": ";
}

ll po(ll x,ll y,ll z){
    if(y==0)
        return 1%z;
    ll pp=po(x,y/2,z);
    if(y%2==0)
        return (pp*pp)%z;
    else
        return (((pp*pp)%z)*(x%z))%z;
}
int main()
{
    IO
    clock_t begin = clock();
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='1')
            ans++;
    }
    // cout<<ans<<endl;
    ll m1=ans-1,m2=ans+1,ss=0,sss=0;
    for(ll i=0;i<n;i++)
    {
        if(m1>0 && s[i]=='1')
        ss=(ss+po(2,n-i-1,m1));
        if(m2>0 && s[i]=='1')
        sss=(sss+po(2,n-i-1,m2));
    }
    // cout<<ss<<' '<<sss<<endl;
    for(ll i=0;i<n;i++)
    {
        ll cnt=0,sum;
        if(s[i]=='0')
        {
            sum=sss;
            sum+=po(2,n-i-1,m2);
            sum%=m2;
            sum+=m2;
            sum%=m2;
            cnt++;
            while(sum>0)
            {
                ll bits=__builtin_popcount(sum);
                cnt++;
                if(sum%bits==0)
                    break;
                sum%=bits;
            }
            // cout<<cnt<<endl;
        }
        else
        {
            if(m1<=0)
            {
                cout<<"0 ";
                continue;
            }
            sum=ss;
            sum-=po(2,n-i-1,m1);
            sum%=m1;
            sum+=m1;
            sum%=m1;
            // cout<<sum<<endl;
            cnt++;
            while(sum>0)
            {
                ll bits=__builtin_popcount(sum);
                cnt++;
                if(sum%bits==0)
                    break;
                sum%=bits;
            }
        }
        cout<<cnt<<' ';
    }
    // cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    string s ; 
    cin >> s ;

    ll num = 0 ;
    ll ans = 0 ;
    for(ll i=0;i<s.length();++i)
    {
        if(s[i]=='B'){
            num++;
        } 
        else {
            ans+=num ;
        }
    }

   //cout << num << endl ;
   cout << ans << endl ;

    return 0 ;
}

Measured memory_bytes: 640
n = int(input())
MX = 10**18
a = list(map(int, input().split()))
for x in a:
    if x == 0:
        print(0)
        exit(0)
ans = 1
for x in a:
    ans *= x
    if ans > MX:
        print(-1)
        exit(0)
print(ans)


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

using namespace std;

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  
  int num = 0;
  for (int i = 0; i <= A; i++)
	for (int j = 0; j <= B; j++)
      for (int k = 0; k <= C; k++)
        if (X == i * 500 + j * 100 + k * 50)
          num++;
      
  cout << num << endl;   
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;

#define F first
#define S second


using namespace std;

int main() {

	SINT64 N = 0;
	SINT64 M = 0;
	SINT64 ANS = 0;

	cin >> N;
	cin >> M;
	if ((N == 1) && (M == 1)) {
		ANS = 1;
	} else if (N == 1) {
		ANS = M-2;
	} else if (M == 1) {
		ANS = N-2;
	} else {
		ANS = N*M - 2*(N-1) - 2*(M-1);
	}

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, sum = 0, t;
	cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w.at(i);
		sum += w.at(i);
	}
	int m = 0, ans = 10000;
	for (int i = 0; i < n; i++) {
		m += w.at(i);
		sum -= w.at(i);
		if (m < sum) {
			if (ans > sum - m) {
				ans = sum - m;
			}
		}
		else if (m > sum) {
			if (ans > m - sum) {
				ans = m - sum;
			}
		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
a = int(input())
n = 1
while True:
    if n > a:
        break
    if n % 3 == 0:
        print(" {}".format(n),end="")
    else:
        m = n
        while m >= 3:
            if m % 10 == 3:
                print(" {}".format(n),end="")
                break
            else:
                m = m // 10
    n += 1
print()


Measured memory_bytes: 5868
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int q = sc.nextInt();
    long[] s = new long[a + 1];
    long[] t = new long[b + 1];
    for(int i = 0; i < a; i++) {
      s[i] = sc.nextLong();
    }
    s[a] = (long)Math.pow(10, 15);
    for(int i = 0; i < b; i++) {
      t[i] = sc.nextLong();
    }
    t[b] = (long)Math.pow(10, 15);
    for(int i = 0; i < q; i++) {
      long x = sc.nextLong();
      int sx = -1;
      int tx = -1;
      int left = 0;
      int right = a;
      while(left < right) {
        int med = (left + right) / 2;
        if(s[med] <= x) {
          sx = med;
          left = med + 1;
        } else {
          right = med;
        }
      }
      left = 0;
      right = b;
      while(left < right) {
        int med = (left + right) / 2;
        if(t[med] <= x) {
          tx = med;
          left = med + 1;
        } else {
          right = med;
        }        
      }
      long ans = 0;
      if(sx == -1) {
        if(tx == -1) {
          ans = Math.max(s[0] - x, t[0] - x);
        } else {
          ans = Math.min(s[0] - x + s[0] - t[tx], x - t[tx] + s[0] - t[tx]);
          ans = Math.min(ans, Math.max(s[0] - x, t[tx + 1] - x));
        }
      } else {
        if(tx == -1) {
          ans = Math.max(t[0] - x, s[sx + 1] - x);
          ans = Math.min(ans, t[0] - s[sx] + Math.min(t[0] - x, x - s[sx]));
        } else {
          ans = Math.max(x - s[sx], x - t[tx]);
          ans = Math.min(ans, Math.max(s[sx + 1] - x, t[tx + 1] - x));
          ans = Math.min(ans, s[sx + 1] - t[tx] + Math.min(s[sx + 1] - x, x - t[tx]));
          ans = Math.min(ans, t[tx + 1] - s[sx] + Math.min(t[tx + 1] - x, x - s[sx]));
        }        
      }
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 104808
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


N = int(input())
A = list(map(int, input().split()))
A.sort()
countA = Counter(A)
maxA = A[-1]
# if countA[1] == 1:
#     print(1)
#     exit()

ef = [True]*(maxA+1)
count = 0
prev = -1
for num in A:
    if num == prev:
        continue
    if ef[num] and countA[num] == 1:
        count += 1

    b = 2*num
    while b <= maxA:
        ef[b] = False
        b += num

    prev = num

print(count)


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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 2e5 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

ll n, T, t[maxn], ans;
deque<pll> dq;

bool check()
{
	ll l1 = dq[0].ff, l2 = dq[1].ff, r1 = dq[0].ss, r2 = dq[1].ss;
	return (max(l1, l2) <= min(r1, r2));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> T;
	fori (i, 0, n)
		cin >> t[i];
	fori (i, 0, n)
		dq.pb(mp(t[i], t[i] + T));
	sort(all(dq));
	while (!dq.empty())
	{
		if (dq.size() == 1)
		{
			ans += (dq[0].ss - dq[0].ff);
			dq.popf();
		}
		else
		{
			if (check())
			{
				ll l = min(dq[0].ff, dq[1].ff), r = max(dq[0].ss, dq[1].ss);
				dq.popf();
				dq.popf();
				dq.pf(mp(l, r));
			}
			else
			{
				ans += (dq[0].ss - dq[0].ff);
				dq.popf();
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
import sys
ab = []
n = int(input())
for i in range(n):
  ab.append(list(map(int,input().split())))
#print(n,ab)

ab.sort(key=lambda x: x[1])
#print(ab)

t = 0
for i in range(n):
  t += ab[i][0]
  if t > ab[i][1]:
    print('No')
    sys.exit(0)

print('Yes')

Measured memory_bytes: 53720
#include <iostream>
using namespace std;
int main(void){
    int l, i=0, a[2];
    while(cin>>l){
        a[i] = l;
        i++;
    }
    
    if((a[0]+a[1])%2==0){
        cout << (a[0]+a[1])/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256