akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long
ll n, a[400000],pref[400000],suf[400000];
signed main(){
	scanf("%lld",&n);
	for(int i=0;i<3*n;i++)scanf("%lld",&a[i]);
	multiset<ll> s;
	ll sum=0;
	for(int i=0;i<3*n;i++){
		sum+=a[i];
		s.insert(a[i]);
		if(s.size()>n){
			sum-=*s.begin();
			s.erase(s.begin());
		}
		pref[i]=sum;
	}
	s.clear();
	sum=0;
	for(int i=3*n-1;i>=0;i--){
		sum+=a[i];
		s.insert(a[i]);
		if(s.size()>n){
			sum-=*s.rbegin();
			s.erase(--s.end());
		}
		suf[i]=sum;
	}
	ll ans=-1e18;
	for(int i=n-1;i<2*n;i++){
		ans=max(pref[i]-suf[i+1],ans);
	}cout<<ans<<endl; return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int d;
    cin >> d;
    string ans = "Christmas";
    REP(_,25-d){
        ans += " Eve";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg): #　B　より小さい最大の　A
    return A_list[arg] < B_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg): #　B　より大きい最小の　A
    return C_list[arg] > B_list[i]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Bを固定
    #Bより小さいAを探す
    A_key = bisect(len(A_list), 0)
    if A_list[A_key] < B_list[i]:
        #Bより大きいCを探す
        C_key = bisect2(-1, len(C_list)-1)
        if B_list[i] < C_list[C_key]:
            #print(A_key, i, C_key, A_list[A_key], B_list[i], C_list[C_key])
            cnt += (n-C_key)*(A_key+1)

print(cnt)


Measured memory_bytes: 29464
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

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

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========     //\\       //||     ||====//||
//      ||        //  \\        ||     ||   // ||
//      ||       //====\\       ||     ||  //  ||
//      ||      //      \\      ||     || //   ||
//  ========== //        \\  ========  ||//====|| 
//  code

void solve(){
    int n,i,j,k,l,p;
    cin >> n >> k;
    vector<int> dp(n, INT_MAX), h(n);
    for(auto &i : h){
        cin >> i;
    }

    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(j = max(0, i - k); j < i; j++){
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
    }

    cout << dp[n - 1] << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3924
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define maxn 100000

int main(){
    char s[maxn];
    scanf("%s", s);
    long n = strlen(s);
    int total0=0;
    int total1=0;
    for(long i = 0; i<n; i++){
        if(s[i]==48){
            total0++;
        }
        else{
            total1++;
        }
    }
    printf("%d\n", min(total0, total1) * 2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  while(cin >> s && s!="#") {
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31) cout << s << " ";
    else if(y==31) {
      if(m<=4) cout << s << " ";
      else {
        cout << "?" << " ";
        y-=31;
        y++;
      }
    } else {
      cout << "?" << " ";
      y-=31;
      y++;
    }
    pr(y,m,d);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endll "\n"
#define all(x) x.begin(),x.end()
#define loop(i,a,b) for(ll int i = a; i < b; i++)
#define speed ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
ll int knapsack(ll int w[],ll int v[],ll int n,ll int wt)
{
    ll int k[n+1][wt+1];
    loop(i,0,n+1)
    loop(j,0,wt+1)
    {
        if(i==0||j==0)k[i][j]=0;
        else if(w[i-1]<=j)k[i][j]=max(v[i-1] + k[i-1][j-w[i-1]], k[i-1][j]);
        else k[i][j] = k[i-1][j]; 
    }
    return k[n][wt];
}
int main()
{
    speed;
    ll int n,wt;
    cin>>n>>wt;
    ll int w[n],v[n];
    loop(i,0,n)cin>>w[i]>>v[i];
    cout<<knapsack(w,v,n,wt);
}

Measured memory_bytes: 79232
#include<iostream>
#include<cstdio>
#include<complex>
#include <string>
#include <vector>
#include <queue>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long

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

    int c[20];
    int v[20];

    rep(i, n) {
        cin >> v[i];
    }
    rep(i, n) {
        cin >> c[i];
    }
    int d[20];
    rep(i, n) {
        d[i] = v[i] - c[i];
    }
    int ans = 0;
    rep(i, n) {
        if (d[i] > 0) {
            ans += d[i];
        }
    }

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  char b;
  cin >> b;
  if (b == 'A')
    cout << 'T' << endl;
  else if (b == 'T')
    cout << 'A' << endl;
  else if (b == 'G')
    cout << 'C' << endl;
  else
    cout << 'G' << endl;

  return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(10) << fixed;

  double r = 180/PI;

  double a, b, x; cin >> a >> b >> x;
  if (x > a*a*b/2) {
    double y = a*a*b - x;
    double k = y*2/(a*a);
    double rad = atan2(k, a);
    debug(y, k, rad);
    cout << rad*r << endl;
    return 0;
  }
  double k = x*2/(b*a);
  double rad = atan2(b, k);
  debug(x, k, rad);
  cout << rad*r << endl;

}

Measured memory_bytes: 256
a = input().split(" ")
bl = input().split(" ")
b = []
for num in bl:
  b.append(int(num))
b.sort(reverse = True)
N = int(a[0])
K = int(a[1])

m=0
i=0
if len(b) <= K:
  print(0)
else:
  for h in range(K,len(b)):
    i = i + b[h]
  print(i)
  

Measured memory_bytes: 26556
#include <iostream>
#include <cmath>
using namespace std;
int main( void )
{
  double d;
  while( 1 ){
    cin >> d;
    if( cin.eof() ) break;
    d = d*d / (2*9.8);
    cout << (int)ceil(d/5) + 1 << endl;
  }
  return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll N;
    cin >> N;

    vector<ll> tmp;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            tmp.push_back(i*j);
        }
    }

    rep (i, tmp.size()) {
        if (tmp[i] == N) {
            Yes;
            return 0;
        }
    }

    No;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,x,sum = 0;
    scanf("%d %d",&n,&x);
    int l[n + 1],d[n + 1];
    d[0] = 0;
    if(d[0] <= x) sum++;
    for(int i = 0;i < n;i++)
    	scanf("%d",&l[i]);
    for(int i = 1;i < n + 1;i++){
    	d[i] = d[i - 1] + l[i - 1];
    	if(d[i] <= x) sum++;
	}
	printf("%d",sum);
	return 0; 
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Vector;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] sequence = new int[n];
    for(int i = 0; i < n; i++){
      sequence[i] = sc.nextInt();
    }
    int koike = 1;
    int tanaka = 0;
    int min = sequence[0];
    for(int i = 0; i < n; i++){
      if(min >= sequence[i]){
        tanaka++;
      }
      min = Math.min(min,sequence[i]);
    }
    System.out.println(tanaka);
  }
}

Measured memory_bytes: 75360
#include<bits/stdc++.h>
#define int long long int
#define PB push_back
using namespace std;
typedef vector<int> VI;

const int INF = 1e9;

int n, m, d1[100010], p1[100010], d2[100010];

int d_list[100010];

bool judge(int num)
{
  VI dp(n, 1);
  
  for(int i = 0; i < m; i++)
    dp[p1[i]] = d1[i] >= num ? 0 : INF;
  
  for(int i = 0; true; i += 3){
    if(i == dp.size() - 1)
      break;
    dp.PB(dp[i] + dp[i + 1] + dp[i + 2] - max({dp[i], dp[i + 1], dp[i + 2]}));
  }

  return (d2 + n - m) - lower_bound(d2, d2 + n - m, num) >= dp[dp.size() - 1];
}

signed main()
{
  scanf("%lld%lld", &n, &m);
  for(int i = 0; i < m; i++){
    scanf("%lld%lld", &d1[i], &p1[i]);
    d_list[i] = d1[i];
    p1[i]--;
  }
  for(int i = 0; i < n - m; i++){
    scanf("%lld", &d2[i]);
    d_list[m + i] = d2[i];
  }

  sort(d_list, d_list + n);
  sort(d2, d2 + n - m);
  
  int start = 0, end = n;
  while(end - start > 1){
    int mid = (start + end) / 2;
    if(judge(d_list[mid]))
      start = mid;
    else
      end = mid;
  }

  printf("%lld\n", d_list[start]);
  return 0;
}

Measured memory_bytes: 7328
#include <bits/stdc++.h>
#define LL long long int
#define Max(x, y) (x > y ? x : y)
#define Min(x, y) (x < y ? x : y)
#define Abs(x) ( (x) > 0 ? (x) : -(x) )
#define Swap(x,y) do{x = x ^ y; y = x ^ y; x = x ^ y;}while(0)
#define IO_BOOST                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
#define setp(x) fixed << setprecision(x)
#define INF 0x3f3f3f3f
#define Lowbit(x) ((x) & (-x))
#define Pii pair<int, int>
#define x first
#define y second
#define MOD ((int)1e9+7)
using namespace std;

struct Node{
    LL w, v;
};
Node a[(int)2e5+5];
LL dp[101][(int)2e5+5] = {0};
int n, k, w;
void solve(){
    
    for(int i = 1 ; i <= n ; i++){
        for(int j = 0 ; j <= w ; j++){
            if( j >= a[i].w ){
                dp[i][j] = Max( dp[ i-1 ][j], dp[i-1][j-a[i].w] + a[i].v );
            }else dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][w] << '\n';

}
int main(){
    IO_BOOST;
    cin >> n >> w;
    for(int i = 1 ; i <= n ; i++)
        cin >> a[i].w >> a[i].v ;
    solve();

}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for (int i = 0; i < Q; ++i) cin >> A[i];
  
  vector<int> AC(N, 0);
  for (int i = 0; i < Q; ++i) ++AC[A[i] - 1];
  
  for (int i = 0; i < N; ++i) {
    if (K > Q - AC[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

#define int long long

#define MOD 1000000007
#define PB(a) push_back(a);
#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)
using  ll = long long;

signed main()
{
	int n;
	cin >> n;
	if (n == 0 || n == 2) {
		cout << 1 << endl;
	} else if (n == 1) {
		cout << 2 << endl;
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
long long data1[200005], data2[200005], data[200005];
int main()
{
    int n;
    long long minNum = (long long)INT_MAX * 10000000;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &data[i]);
        if (i > 0)
            data1[i] = data[i] + data1[i - 1];
        else
            data1[i] = data[i];
        //printf("%lld ", data1[i]);
    }
    //putchar('\n');
    for (int i = n - 1; i >= 0; --i)
    {
        if (i < n - 1)
            data2[i] = data2[i + 1] + data[i];
        else
            data2[i] = data[i];
            
    }
    for (int i = 0; i < n - 1; ++i)
    {
        //printf("%lld ", data2[i]);
        if (abs(data1[i] - data2[i + 1]) < minNum)
            minNum = abs(data1[i] - data2[i + 1]);

    }
    printf("%lld\n", minNum);
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define F0R(i, N) for (long i = 0; i < (N); i++)

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

    cout << pow(N, 3) << "\n";

    return 0;
}


Measured memory_bytes: 384
MAX = 100000
def m():
    N = int(input())
    a = list(map(int, input().split()))
    t = [0] * (MAX + 1)

    for i in range(N): t[a[i]] += 1
    ans = 0
    tmp = 0
    for n in range(1, MAX):
        ans = max(t[n - 1] + t[n] + t[n + 1], ans)
    return ans

print(m())


Measured memory_bytes: 13964
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int f[200005];
int fa[200005];
int find(int x){
	return x != f[x]?f[x]=find(f[x]):x;
}

void join(int x,int y){
	int fx = find(x);
	int fy = find(y);
	if(fx != fy) f[fx] = fy;
}

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) f[i] = i;
	
	for(int i=1;i<=m;i++){
		int aa,bb;
		cin>>aa>>bb;
		join(aa,bb);	
	}
	
    for(int i=1;i<=n;i++) fa[i] = find(f[i]);
	int ans = -inf;
	sort(fa+1,fa+1+n);
	int num = 1;
	for(int i=2;i<=n;i++){
		if(fa[i] == fa[i-1]) ++num;
		else ans = max(ans,num),num=1;
	}
	cout<<max(ans,num)<<endl;
	return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >>c;
	if (a == b && b == c)cout << "No" << endl;
	else if (a == b || b == c || a == c)cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll MOD = (1LL<<32);

int main() {
    int n;
    cin >> n;
    while (n--){
        VL a(8);
        ll b;
        REP(i,8) scanf("%llx", &a[i]);
        scanf("%llx", &b);
        ll ans = 0;
        REP(i,32){
            ll sum = 0;
            REP(j,8) sum = (sum + a[j]) % MOD;
            if (((sum ^ b) >> i & 1)) {
                ans += 1 << i;
                REP(j,8) a[j] ^= 1 << i;
                b ^= 1 << i;
            }
        }
        ans -= (ans >> 32) << 32;
        printf("%llx\n", ans);
    }

    return 0;
}

Measured memory_bytes: 3124
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll a;
  cin >> a;
  cout << a+(a*a)+(a*a*a) << endl;
  return 0;
}




Measured memory_bytes: 3584
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    loop {
        let sum: u32 = get_line().chars()
            .map(|n| n.to_digit(10).unwrap())
            .fold(0, |sum, x| sum + x);
        if sum == 0 {
            break;
        }
        println!("{}", sum);
    }
}



Measured memory_bytes: 5036
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long ans = sc.nextLong() + sc.nextLong();
    if (ans%2 == 1)
      System.out.println("IMPOSSIBLE");
    else
    System.out.println(ans/2);
  }
}


Measured memory_bytes: 21844
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    from collections import defaultdict
    dp = defaultdict(int)
    B = sorted(enumerate(A), key=lambda x: x[1], reverse=True)
    for step, (i, a) in enumerate(B, 1):
        #print('i={}, a={}'.format(i, a))
        for left in range(step):
            right = N - step + left
            #print('[{},{}]'.format(left, right))
            #print('left[{},{}]: {} vs {}+{}'.format(left+1, right, dp[(left+1, right)], dp[(left, right)], abs(left-i)*a))
            #print('right[{},{}]: {} vs {}+{}'.format(left, right-1, dp[(left+1, right)], dp[(left, right)],abs(right-i)*a))
            dp[(left+1, right)] = max(dp[(left+1, right)], dp[(left, right)] + abs(left-i)*a)
            dp[(left, right-1)] = max(dp[(left, right-1)], dp[(left, right)] + abs(right-i)*a)    
    return max(v for v in dp.values())


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 366944
#include<stdio.h>
int main(){
    int x,y,z,d;
    scanf("%d%d",&x,&y);
    
    if(x>=y){
        while(y !=0){
            d=x%y;
            x=y;
            y=d;
        }
        printf("%d\n",x);
    }
    
    else{
        while(x != 0){
            d=y%x;
            y=x;
            x=d;
        }
        printf("%d\n",y);
    }
    return 0;
}


Measured memory_bytes: 2064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N;
    cin >> N;
    vector<int>a(N+2);
    a[0] = 0;
    a[N] = 0;
    for (int i=0; i<N; i++)cin >> a[i+1];
    int cost = 0;
    int last = 0;
    for (int i=0; i<N; i++){
        cost += abs(last - a[i+1]);  
        last = a[i+1];
    }   
    
    cost += abs(last);

    for (int i=1; i<N+1; i++){
        //a[i]に行かなくてすむ
        int ans = cost;
        ans -= abs(a[i-1] - a[i]);
        ans -= abs(a[i] - a[i+1]);
        ans += abs(a[i-1] - a[i+1]);
        cout << ans << endl;
    }

}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

signed main() {
  int64_t n;
  cin >> n;

  int64_t p;
  cin >> p;
  int64_t minP = p;
  int64_t count = 1;
  REP(i,n-1){
    cin >> p;
    if(p<=minP){
      minP = p;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vi a(n),b(n);
    cin>>a>>b;
    REP(i,1,n){
        a[i]+=a[i-1];
        b[n-1-i]+=b[n-i];
    }
    int ma=0;
    REP(i,n){
        chmax(ma,a[i]+b[i]);
    }
    cout<<ma<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
p = Array.new(m)
s = Array.new(m)
for i in 0..(m-1)
  p[i], s[i] = gets.chomp.split
  p[i] = p[i].to_i
end

acs = Array.new(n+1, 0)
was = Array.new(n+1, 0)
for i in 0..(m-1)
  if s[i] == "AC"
    acs[p[i]] = 1
  elsif acs[p[i]] == 0
    was[p[i]] += 1
  end
end
ac = 0
pn = 0
for i in 1..n
  if acs[i] == 1
    ac += 1
    pn += was[i]
  end
end
puts "#{ac} #{pn}"

Measured memory_bytes: 11900
#include "stdio.h"
#include "string.h"

int ACGT(char X){
  if (X=='A' ||X=='T' ||X=='G' ||X=='C' ) {
    return 1;
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  char T[100];
  scanf("%s", T);
  int N=strlen(T);
  int preans=0;
  int ans=0;
  for (size_t i = 0; i < N; i++) {
    if (ACGT(T[i])==1) {
      preans++;
    }else{
      if (ans<preans) {
        ans=preans;
      }
      preans=0;
    }
  }
  if (ACGT(T[N-1])==1) {
    if (ans<preans) {
      ans=preans;
    }
    preans=0;
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int ans;
    ans = 1;
    int h1;
    cin >> h1;
    int max;
    max = h1;
    int h;
    for(int i=1; i < N; i++){
        cin >> h;
        if(max <= h){
            max = h;
            ans++;
        }
    }
    cout << ans << endl;
}


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


int main() {
	
	int N;
	string s;
	cin >> N >> s;
	int x = 0;
	int maxx = 0;
	for (auto i : s){
		if( i == 'I' ) x++;
		else x--;
		
		maxx = max(x, maxx);
	}
	cout << maxx << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 200000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, h[MAX_N+5], a[MAX_N+5]; lnt tr[MAX_N+5];
void upd(int p, lnt x) {for (; p <= n; p += (p&-p)) tr[p] = max(tr[p], x);}
lnt qry(int p) {lnt ret = 0; for (; p; p -= (p&-p)) ret = max(ret, tr[p]); return ret;}
int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(h[i]);
	for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 1; i <= n; i++)
		upd(h[i], qry(h[i])+a[i]);
	return printf("%lld\n", qry(n)), 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout<<fixed;
  size_t H;
  cin>>H;
  size_t i=1;
  while(i<=H) i<<=1;
  cout<<i-1<<"\n";
  return 0;
}

Measured memory_bytes: 512
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    readln.chomp.map!(a => a=='p' ? -1:1).sum.pipe!"a/2".writeln;
}


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

int main() {
	string S;
	int L, R, ans = 0;
	cin >> S;
	L = 0, R = S.size() - 1;
	while (L < R) {
		if (S[L] == S[R]) L++, R--;
		else if (S[L] == 'x') ans++, L++;
		else if (S[R] == 'x') ans++, R--;
		else {
			ans = -1;
			break;
		}
	}
	cout << ans;
}

Measured memory_bytes: 512
N = int(input())
D = [[0, 0, 0] for _ in range(N)]
for i in range(N):
    a = tuple(map(int, input().split()))
    for j in range(3):
        D[i][j] = a[j]

INIT = -1
dp = [[INIT, INIT, INIT] for _ in range(N)]
dp[0][0] = D[0][0]
dp[0][1] = D[0][1]
dp[0][2] = D[0][2]

for i in range(1, N):
    for j in range(3):
        tmp = INIT
        for k in range(3):
            if k == j:
                continue
            tmp = max(tmp, dp[i-1][k] + D[i][j])
        dp[i][j] = tmp

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


Measured memory_bytes: 42556
xn = input().split()
X = int(xn[0])
N = int(xn[1])
A = [int(x) for x in input().split()]
li = [x for x in range(102)] 
li2 = list(x for x in li if x not in A )
d_tmp = 1200
ans_tmp = -1
for i in li2:
    d = abs(X-i)
    if d < d_tmp:
        d_tmp = d
        ans_tmp = i
print(ans_tmp)



Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b,x,y;
  cin >> n;
  y = 0;
  x = 0;
  for(int i = 0;i<n;++i){
  cin >>a >>b;
    x = b - a + 1;
      y += x ;
  }
  cout << y << endl;
}


Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    IN(h, w, k);
    bool m[h][w];
    rep(i, h) {
        INS(string, s);
        rep(j, w) {
            m[i][j] = s[j]=='#';
        }
    }
    ll ans = 0;
    rep(y, 1<<h) {
        rep(x, 1<<w) {
            ll d = 0;
            rep(i, h) {
                rep(j, w) {
                    if (((y>>i)&1)==0 && ((x>>j)&1)==0 && m[i][j]) ++d;
                }
            }
            if (d == k) ans++;
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3612
x, k, d = map(int, input().split())

if x < 0:
    x = abs(x)

if x-k*d >= 0:
    print(x-k*d)
else:
    r = k - x//d
    dis = x - d*(x//d)
    if abs(dis-d) > dis and r > 1:
        r -= 1
        dis -= d
        if r%2==0:
            print(abs(dis))
        else:
            print(abs(dis+d))
    else:
        if r%2==0:
            print(abs(dis))
        else:
            print(abs(dis-d))


Measured memory_bytes: 9168
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
 
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int a[N],b[N];
int main(){
    int n,i,j,k,K,T,m=0;
    scanf("%d",&n);
    rep(i,0,n)scanf("%d",&a[i]),b[i]=a[i];
    sort(b,b+n);
    rep(i,0,n){
        a[i]=lower_bound(b,b+n,a[i])-b;
        j=a[i]&1;
        if(j!=(i&1))m++;
    }
    printf("%d\n",m/2);
    return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: i32 = read();
    let M: i32 = read();
    let mut divisors: Vec<i32> = Vec::new();
    for i in 1..100100 {
        if M % i == 0 {
            divisors.push(i);
            divisors.push(M/i);
        }
        if i*i >= M { break; }
    }
    divisors.sort();
    for d in divisors {
        if d >= N {
            println!("{}", M/d);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		while (A[i] % 2 == 0) {
			A[i] /= 2;
			res++;
		}
	}
	cout << res << endl;
}

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

struct unionfind {
  int n;

  vector<int> prt;
  unionfind(){};
  unionfind(int _n) {
    n = _n;
    prt.resize(n, -1);
  };

  int root(int i) {
    if (prt[i] == -1)
      return i;
    else
      return prt[i] = root(prt[i]);
  }

  void unite(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    prt[a] = b;
  }
  bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  for (auto&& w : p) {
    cin >> w;
    w--;
  }

  auto uf = unionfind(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    uf.unite(x, y);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (uf.same(i, p[i])) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e5;
int n,L,w[N];
int main()
{
    scanf("%d%d",&n,&L);
    for(int i=1;i<=n;i++)scanf("%d",w+i);
    int pd=0;
    for(int i=1;i<n;i++)if(w[i]+w[i+1]>=L){pd=i;break;}
    if(!pd){puts("Impossible");return 0;}
    puts("Possible");
    for(int i=1;i<pd;i++)printf("%d\n",i);
    for(int i=n-1;i>pd;i--)printf("%d\n",i);
    printf("%d\n",pd);
}

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

int main() {
  int p,q,r; cin >> p >> q >> r;
  int ans;
  if (p + q <= q + r) {
    ans = p+q;
  } else {
    ans = q +r;
  }
  if (ans >= p +r) {
    ans = p+r;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    s = input()
    K = int(input())
    print(sorted(list({s[i:j]
                       for i
                       in range(len(s))
                       for j
                       in range(i + 1, min(i + K + 1, len(s) + 1))}))[K - 1])
    return


main()


Measured memory_bytes: 4464
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;


int main() {
    int N;
    cin >> N;
    vector<long> A(N);
    for (int n = 0; n < N; n++) cin >> A[n];
    int cnt = 0;
    for (int n = 0; n < N; n++) if (A[n] < 0) cnt++;
    for (int n = 0; n < N; n++) A[n] = abs(A[n]);
    long sum = 0;
    for (int n = 0; n < N; n++) sum += A[n];

    if (cnt % 2) {
        sort(A.begin(), A.end());
        sum -= 2 * A[0];
    }

    cout << sum << endl;
}



Measured memory_bytes: 1024
/******************************************************************************

                              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>
typedef long long ll;
typedef double flot;
using namespace std;
#define rep(i,a,b) for(long long int i=a;i<b;i++)
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll cc=1;
    while(a>0 && c>0)
    {if(cc==1)
    {
        c=c-b;
    }
    else
        {a=a-d;}
    cc=1-cc;
    }
    if(a<=0)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int maxn=5e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;

int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	swap(a,b);
	swap(a,c);
	printf("%d %d %d",a,b,c);
	return 0;
}

Measured memory_bytes: 256
import kotlin.math.*

fun main() {
    println(solve())
}

val solve: () -> Any = {
    val (a,b,c,d) = readLongList()

    listOf(a*c,a*d,b*c,b*d).max()!!
}

val mod: Int = 1_000_000_007


fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

fun <E> List<E>.toPair() = this[0] to this[1]

fun <T> readPair(t: (String) -> T) = readPair(t, t)
fun <S, T> readPair(s: (String) -> S, t: (String) -> T) =
    readLine()!!.split(" ").let { Pair(s(it[0]), t(it[1])) }

fun Int.pow(n: Int) = this.toDouble().pow(n).toInt()

fun minAndMax(a: Int, b: Int) = if (a < b) a to b else b to a

fun <T> T.ifOrThis(bool: (T) -> Boolean, trans: (T) -> T) = if (bool(this)) trans(this) else this
fun <T> T.ifOrThis(bool: Boolean, trans: (T) -> T) = if (bool) trans(this) else this

Measured memory_bytes: 38976
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL long long

using namespace std;

int main()
{
    char s[10];
    while(scanf("%s",s)!=EOF)
    {
        int len=strlen(s);
        int sum=0;
        for(int i=0;i<len;i++)
        {
            if(s[i]=='1')
            {
                sum++;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


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

#define o(output) cout << output << endl

using namespace std;

string s,t,u;
int a,b,c,d;
char A,B;
priority_queue<int,vector<int>,greater<int> >small;
int l[14]={0,13,1,2,3,4,5,6,7,8,9,10,11,12};

int main(){
  cin>>s;
  s[5]=' ';
  s[13]=' ';
  o(s);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		
		int N= sc.nextInt();
		int M= sc.nextInt();
		
		
		int least= N;
		for(int i=0;i<M;i++){
			int A= sc.nextInt();
			least-= A;

			if(A<0)break;
		}
		
		sc.close();
		
		if(least>=0)System.out.println(least);
		else System.out.println(-1);
		
	}

}


Measured memory_bytes: 46708
n,k,q = map(int,input().split())
player = []
for i in range(n):
    player.append(0)
for i in range(q):
    player[int(input())-1] += 1
for i in range(n):
    if player[i] > q-k:
        print('Yes')
    else:
        print('No')

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

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

    int a[n][n];
    int done[n]; // -1: まだ ソレ以外: 確定距離
    for (int i = 0; i < n; ++i) {
        done[i] = -1;
        for (int j = 0; j < n; ++j) {
            a[i][j] = -1;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v, c;
            cin >> v >> c;
            a[i][v] = c;
        }
    }

    // デバッグ用
//     for (int i = 0; i < n; ++i) {
//         for (int j = 0; j < n; ++j) {
//             cout << i << " " << j << " " << a[i][j] << endl;
//         }
//     }

    // 最初は0が確定済みのノードとなる
    done[0] = 0;

    // 確定済みのノードから行ける、未到達の最小のノードを探す
    // その最小のノードは次の確定済みとする...
    // とりあえずデバッグがてら10回す (最終的にwhileにして条件で対応する)
    // 全てdoneになったら終了
    for (int r = 0; r < n-1; ++r) {
        int next_node = -1;
        int next_cost = 1000000;
        for (int i = 0; i < n; ++i) {
            if (done[i] == -1) {
                // 未確定であれば何もしない
                continue;
            }

            for (int j = 0; j < n; ++j) {
                // 到達済みは見ない
                if (done[j] != -1) {
                    continue;
                }

                // コストが-1なら到達できない
                if (a[i][j] == -1) {
                    continue;
                }

                // 行けるところのコスト (iまでの距離+そこからの距離) を探す
//                cout << "src:" << i << " dst:" << j << " cost:" << a[i][j] << " total:" << done[i] + a[i][j] << endl;

                // 今のnext_costよりもtotalcostが小さければ、次のノードにしたい
                if ((done[i] + a[i][j]) < next_cost) {
                    next_cost = done[i] + a[i][j];
                    next_node = j;
                }
            }
        }
//        cout << "iter:" << r << endl;
//        cout << "next_node:" << next_node << endl;
//        cout << "next_cost:" << next_cost << endl;
        done[next_node] = next_cost;
    }

    for (int i = 0; i < n; ++i) {
        cout << i << " " << done[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    string n;
    cin >> n;
    long long ans = 0;
    bool flag = false;
    for(long long i=0;i<n.length();i++){
        int x = stoi(n.substr(i,1));
        if(i==0){
            ans+=x;
        }else{
        if(flag == false){
            if(x!=9){
                ans+=8;
                flag = true;
            }else{
                ans+=x;
            }
        }else{
            ans+=9;
        }
        }
        }
        cout << ans << endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define INF 1e12
typedef long long ll;

ll find_min(ll x, ll s1, ll s2, ll t1, ll t2) {
	//cout << s1 << " " << s2 << " " << t1 << " " << t2 << endl;
	ll a[8] = {s1, s1, s2, s2, t1, t1, t2, t2};
	ll b[8] = {t1, t2, t1, t2, s1, s2, s1, s2};

	ll mi = INF;
	rep(i,8) {
		mi = min(mi, abs(a[i]-x)+abs(b[i]-a[i]));
	}

	return mi;
}

int main(){
	int a,b,q;
	cin >> a >> b >> q;
	vector<ll> s,t,xs;

	rep(i,a) {
		ll x;
		cin >> x;
		s.push_back(x);
	}

	rep(i,b) {
		ll x;
		cin >> x;
		t.push_back(x);
	}

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());

	rep(i,q) {
		ll x;
		cin >> x;
		ll s1,s2,t1,t2;
		auto it_s1 = lower_bound(s.begin(), s.end(), x);
		if (it_s1 >= s.end()) { 
			s1 = INF;
		} else if (it_s1 < s.begin()) {
			s1 = -1 * INF;
		} else {
			s1 = *it_s1;
		}
		auto it_s2 = it_s1 - 1;
		if (it_s2 >= s.end()) {
			s2 = INF;
		}else if (it_s2 < s.begin()) {
			s2 = -1 * INF;
		}  else {
			s2 = *it_s2;
		}

		auto it_t1 = lower_bound(t.begin(), t.end(), x);
		if (it_t1 >= t.end()) {
			t1 = INF;
		}else if (it_t1 < t.begin()) {
			t1 = -1 * INF;
		}  else {
			t1 = *it_t1;
		}
		auto it_t2 = it_t1 - 1;
		if (it_t2 >= t.end()) {
			t2 = INF;
		}else if (it_t2 < t.begin()) {
			t2 = -1 * INF;
		}  else {
			t2 = *it_t2;
		}

		
		cout << find_min(x, s1,s2,t1,t2) << endl;
	}
}



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

int main() {
  int x, y;
  cin >> x >> y;
  if (2*x <= y && y <= 4*x && y%2 == 0) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int odd = 0;
        for (int i = 0; i < N; ++i) {
            int a = sc.nextInt();
            if (a % 2 != 0) {
                ++odd;
            }
        }
        if (odd % 2 == 1) {
            if (N == 1) {
                _out.println("YES");
            } else {
                _out.println("NO");
            }
        } else {
            _out.println("YES");
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 48584