akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
    public static void main(String args[]){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line;
            while((line=br.readLine())!=null){  if(line.equals(""))break;
                String[] splited = line.split(",");
                double xa=Double.parseDouble(splited[0]),ya=Double.parseDouble(splited[1]);
                double xb=Double.parseDouble(splited[2]),yb=Double.parseDouble(splited[3]);
                double xc=Double.parseDouble(splited[4]),yc=Double.parseDouble(splited[5]);
                double xd=Double.parseDouble(splited[6]),yd=Double.parseDouble(splited[7]);
                gra=(yc-ya)/(xc-xa);y0=ya;x0=xa;
                boolean check1;
                check1=linemaker(xb,yb)*linemaker(xd,yd)<0;
      if(!check1){System.out.println("NO");continue;}
      gra=(yd-yb)/(xd-xb);y0=yb;x0=xb;
                boolean check2=linemaker(xa,ya)*linemaker(xc,yc)<0;
                if(check2)System.out.println("YES");else System.out.println("NO");
                
            }         
        }catch(Exception e){e.printStackTrace();}        
    }
    static double gra=0,y0=0,x0=0;
    static double linemaker(double x1, double y1){
        return y1-y0-(gra*(x1-x0));
    }
}

Measured memory_bytes: 15088
#include<bits/stdc++.h>
using namespace std;
long N,M,K;
long D[20];
int roomlump[110];
long v[105][105];
long long dist[1<<17],INF=2000;
queue<long long> que;

int main(){
  cin>>N>>M>>K;
  fill(roomlump,roomlump+110,-1);

  for(int i=0;i<M;i++){
    cin>>D[i];
    D[i]--;
    roomlump[D[i]]=i;
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<K;j++){
      cin>>v[i][j];
      v[i][j]--;
    }
  }
  long long initial=((1<<M)-1);
  fill(dist,dist+(1<<M),INF);
  que.push(initial);
  dist[(1<<M)-1]=0;

  while(!que.empty()){
    long long current = que.front();
    que.pop();
    for(int j=0;j<K;j++){
      long long next=0;
      for(int i=0;i<M;i++){
        if((current)&(1<<i)){
          if(roomlump[v[D[i]][j]]!=-1){
            next |= 1<<(roomlump[v[D[i]][j]]);
          }
        }
      }
      if(dist[next]>dist[current]+1){
        dist[next]=dist[current]+1;
        if(next!=0) que.push(next);
      }
    }
  }
  cout<<dist[0]<<endl;
  return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll A,B;
  cin >> A >> B;

  ll g = __gcd(A,B);
  ll l = A/g*B;
  cout << l << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int H; int W; cin >> H >> W;
    int ar[H][W];
    int holes[H][W];
    char temp;
    for(int i=0;i<H;i++){
        for(int j = 0;j<W;j++){
            cin >> temp;
            if(temp=='#'){
                ar[i][j] = 1;
            }
            else{
                ar[i][j] = 0;
            }
        }
    }
    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++){
            if(i==0&&j==0){
                holes[i][j]=0;
            }
            else if(i==0){
                holes[i][j] = holes[i][j-1]+abs(ar[i][j]-ar[i][j-1]);
            }
            else if(j==0){
                holes[i][j] = holes[i-1][j]+abs(ar[i][j]-ar[i-1][j]);
            }
            else{
                holes[i][j] = min(holes[i-1][j]+abs(ar[i][j]-ar[i-1][j]),holes[i][j-1]+abs(ar[i][j]-ar[i][j-1]));
            }
        }
    }
    if(holes[H-1][W-1]%2 == 1){
        cout << (holes[H-1][W-1]+1)/2;
    }
    else{
        if(ar[0][0]==0){
            cout << holes[H-1][W-1]/2;
        }
        else{
            cout << 1+(holes[H-1][W-1]/2);
        }
    }
    return 0;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef long long ll;

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

int f[maxn][maxn];
int n, k;
int a[maxn];

bool ok(int id){
  for (int i = 0; i <= n; ++i) for (int j = 0; j <= k; ++j)
    f[i][j] = 0;

  f[0][0] = 1;
  for (int i = 1; i <= n; ++i){
    for (int val = 0; val <= k; ++val) f[i][val] |= f[i-1][val];
    if (i == id) continue;
    for (int val = a[i]; val <= k; ++val){
      f[i][val] |= f[i-1][val-a[i]];
    }
  }

  for (int val = 1; val <= k; ++val) f[n][val] += f[n][val-1];
  int l = max(0, k - a[id]), r = k - 1;
  if (l == 0) return f[n][r] == 0;
  return (f[n][r] - f[n][l-1]) == 0;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i){
    cin >> a[i];
  }

  sort(a + 1, a + n + 1);
  int l = 1, r = n;
  while (l <= r){
    int mid = (l + r) / 2;
    if (ok(mid)) l = mid + 1;
    else r = mid - 1;
  }
  cout << l - 1;
}




Measured memory_bytes: 98176
#include<iostream>
#include<utility>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>
#define m 102
#define mod 1000000007
#define ll long long int
using namespace std;
ll k[101][100001]={0};
ll knap(int n,int W,vector<ll> v,vector<ll> wt){
	for(int i=0;i<=n;i++){
		for(int w=0;w<=W;w++){
			if(i==0 || w==0){
				k[i][w]=0;
			}
			else if(wt[i-1]<=w){
				k[i][w]=max(v[i-1]+k[i-1][w-wt[i-1]],k[i-1][w]);
			}
			else{
				k[i][w]=k[i-1][w];
			}
		}
	}
	return k[n][W];
}
int main(){
	ll n=0,W=0,a=0,b=0;
	cin >> n >> W;
	vector<ll> v;
	vector<ll> wt;
	memset(k,0,sizeof(k));
	for(int i=0;i<n;i++){
		cin >> a >> b;
		wt.push_back(a);
		v.push_back(b);	
	}
	ll val=knap(n,W,v,wt);
	cout << val;
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc089_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
                             const Iterator last) {
  /* Credits: Thomas Draper */
  if ((first == last) || (first == k) || (last == k)) return false;
  Iterator itr1 = first;
  Iterator itr2 = last;
  ++itr1;
  if (last == itr1) return false;
  itr1 = last;
  --itr1;
  itr1 = k;
  --itr2;
  while (first != itr1) {
    if (*--itr1 < *itr2) {
      Iterator j = k;
      while (!(*itr1 < *j)) ++j;
      iter_swap(itr1, j);
      ++itr1;
      ++j;
      itr2 = k;
      rotate(itr1, j, last);
      while (last != j) {
        ++j;
        ++itr2;
      }
      rotate(k, itr2, last);
      return true;
    }
  }
  rotate(first, k, last);
  return false;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  map<char, ll> m;
  rep(i, N) {
    string s;
    cin >> s;
    m[s[0]]++;
  }

  ll ans = 0;
  string a = "MARCH";
  rep(i, a.size() - 2) {
    repi(j, i + 1, a.size() - 1) {
      repi(k, j + 1, a.size()) {
        ans += m[a[i]] * m[a[j]] * m[a[k]];
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli a,b;

int main(){
  cin >> a >> b;
  if(b >= a) cout << a << endl;
  else cout << a-1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main(){
	LL n,ans=0;scanf("%lld",&n);
	if(n&1)return putchar('0'),0;
	n/=2;while(n)n/=5,ans+=n;
	printf("%lld",ans);
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int xored = 0;
	int a[n];
	for (auto &i : a) i = ri(), xored ^= i;
	
	for (auto i : a) printf("%d ", i ^ xored);
	puts("");
	return 0;
}


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

ll inf=1ll<<60,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,k,a[100],ans=0,i;
	cin>>n>>k;
	for (i=0;i<n;i++){
		cin>>a[i];
	}
	for (i=0;i<n;i++){
		ans+=2*min(abs(k-a[i]),a[i]);
	}
	cout<<ans;
	return 0;
}

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

int main(){
  int a,b,k,x;
  cin >> k >> a >> b;
  for(int i = a/k; k*i <= b; i++){
    if((k*i >= a) && (k*i <= b)){
      cout<<"OK";
      return 0;
    }
  }
  cout<<"NG";
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,c; cin>>a>>b>>c;
    int ans;
    ans=min(a+b,min(b+c,c+a));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#define rep(i, n) for (int i=0; i<n; ++i)
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    string s, s1, s2;
    cin >> n;
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    cin >> s;
    s1 = s.substr(0, n/2);
    s2 = s.substr(n/2);
    if(s1 == s2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
int main()
{
  int n,k,x,y;
  scanf("%d%d%d%d",&n,&k,&x,&y);
  int ans;
  if(n<=k)
  {
    ans=n*x;
    printf("%d",ans);
  }
  
  else
  {
    ans= x*k + (n-k)*y;
    printf("%d",ans);
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

const int AA = 10;
ll dp[1 << AA][100005];

void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> v(n), w(n);
    int i,j;
    for (i = 0; i < n; i++) {
        scanf("%d%d", &v[i], &w[i]);
    }

    int Q;
    scanf("%d", &Q);
    vector<int> vv(Q), L(Q);
    for (i = 0; i < Q; i++) {
        scanf("%d%d", &vv[i], &L[i]); vv[i]--;
    }

    int m = MIN(1 << AA, n);
    for (i = 0; i < m; i++) {
        int p = (i + 1) / 2 - 1;
        for (j = 0; j <= 100000; j++) {
            if (i == 0) {
                dp[i][j] = 0;
            }
            else {
                dp[i][j] = dp[p][j];
            }
            int j2=j - w[i];
            if (j2 >= 0) {
                if (p >= 0) {
                    dp[i][j] = MAX(dp[i][j], dp[p][j2] + v[i]);
                }
                else {
                    dp[i][j] = MAX(dp[i][j], v[i]);
                }
            }
            if(j>0) dp[i][j] = MAX(dp[i][j], dp[i][j - 1]);
        }
    }

    for (i = 0; i < Q; i++) {
        if (vv[i] < (1 << AA)) {
            printf("%lld\n", dp[vv[i]][L[i]]);
        }
        else {
            ll ans = 0;
            int tmp=vv[i] + 1;
            vector<int> v0;
            while (tmp > (1 << AA)) {
                v0.push_back(tmp-1);
                tmp /= 2;                
            }
            int p = tmp - 1;
            int siz = (int)v0.size();
            int k;
            for (k = 0; k < (1 << siz); k++) {
                int sum = 0;
                ll sumv = 0;
                int kk;
                int bad = 0;
                for (kk = 0; kk < siz; kk++) {
                    if (k & (1 << kk)) {
                        sum += w[v0[kk]];
                        sumv += v[v0[kk]];
                        if (sum > L[i]) {
                            bad = 1;
                            break;
                        }
                    }
                }
                if (bad) {
                    continue;
                }
                if (sum <= L[i]) {
                    int tt=L[i] - sum;
                    ll ans0=dp[p][tt] + sumv;
                    ans = MAX(ans, ans0);
                }
            }
            printf("%lld\n", ans);
        }
    }

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

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


void solve(long long A, long long B, long long C, long long D){
    cout << min(A, B) + min(C, D) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  string s;
  cin >> s;
  if(s[s.length()-1]=='s'){
    cout << s << "es" << endl;
  }else{
    cout << s << "s" << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

LL d,p10[20];
int ans;

map<pair<pii,LL>,int> m;
int dfs(int l,int r,LL y)
{
	if(y>=p10[r+1]||y<=-p10[r+1])return 0;
	if(m[mp(mp(l,r),y)])return m[mp(mp(l,r),y)]-1;
	if(l>r)return y==0;
	if(l==r)return (y==0)*10;
	int ret=0;
	if(l==0)
	{
		for(int tl=1;tl<=9;tl++)for(int tr=1;tr<=9;tr++)
			ret+=dfs(l+1,r-1,y+p10[l]*tl+p10[r]*tr-p10[l]*tr-p10[r]*tl);
	}
	else
	{
		for(int tl=0;tl<=9;tl++)for(int tr=0;tr<=9;tr++)
			ret+=dfs(l+1,r-1,y+p10[l]*tl+p10[r]*tr-p10[l]*tr-p10[r]*tl);
	}
	m[mp(mp(l,r),y)]=ret+1;
	return ret;
}
int main()
{
	p10[0]=1;for(int i=1;i<19;i++)p10[i]=p10[i-1]*10;
	get1(d);
	for(int i=1;i<18;i++)ans+=dfs(0,i,d);
	printendl(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();

        int[] cnt = new int[100005];
        for (int i = 0; i < N; i++) {
            cnt[sc.nextInt()]++;
        }

        long sum = 0;
        for (int j = 0; j < 100005; j++) {
            sum += j * cnt[j];
        }

        int Q = sc.nextInt();
        for (int i = 0; i < Q; i++) {
            int before = sc.nextInt();
            int after = sc.nextInt();
            cnt[after] += cnt[before];
            sum += after * cnt[before] - before * cnt[before];
            cnt[before] = 0;
            System.out.println(sum);
        }
        sc.close();

    }
}


Measured memory_bytes: 59864
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cout << fixed << setprecision(15);

  ll N, M;
  cin >> N >> M;

  priority_queue<ll> A;

  for (ll i = 0; i < N; i++) {
    ll a;
    cin >> a;
    A.push(a);
  }

  for (ll i = 0; i < M; i++) {
    ll t = A.top();
    A.pop();
    A.push(t / 2);
  }

  ll ans = 0;
  while (!A.empty()) {
    ll a = A.top();
    ans += a;
    A.pop();
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	ll a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >>n;
    int p[n];
    int same=0;
    int twins=0;
    for (int i=0; i<n; i++){
        cin >>p[i];
        p[i]--;
    }
    int ans=0;
    int count=0;
    for (int i=0; i<n; i++){
        if (p[i]==i){
            count++;
        }else{
            ans+=(count+1)/2;
            count=0;
        }
    }
    ans+=(count+1)/2;
    cout << ans <<endl;
}
    


    

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

if n%10 == 0 and n != 10:
    print(10)
else:
    a,b = 1,0
    sA, sB= 0,0
    soma = []

    while a<=n:
        b=n-a

        for i in str(a):
            sA+=int(i)
        for j in str(b):
            sB+=int(j)
        soma.append(sA+sB)
    
        a=a+1
    print(min(soma))


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

using namespace std;
typedef long long ll;

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

    int opt = pow(2,n);

    vector<int> vals(opt, numeric_limits<int>::max());
    for(int i=0; i < m; i++) {
        int a,b;
        cin >> a >> b;

        int ind = 0;
        for(int j=0; j < b; j++) {
            int val;
            cin >> val;
            ind |= 1<<(val-1);
        }

        vals[ind] = min(a, vals[ind]);
    }

    for(int i=0; i < opt; i++) {
        for(int j=0; j < opt; j++) {
            if(vals[i] == numeric_limits<int>::max() || vals[j] == numeric_limits<int>::max()) continue;
            if(i == j) continue;
            vals[i|j] = min(vals[i|j], vals[i] + vals[j]);
        }
    }

    if(vals[opt-1] == numeric_limits<int>::max()) cout << -1;
    else cout << vals[opt-1];
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> s(n+1);
  for(ll i=0;i<n;i++) {
    ll temp;
    cin >> temp;
    s[i+1]=s[i]+temp;
  }
  map<ll,ll> ans;
  for(ll i=0;i<=n;i++) {
    ans[s[i]]++;
  }
  ll out=0;
  for (auto p: ans) {
    ll temp=p.second;
    out+=temp*(temp-1)/2;
  }
  cout << out << endl;
}

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

using namespace std;

struct Query
{
    int a, b, c, d;
    Query(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}
};

// 繰り上がりみたいに考える
void next_v(vector<int> &v, int M)
{
    int s = v.size();
    v[s - 1]++;
    for (int i = s - 1; i >= 1; i--)
    {
        if (v[i] == M + 1)
        {
            v[i] = 1;
            v[i - 1]++;
        }
        else
        {
            break;
        }
    }
    for (int i = 1; i < s; i++)
    {
        if (v[i - 1] > v[i])
            v[i] = v[i - 1];
    }
}

int get_score(vector<int> &v, vector<Query> &vq)
{
    int score = 0;
    for (Query q : vq)
    {
        if (v[q.b - 1] - v[q.a - 1] == q.c)
            score += q.d;
    }
    return score;
}

signed main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<Query> vq;
    for (int i = 0; i < Q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        vq.push_back(Query(a, b, c, d));
    }

    vector<int> v(N, 1);

    int ans = 0;
    while (true)
    {
        ans = max(get_score(v, vq), ans);
        // for (int x : v)
        // {
        //     cout << x << " ";
        // }
        // cout << endl;
        if (v[0] == M)
            break;
        next_v(v, M);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
/// I won't go back on my word, that's my ninja way!
#include<bits/stdc++.h>
using namespace std;
const int N = 2e3+5 ,mod = 1e9+7 ;
int n ,k ,mem[N][N] ,mem2[N][N] ;
int solve(int red,int blue){
    if(red<0 || blue<0)return 0;
    if(red==0 && blue<=1)return 1;
    if(red==0)return 0;
    int&ret=mem[red][blue];
    if(~ret) return ret;
    return ret = (solve(red-1,blue) + solve(red-1,blue-1))%mod;
}
int solve2(int i,int rem){
    if(rem<0) return 0;
    if(i==0) return rem==0 ;
    int&ret=mem2[i][rem];
    if(~ret)return ret;
    return ret = (solve2(i-1,rem) + solve2(i,rem-1))%mod;
}
int main(){
    scanf("%d%d",&n,&k);
    memset(mem,-1,(n+1)*sizeof mem[0]);
    memset(mem2,-1,(n+1)*sizeof mem2[0]);
    for(int i=1;i<=k;++i){
        int rem = k - i ;
        int ways = solve2(i,rem);

        int red = n - k ;
        int blue = i ;

        int cnt = solve(red,blue);
        printf("%d\n" ,1ll*cnt*ways%mod);
    }
    return 0 ;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i < n; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    int a[210], cnt = 0;
    rep(i, 0, n){
        cin >> a[i];
    }
    while(1){
        bool flag = false;
        for(int i = 0; i < n; i++){
            if(a[i] % 2 != 0) flag = true;
        }
        if(flag) break;
        for (int i = 0; i < n; i++){
            a[i] /= 2;
        }
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

template<typename T>
struct Dijkstra {
  int n;
  WeightedGraph<T> es;
  vector<T> dist;
  vector<int> prev;
  Dijkstra(int _n, WeightedGraph<T> _es) {
    init(_n, _es);
  }
  void init(int _n, WeightedGraph<T> _es) {
    n = _n; es = _es;
  }
  void reset() {
    dist.assign(n, inf);
    prev.assign(n, -1);
  }
  void run(int s) {
    reset();
    dist[s] = 0;
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(P(0, s));
    while (!pq.empty()) {
      P p = pq.top(); pq.pop();
      T v = p.second;
      if (dist[v] < p.first) continue;
      for (int i=0; i<(int)es[v].size(); i++) {
        edge<T> e = es[v][i];
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          pq.push(P(dist[e.to], e.to));
          prev[e.to] = v;
        }
      }
    }
  }
  vector<int> getpath(int t) {
    vector<int> path;
    if (dist[t] == inf) return path;
    for (; t!=-1; t=prev[t]) path.push_back(t);
    reverse(path.begin(), path.end());
    return path;
  }
};

int main()
{
  int n; cin>>n;
  WeightedGraph<ll> g(n);
  rep(i, n-1) {
    int a,b,c; cin>>a>>b>>c; a--; b--;
    g[a].push_back(edge<ll>(b, c));
    g[b].push_back(edge<ll>(a, c));
  }
  int q,k; cin>>q>>k; k--;
  Dijkstra<ll> dij(n, g);
  dij.run(k);
  vector<ll> ans(q);
  rep(i, q) {
    int x, y; cin>>x>>y; x--; y--;
    ans[i] = dij.dist[x] + dij.dist[y];
  }
  rep(i, q) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 28672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    int n,sum,ans=0;
    cin>>n;
    int a[2][n];
    rep(i,2)rep(j,n)cin>>a[i][j];

    rep(i,n){
        sum=0;
        rep(j,n) if(i==j) sum+=a[0][j]+a[1][j]; else if(j<i)sum+=a[0][j]; else sum+=a[1][j];
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define mp make_pair
using namespace std;
int mod=1e9+7;
int add(int a,int b)
{
    return (a%mod+b%mod)%mod;
}
int mul(int a,int b)
{
    return (a%mod*b%mod)%mod;
}
int32_t main() {
	// your code goes here

	  //cout<<"Case #"<<x++<<":\n";
	 int n,m,i,j,k;
	cin>>n;
	vi a(n),pre(n);
	for(i=0;i<n;i++)
	cin>>a[i];
	 pre[n-1]=a[n-1];
	 for(i=n-2;i>=0;i--)
	 pre[i]=add(pre[i+1],a[i]);
	 int sum=0;
	 for(i=0;i<n-1;i++)
	 sum=add(sum,mul(a[i],pre[i+1]));
	cout<<sum<<"\n";
	
	return 0;
}


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



void solve(long long N){
    if(N%1000 == 0)
        cout << 0 << endl;
    else
        cout << 1000-N%1000 << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;


int main(void) {

    int N;
    cin >> N ;
    int P[N];
    int ans = 0;
    int mn = 200001;
    rep(i, N) {
        cin >> P[i];
        if(mn >= P[i]) {
            ans++;
            mn = min(mn, P[i]);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define INF 2000000001
int main(){
  int n,m,l,k,s,t;
  while(cin>>n>>m>>l>>k>>s>>t,n){
    int lt[111];
    int d[111][111];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(i==j)d[i][j]=0;
	else d[i][j]=INF;
  
    for(int i=0;i<l;i++)cin>>lt[i];
    for(int i=0;i<k;i++){
      int x,y,z;
      cin>>x>>y>>z;
      d[x][y]=z;
      d[y][x]=z;
    }

    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  if(d[i][k]!=INF&&d[k][j]!=INF)
	    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    if(d[s][t]<=m){
      cout<<d[s][t]<<endl;
    }else{
    int d2[111][111];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(i==j)d2[i][j]=0;
	else d2[i][j]=INF;

    for(int i=0;i<l;i++){
      if(d[s][lt[i]]<=m){
	d2[s][lt[i]]=d[s][lt[i]];
	d2[lt[i]][s]=d[s][lt[i]];
      }
      if(d[t][lt[i]]<=m){
	d2[t][lt[i]]=d[t][lt[i]];
	d2[lt[i]][t]=d[t][lt[i]];
      }
    }
    for(int i=0;i<l;i++)
      for(int j=0;j<l;j++)
	if(d[lt[i]][lt[j]]<=m){
	  d2[lt[i]][lt[j]]=d[lt[i]][lt[j]];
	  d2[lt[j]][lt[i]]=d[lt[i]][lt[j]];
	}
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  if(d2[i][k]!=INF&&d2[k][j]!=INF)
	    d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
  
    if(d2[s][t]==INF)cout<<"Help!"<<endl;
    else cout<<d2[s][t]*2-m<<endl;
    }
  }
  return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> P(N),Q(N);

    for (int i = 0; i < N; i++) {
        cin >> P.at(i);
        Q.at(i) = P.at(i);
    }

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

    int s = 0;

    for (int i = 0; i < N; i++) {
        if (P.at(i) != Q.at(i)) {
            s++;
        }
    }

    if (s == 0 || s == 2) {
        cout << "YES" << endl;
    }

    else {
        cout << "NO" << endl;
    }


}

Measured memory_bytes: 256
from itertools import permutations
import sys
import gc
def main():
    N, M, R = map(int, input().split())
    rs = [x - 1 for x in map(int, input().split())]
    # グラフを作る
    dist = [[float('inf')] * (N) for _ in range(N)]
    for e in sys.stdin:
        A, B, C = map(int, e.split())
        dist[A - 1][B - 1] = dist[B - 1][A - 1] = C
    # ワーシャルフロイドで全頂点間距離算出
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    # 組み合わせ全探索
    ans = float('inf')
    for p in permutations(rs):
        tmp = 0
        for u, v in zip(p, p[1:]):
            tmp += dist[u][v]
            if tmp > ans:
                break
        else:
            ans = tmp
    print(ans)
if __name__ == '__main__':
    gc.disable()
    main()

Measured memory_bytes: 4688
a,b=map(int,input().split())
if(a<b):
    A=str(a)
    for i in range (0,b-1):
        A=A+str(a)
    print(A)
else:
    B=str(b)
    for i in range(0,a-1):
        B=B+str(b)
    print(B)

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

using namespace std;
#define ff(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define rep(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define fd(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define SZ(x) ((int)(x).size())
#define db(x) cout << #x << " == " << x << endl
#define _ << ", " << 
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define endl '\n'
#define pc putchar
#define gc getchar 
#define bit(i) (1<<(i))

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

const int N=1e5+5;
int n,a[N];

void enter(){
	cin>>n;
	ff(i,1,n) cin>>a[i];
}

void process(){
	int ans=0;
	ff(i,1,n-1){
		if (a[i]==i) {
			++ans;
			swap(a[i],a[i+1]);
		}
	}
	if (a[n]==n) ++ans;
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	//freopen("test.inp","r",stdin);
	//freopen("test.out","w",stdout);

	enter();
	process();	

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_bit(n) for (int bit = 0; bit < (1<<n); ++bit)
#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define SP <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> Graph;

//条件式 ? 真の場合の文 : 偽の場合の文
//abs(x) = (x の絶対値)
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//swap(a, b)
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換
int main(){

    int n;
    cin >> n;
    vl a(n);
    rep(i,n) cin >> a.at(i);
    map<ll,ll> mp;
    ll ans = 0;
    rep(i,n){
        ll sa = i - a.at(i);
        if(mp.count(sa)) ans += mp.at(sa);
        ll wa = a.at(i)+i;
        mp[wa]++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 17028
from collections import defaultdict
from heapq import heappop, heappush
 
class Graph(object):
    """
    隣接リストによる有向グラフ
    """
 
    def __init__(self):
        self.graph = defaultdict(list)
 
    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))
 
 
class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """
 
    def __init__(self, graph, start):
        self.g = graph.graph
 
        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0
 
        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)
 
        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))
 
        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))
 
    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]
 
def main():
    n, m= map(int,input().split())
    g = Graph()
 
    inputs = [0]*m
 
    for i in range(m):
        lst = [int(i) for i in input().split()]
        inputs[i]=lst
        g.add_edge(lst[0], lst[1],lst[2])
        g.add_edge(lst[1], lst[0],lst[2])
 
    lst = [[0 for i in range(n+1)] for j in range(n+1)]
    for i in range(1,n+1):
        for j in range(1,n+1):
            if i != j and lst[j][i] == 0:
                d = Dijkstra(g,i)
                lst[i][j] = d.shortest_distance(j)
 
    #print(lst)
    #print(inputs)
 
    ans = 0
    for i in range(m):
        if lst[min(inputs[i][0],inputs[i][1])][max(inputs[i][0],inputs[i][1])] < inputs[i][2]:
            ans+=1
 
    print(ans)
 
if __name__ == "__main__":
        main()

Measured memory_bytes: 85980
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    int A[5];
    cin >> A[0];
    cin >> A[1];
    cin >> A[2];
    cin >> A[3];
    cin >> A[4];

    int time = 999999;
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            for(int k = 0; k < 5; k++)
            {
                for(int m = 0; m < 5; m++)
                {
                    for(int n = 0; n < 5; n++)
                    {
                        int sub = 0;
                        if(i!=j and i!=k and i!=m and i!=n and
                           j!=k and j!=m and j!=n and
                           k!=m and k!=n and
                           m!=n)
                        {
                            sub += A[i];
                            if(sub % 10 != 0)
                            {
                                sub /= 10;
                                sub += 1;
                                sub *= 10;
                            }
                            sub += A[j];
                            if(sub % 10 != 0)
                            {
                                sub /= 10;
                                sub += 1;
                                sub *= 10;
                            }
                            sub += A[k];
                            if(sub % 10 != 0)
                            {
                                sub /= 10;
                                sub += 1;
                                sub *= 10;
                            }
                            sub += A[m];
                            if(sub % 10 != 0)
                            {
                                sub /= 10;
                                sub += 1;
                                sub *= 10;
                            }
                            sub += A[n];

                            time = min(time, sub);
                        }//ifend
                    }
                }
            }
        }
    }

    cout << time << endl;

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string IntToString(int number) {
    stringstream ss;
    ss << number;
    return ss.str();
}

int main(){
    int n;
    string s;
    while(cin >> n, n){
        cin >> s;
        rep(i, n){
            string t;
            rep(j, s.size()){
                int count = 0;
                int idx = j;
                for(int k=j; k < s.size(); k++, j++){
                    if(s[idx] == s[k]) count++;
                    else break;
                }
                t += IntToString(count) + s[idx];
                j--;
            }
            s = t;
        }
        cout << s << endl;
    }
}

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

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

#define EACH(it, que) for (auto it = que.begin(); it != que.end(); ++it)

typedef pair<ll, ll> pll;
// const ll INF = (ll)1e18;

struct P { string name; int time; };

signed main() {
	queue<P> que, res;
	int n, q;
	cin >> n >> q;
	REP (i, n) {
		P p;
		cin >> p.name >> p.time;
		que.push(p);
	}

	int t = 0;
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		p.time -= q;
		t += q;
		if (p.time <= 0) {
			int tt = p.time;
			p.time += t;
			t += tt;
			res.push(p);
		} else {
			que.push(p);
		}
	}

	while (!res.empty()) {
		P e = res.front();
		cout << e.name << " " << e.time << endl;
		res.pop();
	}
}

Measured memory_bytes: 6112
import java.util.Scanner;

public class Main {
    static int w, h;
    static int[][] map;
    static int c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            w = sc.nextInt();
            h = sc.nextInt();
            if ((w | h) == 0) {
                break;
            }
            map = new int[h][w];
            int sx = 0;
            int sy = 0;
            c = 0;
            for (int i = 0; i < h; i++) {
                String line = sc.next();
                for (int j = 0; j < w; j++) {
                    if (line.charAt(j) == '@') {
                        sy = i;
                        sx = j;
                        map[i][j] = 0;
                    } else {
                        map[i][j] = line.charAt(j) == '.' ? 0 : 1;
                    }
                }
            }
            dfs(sy, sx);
            System.out.println(c);
        }
    }

    public static void dfs(int y, int x) {
        if (y < 0 || y >= h || x < 0 || x >= w) {
            return;
        }
        if (map[y][x] == 1) {
            return;
        }
        map[y][x] = 1;
        int[] d = new int[] { 0, 1, 0, -1, 0 };
        for (int i = 0; i < 4; i++) {
            dfs(y + d[i], x + d[i + 1]);
        }
        c++;
    }

}

Measured memory_bytes: 39944
#!/usr/bin/env python3

N = int(input())
x = [None] * N
u = [None] * N
for i in range(N):
    x[i], u[i] = input().split()
    x[i] = float(x[i]) if u[i] == 'JPY' else float(x[i]) * 380000.0
print(sum(x))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
 
int main() {
  char* str;
  str = (char*)malloc(sizeof(char) * 200000);
  long i, length;
  long start;
  scanf("%s%*c", str);
  for (i = 0; i < strlen(str); i++) {
    if (str[i] == 'A') {
      start = i;
      break;
    }
  }
  for (; i < strlen(str); i++) {
    if (str[i] == 'Z') {
      length = i - start + 1;
    }
  }
  printf("%ld\n", length);
  free(str);
  return 0;
}



Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
			final List<Integer> vList = Arrays.stream(args.get(1).split(" ")).map(Integer::valueOf).collect(Collectors.toList());
			final List<Integer> cList = Arrays.stream(args.get(2).split(" ")).map(Integer::valueOf).collect(Collectors.toList());
			int ans = 0;
			for (int i = 0; i < vList.size(); i++) {
				ans += Math.max(0, vList.get(i) - cList.get(i));
			}
			System.out.println(ans);
        };
    }

}


Measured memory_bytes: 28616
import java.util.Scanner;

//AtCoder Beginner Contest 160
// B - Golden Coins
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();
		int ans = 0;
		ans += (X/500) * 1000;
		X = X%500;
		ans += X/5 * 5;

		System.out.println(ans);
	};
}


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

int main() {
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int dp[n+1];
  dp[0]=0;
  dp[1]=0;
  for(int i=2;i<=n;i++){
    if(s[i-2]=='A' && s[i-1]=='C') dp[i]=dp[i-1]+1;
    else dp[i]=dp[i-1];
  }
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    cout<<dp[r]-dp[l]<<endl;
  }
}


Measured memory_bytes: 1408
<?php

fscanf(STDIN, '%d %d %d', $N, $M, $C);
$bArray = explode(' ', trim(fgets(STDIN)));

$ans = 0;
for ($i = 0; $i < $N; $i++) {
    $aArray = explode(' ', trim(fgets(STDIN)));

    $sum = 0;
    for ($j = 0; $j < $M; $j++) {
        $sum += $aArray[$j] * $bArray[$j];
    }

    if (($sum + $C) > 0) {
        $ans++;
    }
}

echo $ans . PHP_EOL;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    cout << x * min(k,n) + y * max(0, n-k) << endl;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        if(input.length() == 2){
            System.out.println(input);
        }else{
            String first = input.substring(0,1);
            String second = input.substring(1,2);
            String third = input.substring(2,3);
            System.out.println(third + second + first);
        }
        
    }
}


Measured memory_bytes: 23764
/*input
serval
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
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> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> a;

int mdf(){
	vector<int> v;
	int ret=0;

	{
		bool f=0;
		REP(i,SZ(a)) if(a[i]) f=1;
		if(!f) return INF;
	}
	{
		bool f=0;
		REP(i,SZ(a)) if(!a[i]) f=1;
		if(!f) return 0;
	}

	while(SZ(a)){
		v.clear();
		REP(i,SZ(a)-1){
			v.pb(a[i]||a[i+1]);
		}
		a=v;
		ret++;

		{
			bool f=0;
			REP(i,SZ(a)) if(!a[i]) f=1;
			if(!f) return ret;
		}
	}
	return INF;
}

int main(){
	IOS;
	string s;
	cin>>s;
	int ans=INF;
	REP(i,26){
		a.clear();
		REP(j,SZ(s)) a.pb(s[j]=='a'+i);

		ans=min(ans,mdf());
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define M_PI           3.14159265358979323846
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin>>n>>m;
	ll a[m];
	ll s=0;
	for(int i=0;i<m;i++)
	{
	cin>>a[i];s+=a[i];}
	if(s>n)cout<<-1;
	else
		cout<<n-s;
	
}

Measured memory_bytes: 3692