akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B; cin >> A >> B;
  int ans;
  if (B >= 0) {
  	ans = max(A + B, A * B);
  }
  else ans = max(A - B, A * B);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
  
int
main(void){
  long long int n, m;
  cin>>n>>m;
 
  int one = 1;
  if(n == 1 && m == 1){cout << one << endl;}
  else if(n == 1 && m > 1){cout << m-2 << endl;}
  else if(m == 1 && n > 1){cout << n-2 << endl;}
  else{
    cout << m*n - n - n -(m-2) -(m-2) << endl;
  }
  return 0;
}
 

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


typedef long long ll;
    typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
ll ans;
string str;

int main(){
    int a;
    int min_e=iINF;
    bool even=true;
    cin>>n;
    ans=0LL;
    forn(i){
        cin>>a;
        if(a<0){
            even=!even;
            a*=-1;
        }
        min_e=min(min_e, a);
        ans+=a;
    } 
    if(!even){
        ans-=(2*min_e);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        long diff = 0;
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
            diff -= a[i];
        }
        for (int i = 0; i < n; ++i) {
            b[i] = in.nextInt();
            diff += b[i];
        }
        long num = 0;
        for (int i = 0; i < n; ++i) if (a[i] < b[i]) {
            num += (b[i] - a[i] + 1) / 2;
        }
        System.out.println((num <= diff) ? "Yes" : "No");
    }
}

Measured memory_bytes: 43440
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1<<16;
int n,m,v[20][20];
long long ans,in[maxn],f[maxn][20];
vector<int>d[20];
int main(){
	read(n),read(m);
	for(rg int i=1,x,y,z;i<=m;i++){
		read(x),read(y),read(z),v[x][y]=v[y][x]=z;
		ans+=z;
		d[x].push_back(y),d[y].push_back(x);
	}
	int tot=1<<n;
	for(rg int i=0;i<tot;i++){
		for(rg int j=1;j<=n;j++)
			if(!(i&(1<<(j-1)))){
				int w=d[j].size(),sum=in[i];
				for(rg int k=0;k<w;k++)
					if(i&(1<<(d[j][k]-1)))sum+=v[j][d[j][k]];
				in[i|(1<<(j-1))]=sum;
		}
	}
	memset(f,-1,sizeof f);
	f[1][1]=0;
	for(rg int i=0;i<tot;i++)
		for(rg int k=1;k<=n;k++){
			if(f[i][k]==-1)continue;
			if(i&(1<<(k-1))){
				for(rg int j=1;j<=n;j++)
					if(!(i&(1<<(j-1)))&&v[k][j])
						f[i|(1<<(j-1))][j]=max(f[i][k]+v[k][j],f[i|(1<<(j-1))][j]);
				int now=((tot-1)^i)|(1<<(k-1));
				for(rg int j=now;j;j=(j-1)&now)
				    if(j&(1<<(k-1)))f[i|j][k]=max(f[i][k]+in[j],f[i|j][k]);
			}
		}
	printf("%lld\n",ans-f[tot-1][n]);
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt;
int vis[100005];
ll ans;
struct point
{
    int x,y,i;
}z[100005];
struct edge
{
    int a,b,v;
}xx[200005];
bool cmp1(point a, point b)
{
    return a.x < b.x;
}
bool cmp2(point a, point b)
{
    return a.y < b.y;
}
bool cmp3(edge a, edge b)
{
    return a.v < b.v;
}
int findd(int x)
{
    if (x == vis[x])
        return vis[x];
    return vis[x] = findd(vis[x]);
}
int main()
{
//    freopen("in.txt","r",stdin);
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &z[i].x, &z[i].y);
    for (int i = 1; i <= n; i++)
        z[i].i = i;
    sort(z + 1, z + n + 1, cmp1);
    for (int i = 2; i <= n; i++)
    {
        xx[cnt].v = z[i].x - z[i - 1].x;
        xx[cnt].a = z[i].i;
        xx[cnt++].b = z[i - 1].i;
    }
    sort(z + 1, z + n + 1, cmp2);
    for (int i = 2; i <= n; i++)
    {
        xx[cnt].v = z[i].y - z[i - 1].y;
        xx[cnt].a = z[i].i;
        xx[cnt++].b = z[i - 1].i;
    }
    for (int i = 1; i <= n; i++)
        vis[i] = i;
    sort(xx, xx + cnt, cmp3);
    for (int i = 0; i < cnt; i++)
    {
        if (findd(xx[i].a) == findd(xx[i].b))
            continue;
        ans += (ll)xx[i].v;
        vis[vis[xx[i].a]] = vis[xx[i].b];
    }
    printf("%lld\n", ans);
    return 0;
}

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

const int N = 1e5 + 10;

int n, k;
char s[N];

int solve(){
    int ret = 0;
    int cnt = 0, pre = 0, cur = 0;
    for(int i=0; i<n; i++){
        if(s[i] == pre){
            cur++;
        } else {
            cnt++;
            if(cur) ret += (cur - 1);
            pre = s[i];
            cur = 1;
        }
    }

    if(cur) ret += (cur - 1);

    return min(n-1, ret + k * 2);
}

int main(){
    while(~scanf("%d %d", &n, &k)){
        scanf("%s", s);
        printf("%d\n", solve());
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[55];
int main() {
	int N, K, i, j, k;
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) scanf("%d", &in[i]);

	int ans = 0;
	for (i = 0; i <= N; i++) {
		for (j = 0; i + j <= N; j++) {
			vector <int> Vl;
			if (i + j > K) continue;

			for (k = 1; k <= i; k++) Vl.push_back(in[k]);
			for (k = N - j + 1; k <= N; k++) Vl.push_back(in[k]);
			sort(all(Vl));
			reverse(all(Vl));

			int c = K - i - j;
			while (!Vl.empty()) {
				if (c == 0) break;
				if (Vl.back() >= 0) break;
				c--;
				Vl.pop_back();
			}

			int s = 0;
			for (auto it : Vl) s += it;
			ans = max(ans, s);
		}
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String[] list = s.split("");
      	int check = 0;
      	for(int i=0; i<s.length(); i++){
          if(list[i].equals("7")) check=1;
        }
      	if(check==0) System.out.println("No");
      	else System.out.println("Yes");
	}
}


Measured memory_bytes: 35820
import fractions
A,B,C,D = map(int,input().split())

lcm = int(C*D / fractions.gcd(C,D))
ans_b = B - (B // C) - (B // D) + (B // lcm)
ans_a = A - 1 - ((A - 1)// C) - ((A - 1)// D) + ((A - 1) // lcm)

print(ans_b - ans_a)

Measured memory_bytes: 5048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int a;
int main()
{
	int n=4,s=0;
	while(n--)
	{
		scanf("%1d",&a);
		if(a==2)s++;
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
	ll s, t;
	cin >> s >> t;
	ll ans = 0;
	if (2 * s<t) {
		ans += s;
		t -= 2 * s;
		ans += t / 4;
	}
	else if (2 * s == t) {
		ans = s;
	}
	else if (2 * s>t) {
		ans = t / 2;
	}
	cout << ans << endl;
}

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

int main() {

    int n; string s; cin >> n >> s;
    int cnt_w = 0;
    int cnt_b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '.') cnt_w++;
        if (s[i] == '#') cnt_b++;
    }
    vector<int> rev_accum_w(n + 1, 0);    
    for (int i = n - 1 ; i >= 0; i--) {
        if (s[i] == '.') rev_accum_w[i]++;
        rev_accum_w[i] += rev_accum_w[i + 1];
    }
    vector<int> accum_b(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        accum_b[i] += accum_b[i - 1];
        if (s[i - 1] == '#') accum_b[i]++;        
    }
    int ans = 100000000;
    for (int i = 0; i <= n; i++) {
        int tmp = 0;
        tmp += accum_b[i];
        tmp += rev_accum_w[i];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5228
#include<iostream>
#include<math.h>
using namespace std;

int main(void) {
	unsigned long long s, a, b;
	cin >> s;
	b = (int)sqrt(s);
	if (s == b * b) {
		cout << "0 0 0 " << b << " " << b << " 0" << endl;
	}
	else {
		a = (b+1) * (b+1);


		cout << "0 0 1 " << b+1 << " " << b+1 << " " << a - s << endl;
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int A, B;
    io.read(A, B);
    if(A * B % 2 == 0) {
        cout << "No";
    }
    else {
        cout << "Yes";
    }
    return 0;
}

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

int main() {
    int n, count = 0;
    cin>>n;
    if(n%2 == 1)
    {
        cout<<"No";
    }
    else
    {
        string a;
    cin>>a;
    int i = 0, j = n/2;
    while(1)
    {
        if(a[i] == a[j])
        {
            count++;
        }
        if(j == n)
            break;
        i++;
        j++;
    }
    if(count == n/2 && n != 1)
        cout<<"Yes";
    else
        cout<<"No";
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    string s;ll k;
    cin>>s>>k;
    ll ans;
    for(ll i=0;i<s.length();i++)
    {
        if(k==0)
        break;
        if(s[i]=='1')
        k--;
        else
        {
            ans=s[i]-'0';
            break;
        }
    }
    if(k)cout<<ans;
    else
    {
        cout<<1;
    }
    
  }  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

R = []
G = []
B = []
result = 0

for i in range(N):
    if S[i] == 'R':
        R.append(1)
        G.append(0)
        B.append(0)
    elif S[i] == 'G':
        R.append(0)
        G.append(1)
        B.append(0)
    if S[i] == 'B':
        R.append(0)
        G.append(0)
        B.append(1)
for i in range(N):
    R.append(0)
    G.append(0)
    B.append(0)
R_total = sum(R)
G_total = sum(G)
B_total = sum(B)
R_count = []
G_count = []
B_count = []
for i in range(N):
    if S[i] == 'R':
        R_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)
    elif S[i] == 'G':
        G_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)
    if S[i] == 'B':
        B_total -= 1
        R_count.append(R_total)
        G_count.append(G_total)
        B_count.append(B_total)

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == 'R':
            if S[j] == 'G':
                result += B_count[j]
                if B[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'B':
                result += G_count[j]
                if G[j * 2 - i] == 1:
                    result -= 1
        elif S[i] == 'G':
            if S[j] == 'R':
                result += B_count[j]
                if B[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'B':
                result += R_count[j]
                if R[j * 2 - i] == 1:
                    result -= 1
        elif S[i] == 'B':
            if S[j] == 'R':
                result += G_count[j]
                if G[j * 2 - i] == 1:
                    result -= 1
            if S[j] == 'G':
                result += R_count[j]
                if R[j * 2 - i] == 1:
                    result -= 1
print(result)

Measured memory_bytes: 74520
n = int(input())
a = [int(input()) for _ in range(n)] + [0]
if a[0] > 0:
    print(-1)
else:
    ans = 0
    for i in range(n):
        if a[i] < a[i + 1] - 1:
            print(-1)
            break
        elif a[i] >= a[i + 1]:
            ans += a[i]
    else:
        print(ans)


Measured memory_bytes: 12584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int count=0;
	for(int i=0;i<s.length()-1;i++){
		if(s[i]!=s[i+1])count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,p,n) for(ll i=n-1;i>=p;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define trav(it,a) for(auto it=a.begin();it!=a.end();++it)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll n,m;
  cin>>n>>m;
  ll arr[n],s=0;
  fo(i,n)
    cin>>arr[i];
  fo(i,n)
  s=s+arr[i];
  sort(arr,arr+n);
  ll c=0;
  for(ll i=n-1;i>=0;i--)
  {
    if((arr[i]*4*m)<s)
      break;
    else
      c++;
    if(c==m)
      break;
  }
  if(c==m)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, raw_input().split())
w = []
max = 0
sum = 0
for i in xrange(n):
	w_i = int(raw_input())
	if w_i > max:
		max = w_i
	sum += w_i
	w.append(w_i)

def can_put(w, p, k):
	weight = 0
	cnt = 1
	for w_i in w:
		if weight + w_i <= p:
			weight += w_i
		else:
			cnt += 1
			if cnt > k:
				return 0
			else:
				weight = w_i
	return 1

low = max
high = sum

while low < high:
	mid = (low + high) / 2
	#print high, mid, low
	if can_put(w, mid, k) == 1:
		#print("*1")
		high = mid
	else:
		#print("*0")
		low = mid + 1
	#print high, mid, low
print high

Measured memory_bytes: 9388
A, B, C, D = map(int, input().split())

def gcd(a, b):
    mod = a%b
    while mod > 0:
        a = b
        b = mod
        mod = a%b
    return b

x = 0
if A%C == 0:
    x += B//C - A//C + 1
else:
    x += B//C - A//C

if A%D == 0:
    x += B // D - A // D + 1
else:
    x += B // D - A // D

E = C*D//gcd(C,D)
if A%E == 0:
    x -= B // E - A//E + 1
else:
    x -= B // E - A // E

print(B-A-x+1)

Measured memory_bytes: 3064
/*
    written by Pankaj Kumar.
    country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
typedef vector<pair<int,int>> vpi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<ll,ll> ml;
typedef set<string> ss;
typedef set<char>sc;
typedef set<int> si;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define Endl "\n"
// loops
#define loop(i,start,end) for(ll i=ll(start);i<ll(end);i++)
#define loop0(num) for(ll i=0;i<ll(num);i++)
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
// Some print
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define cc ll test;cin>>test;while(test--)
// sort
#define all(V) (V).begin(),(V).end()
#define srt(V) sort(all(V))
#define srtGreat(V) sort(all(V),greater<ll>())
// function

ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)res*=x;
        y/=2; x*=x;
    }
    return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/
ll solve()
{
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> v(n);
    vector<bool> check(n,false);
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    ll count=0,maxo=0;
    for(ll i=0;i<n;i++)
    {
        if(check[i]==false)
        {
            queue<ll> q;
            q.push(i);
            check[i]=true;
            count=0;
            while(!q.empty())
            {
                ll u=q.front();
                q.pop();
                count++;
                for(auto s:v[u])
                {
                    if(check[s]==false)
                    {
                        q.push(s);
                        check[s]=true;
                    }
                }
            }
            maxo=max(maxo,count);
        }
        
    }
    cout<<maxo<<endl;
    return 0;
}

int main()
{
    //freopen("input.txt"a, "r", stdin);
    // cc
    // {
        solve();
    // }
}


Measured memory_bytes: 16972
#include<bits/stdc++.h>
#include <typeinfo>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = (1LL<<31)-1;

int main(){
    string S; cin >> S;
    ll ans = 0;
    for(ll bit = 0;bit < (1<<(S.size()-1));bit++){
        string cur;
        rep(i,S.size()){
            cur.push_back(S[i]);
            if(bit & (1<<i)){
                if(cur!=""){
                    ll a = stol(cur);
                    ans += a;
                }
                cur = "";
            }
        }
        if(cur!=""){
            ll a = stol(cur);
            ans += a;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }


    public static void Main()
    {
        var T = ReadArray();
        var arr = ReadStr();

        int n = T[0], k = T[1];

        int i = 0;

        var q = new Queue<int>();

        int ans = 0;
       
        for (int j = 0; j < n; j++)
        {
            if (arr[j] == '0')
            {
                q.Enqueue(j);
            }

            if (q.Count > k)
            {               
                i = q.Dequeue();
                while (i < n && arr[i] == '0') i++;
            }

            while (j < n && arr[j] == '0')
            {
                j++;                
            }

            if(j == n)
                ans = Math.Max(ans, j - i);
            else
                ans = Math.Max(ans, j - i + 1);



        }

        Console.WriteLine(ans);

       

       

      
       


    }


}

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

int main() {
    long N,ans(0);
    cin >> N;
    
    for(long i = 1;i < N+1;i++){
       if((i % 3 != 0 && i % 5 != 0) && (i % 3 != 0 || i % 5 != 0)){
           ans += i;
       }
    }
    cout << ans;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <map>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  std::map<int, int> m;
  int a;
  rep(i, N) {
    cin >> a;
    m[a]++;
  }

  int c = 0;
  for(const auto& e : m) {
    if (e.second % 2 != 0) c++;
  }

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;

  vector<int> nums;

  if (S[0] == '0') {
    nums.push_back(0);
  }

  for (int i = 0; i < S.size(); ) {
    int j = i;
    while (j < S.size() && S[i] == S[j]) {
      j++;
    }
    nums.push_back(j - i);
    i = j;
  }

  if (S.back() == '0') {
    nums.push_back(0);
  }

  // for (auto x: S) {
  //   cout << x << " ";
  // }
  // cout << endl;

  vector<int> sums((int)nums.size() + 1, 0);

  for (int i = 0; i < nums.size(); i++) {
    sums[i+1] = sums[i] + nums[i];
  }

  // for (auto x: sums) {
  //   cout << x << " ";
  // }
  // cout << endl;

  int res = 0;

  for (int left = 0; left < sums.size(); left += 2) {
    int right = left + K*2 + 1;
    if (right >= sums.size()) right = (int)sums.size() - 1;
    res = max(res, sums[right] - sums[left]);
  }

  cout << res << endl;
}


Measured memory_bytes: 1272
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
typedef pair<int,int> pii;
#define all(a) (a).begin(),(a).end()
#define INF 999999999
#define pb push_back
 
//verified
//note that this is 1-index
template<class T>
class BIT{
private:
    vector<T> sum_of_section_;
    int elements_count_;
    T init_;
     
public:
    BIT(int elements_count=0 , T init=0):elements_count_(elements_count*2),init_(init),sum_of_section_(elements_count*2+1,0){
        for(int i=0;i<elements_count_;i++) add(i+1,init);
    }
     
    T sum(int i){   //(1,i)
        int sum=0;
        while(i>0){
            sum+=sum_of_section_[i];
            i -= i&-i;
        }
        return sum;
    }
     
    void add(int i,T val){
        while(i<=elements_count_){
            sum_of_section_[i]+=val;
            i += i&-i;
        }
    }
     
    int getIthNumber(int x){    //i???????????°??????????°????????? ARC033 C????????????
        ll left=0, right=elements_count_-1, mid=(left+right)/2LL;
        while(left+1<right){
            int res = sum(mid);
             
            if(res<x) left = mid;
            else    right= mid;
             
            mid = (left+right)/2LL;
        }
        add(mid+1,-1);
        return mid+1;
    }
    /*
     bit.add(x,1);
     cout<<bit.getIthNumber( I-th )<<endl;
     */
     
};
 
 
vector<ll> getP(ll n){
    vector<ll> data(n);
    rep(i,n){
        ll l=1;
        ll r=i+1;
        printf("? %lld %lld\n", l,r); fflush(stdout);
        cin>>data[i];
    }
     
    vector<ll> ret(n);
    ret[0]=0;
    for(ll i=n-1;i>=1;i--){
        ret[i] = data[i]-data[i-1];
    }
     
    return ret;
}
 
vector<ll> solveLine(ll n,vector<ll> p){
    vector<ll> ret;
     
    BIT<int> bit(n+1);
    rep(i,n)bit.add(i+1,1);
     
    rep(i,n){
        int res = bit.getIthNumber(p[i]+1);
        ret.pb(n-res+1);
    }
     
    return ret;
}
 
 
int main(){
    ll n;
    cin>>n;
     
    vector<ll> p = getP(n);
     
     
    reverse(all(p));
     
    vector<ll> line = solveLine(n,p);
    reverse(all(line));
    cout<<"!";
    rep(i,line.size()){
        cout<<" "<<line[i];
    }cout<<endl;
     
     
}

Measured memory_bytes: 288948
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		for(;;) {
			a-=500;
			if(a<500) {
				break;
			}
				
		}
		if(a<=b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void minAssign(T)(ref T dst, T src)
{
    dst = min(dst, src);
}

alias sread = () => readln.chomp();

void main()
{
    long N = lread();

    static immutable dp = () {
        enum Nmax = 10^^5;
        auto dp = new long[](Nmax + 1);
        dp[] = long.max;
        dp[0] = 0;

        foreach (i; 0 .. Nmax)
            if (dp[i] != long.max)
            {
                dp[i + 1].minAssign(dp[i] + 1);

                size_t j = 6;
                while (i + j < dp.length)
                {
                    dp[i + j].minAssign(dp[i] + 1);
                    j *= 6;
                }

                j = 9;
                while (i + j < dp.length)
                {
                    dp[i + j].minAssign(dp[i] + 1);
                    j *= 9;
                }
            }
        return dp;
    }();

    dp[N].writeln();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }





void solve() {
    /*
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    */
    
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    while (T--) {
        solve();
        // cout << (solve() ? "YES" : "NO") << endl;
    }
}


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  set<pair<int, int>> st;
  for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) st.emplace(i+1, j+1);
  if(n % 2) {
    for(int i = 1; i <= n - 1; i++) {
      st.erase(make_pair(i, n - i));
    }
  } else {
    for(int i = 1; i <= n; i++) {
      st.erase(make_pair(i, 1 + n - i));
    }
  }
  cout << st.size() << endl;
  for(auto p : st) {
    cout << p.first  << " " << p.second << "\n";
  }
  return 0;
}



Measured memory_bytes: 512
import itertools

def chmax(a, b):
    if a < b:
        a = b
        return a
    else:
        return a

n = int(input())
ls = [[int(_) for _ in input().split()] for _ in range(n)]

dp = [[0] * 3 for _ in range(n)]
dp[0] = ls[0]

for i in range(1, n):
	for j, k in itertools.product(range(3), range(3)):
		if j == k:
			continue
		else:
			dp[i][k] = chmax(dp[i][k], dp[i - 1][j] + ls[i][k])

print(max(dp[n - 1]))

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

int main()
{
	int m1,d1,m2,d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(d2 == 1){
		cout << 1 << endl;
	}
	else
		cout << 0 << endl;
	return 0;
} 

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

int main(){

	int x[5],ans=0;
  	cin>>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
  	for(int i=0;i<5;i++){
    	if(x[i] != i+1){
        	ans=i+1;
        }
    }
  cout<<ans<<endl;
return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<vector<bool>> graph(n, vector<bool>(n, false));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        graph[a][b] = true;
        graph[b][a] = true;
    }

    vector<int> order(n);
    rep(i, n) order[i] = i;

    int ans = 0;
    do {
        if (order[0] != 0) continue;
      
        rep(i, n - 1) {
            if (!graph[order[i]][order[i + 1]]) break;
            if (i == n - 2) ans++;
        }

    } while (next_permutation(order.begin(), order.end()));

    cout << ans << endl;
    return 0;
}

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

int main(void) {
    int N;cin>>N;
    ll dp[N+1];
    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        ll a;cin>>a;
        dp[i] = dp[i - 1] + a;
    }
    ll mi = -1;
    for (int i = 1; i <= N - 1; i++) {
        ll x = dp[i];
        ll y = dp[N] - dp[i];
        ll cur = abs(x - y);
        if (mi > cur || mi == -1) mi = cur;
    }
    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int i;
  int K;
  int a = 7 % K;

  
  scanf("%d" ,&K);
  
  if(K == 7){
    
    a = a % K;
    
  }
  
  if(K % 2 != 0 && K % 5 != 0){
  
    for(i = 1; i < K; i++){

       if(a == 0)break;
       a = (a * 10 + 7) % K;     
      
    }
    
  }else{
    
    i = -1;
  
  }
  
  printf("%d\n" ,i);
  
  return 0;
  
}

Measured memory_bytes: 1700
use proconio::input;
fn main() {
    input!{
        n: u64,
    };
    let mut t = n;
    let al = vec!["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
    let mut cs : Vec<u32> =  Vec::new(); //chars
    while t != 0 {
        t = t - 1;
        let idx = (t % 26) as usize;
        cs.push(idx as u32);
        t = t / 26;
    }
    cs.reverse();
    for i in 0..cs.len() {
        print!("{}", al[cs[i] as usize]);
    }
    println!("");
}


Measured memory_bytes: 2136
n,q=map(int,input().split())
a=list(map(int,input().split()))
size=2*n+1
bit=[0]*size
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x)
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s
for i,j in enumerate(a,1):
    bit_update(i,j)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        bit_update(b+1,c)
    else:
        print(bit_sum(c)-bit_sum(b))

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> A(h);
    for (auto &a: A)
        cin >> a;

    const constexpr int INF = 1e6;
    vector<vector<vector<int>>> DP(h + 1, vector<vector<int>>(w + 1, vector<int>(2, INF)));
    DP[0][0][0] = 0;

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (A[i][j] == '#'){
                DP[i + 1][j][1] = min({DP[i + 1][j][1], DP[i][j][0] + 1, DP[i][j][1]});
                DP[i][j + 1][1] = min({DP[i][j + 1][1], DP[i][j][0] + 1, DP[i][j][1]});
            } else {
                DP[i + 1][j][0] = min({DP[i + 1][j][0], DP[i][j][0], DP[i][j][1]});
                DP[i][j + 1][0] = min({DP[i][j + 1][0], DP[i][j][0], DP[i][j][1]});
            }
        }
    }

    cout << DP[h][w - 1][A[h - 1][w - 1] == '#' ? 1 : 0] << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)

typedef pair<ll,ll> pp;
int lcm(int a, int b)
{
    int lar = max(a, b);
    int small = min(a, b);
    for (int i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result
  
    x = x % p; // Update x if it is more than or
                // equal to p
   
    if (x == 0) return 0; // In case x is divisible by p;
  
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
  
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

struct ArrayWrapper
{
    int a[101][101];
};

bool isPowerOfTwo (ll x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}


void solve(){
    ll n, m;
    cin >> n >> m;
    ll h[n];
    vector<ll> v[n];
    for(ll i = 0;i < n;i++) cin >> h[i];
    while(m--){
        ll a, b;
        cin >> a >> b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    ll count = 0;
    for(ll i=0;i < n;i++){
        ll flag = 0;
        for(ll j = 0;j < v[i].size();j++){
            if(h[i] <= h[v[i][j]]){
                flag = 1;
                break;
            }
        }
        if(flag == 0) count++;
    }
    cout << count << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //ll t; cin >> t; while(t--)
        solve();
}


Measured memory_bytes: 10232
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>p(n);
  rep(i,n)cin>>p[i];
  sort(all(p));
  cout<<p[n/2]-p[n/2-1]<<endl;
  return 0;

}


Measured memory_bytes: 1024
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint x[114514],y[114514],w[114514],z[114514],out[114514];
vector<lint> v;
int main()
{
	int n;lint l,t;
	cin>>n>>l>>t;
	rep(i,n) cin>>x[i]>>w[i];
	rep(i,n){
		if(w[i]<2) z[i]=1;else z[i]=-1;
		y[i]=x[i]+z[i]*t;
		y[i]%=l;y[i]+=l;y[i]%=l;
		v.pb(y[i]);
	}
	sort(All(v));
	lint sum=0,a=(t/l)*2,b=(t%l)*2;
	REP(i,1,n){
		if(w[0]==w[i]) continue;
		sum+=a;
		if(w[0]<2){
			lint d=(x[i]+l-x[0])%l;
			if(d<b) sum++;if(d+l<b) sum++;
		}
		else{
			lint d=(x[0]+l-x[i])%l;
			if(d<b) sum++;if(d+l<b) sum++;
		}
	}
	int np=(int)(((0+z[0]*sum)%n+n)%n);
	int zp=-1;
	rep(i,n){
		if(y[0]==v[i]){
			if(z[i]>0 || zp<0) zp=i;
		}
	}
	rep(i,n){
		out[(i+np)%n]=v[(i+zp)%n];
	}
	rep(i,n) cout<<out[i]<<endl;
}


Measured memory_bytes: 6260
def tanri args
    amt, year, rate, fee = args
    cum = 0
    year.times{
        cum += (amt * rate).to_i
        amt -= fee.to_i
    }
    return amt + cum
end

def fukuri args
    amt, year, rate, fee = args
    year.times{amt = amt + (amt * rate).to_i - fee.to_i}
    return amt
end

m = gets.to_i
m.times{
    amt = gets.to_i
    year = gets.to_i
    n = gets.to_i
    arr = []
    n.times{
        type, rate, fee = gets.chomp.split.map(&:to_f)
        args = [amt, year, rate, fee]
        arr << (type == 0.0 ? tanri(args) : fukuri(args))
    }
    puts arr.sort.last
}


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

int main() {
    char C;
    cin >> C;
    vector<char> abc(26);
    abc = {'a','b','c','d','e','f','g','h','i','j','k',
           'l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    char ans;
    for (int i=0; i<25; i++) {
        if (C == abc[i]) {
            ans = abc[i+1];
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3540
#include <iostream>

using namespace std;

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

    if (a - b >= 0) {
        cout << "delicious" << endl;
    }
    else if (x - (b - a) >= 0) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}



Measured memory_bytes: 256
import math
n = int(input())
x = [i for i in range(1,n+1)]
res = []
judge = 0

while len(x)>1:
  for j in x:
    if j%2==0:
      res.append(j/2)
  else:
    x = res
    res = []
    judge += 1

print(math.floor(x[0]*(2**judge)))
    

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

int N,M,Q;
ll cand[1111];

char itoc(int x){
    if(x<10) return '0'+x;
    else return 'A'+x-10;
}

int main(){
    ios_base::sync_with_stdio(0);
    while(cin>>N>>M>>Q && N|M|Q){
        ll sw = 0;
        memset(cand,-1,sizeof(cand));
        rep(_,Q){
            string op,sta;
            cin>>op>>sta;
            rep(i,N)if(op[i]=='1') sw ^= 1LL<<i;
            rep(j,M){
                cand[j] &= sta[j]=='0' ? ~sw : sw;
            }
        }

        rep(i,M){
            int x = -1;
            bool ok = true;
            rep(j,N){
                if(cand[i]>>j & 1){
                    if(x!=-1) ok = false;
                    x = j;
                }
            }
            if(x!=-1 && ok) cout << itoc(x);
            else cout << '?';
        }
        cout << "\n";
    }
}

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

int a[100001];

int main(){
    int n, x;
    cin >> n >> x;
    long long ans = 0;

    for(int i=0; i < n; i++) cin >> a[i];

    //引く
    for(int i=0; i < n-1; i++){
        //総和が大きい時
        if(a[i] + a[i+1] > x){
            //足りないとき
            if(a[i+1] < a[i] + a[i+1] - x){
                ans += a[i + 1];
                ans += abs(x - a[i]);
                a[i + 1] = 0;
            }
            //足りるとき
            else{
                ans += a[i + 1] + a[i] - x;
                a[i + 1] -= a[i] + a[i + 1] - x;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k, s = 0;
    cin >> n >> k;
    int x[n];
    for (int i = 0; i < n; i++) 
    {
        cin >> x[i];
        s += min(x[i], k - x[i]);
    }
    cout << s * 2;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

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

string readString(void) {
	char buf[64];
	scanf("%s", buf);
	return string(buf);
	// string s;
	// cin >> s;
	// return s;

}

int CountWords(const string &w) {
	string t;
	int count = 0;
	for (cin >> t; t != "END_OF_TEXT"; cin >> t) {
		transform(t.begin(), t.end(), t.begin(), ::tolower);
		if (t == w) count++;
	}
	return count;
}

int main(void){
	cin.tie(0);

	cout << CountWords(readString()) << endl;

	return 0;
}



Measured memory_bytes: 3236
#include<cstdio>

const int MAX_N = 100001;
int main(void){
    int N;
    char S[MAX_N];
    int count = 1;
    scanf("%d",&N);
    scanf("%s",S);
    for(int i=1;i<N;i++){
        if(S[i-1]!=S[i]){
            count ++;
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int A, B, D, K, N;
  scanf("%d%d%d", &A, &B, &K);
  D = A+1;
  if (D>B+1) D = B+1;
  N = 0;
  while (N<K && D>1) {
    D--;
    if (!(A%D) && !(B%D)) N++;
  }
  printf("%d\n", D);
  return 0;
}
  

Measured memory_bytes: 128
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <unordered_set>
// #include <prettyprint.hpp>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;
vector<ll> height(max_n, -1);
vector<pair<ll,ll>> edge_list(max_n);

ll N, M, Q;


void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll h, a, b;
    sll(N);
    sll(M);
    rep(i, N){
        sll(h);
        height[i] = h;
    }

    // unordered_set<ll> high_set;
    unordered_set<ll> low_set;
    rep(i, M){
        sll(a);
        sll(b);
        a --;
        b --;
        if(height[a]>height[b]){
            // high_set.insert(a);
            low_set.insert(b);
            // if(high_set.find(b) != high_set.end()){
            //     high_set.erase(b);
            // }
        }else if(height[a]<height[b]){
            low_set.insert(a);
            // high_set.insert(b);
            // if(high_set.find(a) != high_set.end()){
                // low_set.erase(a);
            // }
        }else{
            // if(high_set.find(a)!=high_set.end()){
            //     high_set.erase(a);
            // }

            // if(high_set.find(b) != high_set.end()){
            //     high_set.erase(b);
            // }

            low_set.insert(a);
            low_set.insert(b);
        }
        // edge_list[i] = make_pair(a, b);

    }
    // cout << "low set:" << low_set << endl;

    // rep(i, N){
    //     auto edge = edge_list[i];
    // }

    printf("%lld\n", N-(ll)low_set.size());


    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 7824
n, m, x = map(int, input().split())

c = []
for i in range(n):
    ci = list(map(int, input().split()))
    c.append(ci)

min_cost = 10000000 * n
for i in range(1, 2 << n-1):
    a_total = []
    cost = 0
    for l in range(m):
        a_total.append(0)
    p = list(format(i, 'b').zfill(n))
    for j in range(len(p)):
        if p[j] == '1':
            a_total = [a + b for a, b in zip(a_total, c[j][1:])]
            cost += c[j][0]
    for a in a_total:
        if a < x:
            break
    else:
        min_cost = min(cost, min_cost)

if min_cost == 10000000 * n:
    print(-1)
else:
    print(min_cost)

Measured memory_bytes: 9184