akhauriyash/Code-Regression huggingface dataset:
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=1e5;
int mm[N];

int main(){	
	fastio;
	int n;cin>>n;
	int lim=(1<<n);
	FER(i,0,n)cin>>mm[i];
	FER(i,0,n){
		int k;cin>>k;
		mm[i]-=k;
	}
	int ans=0;
	FER(i,0,lim){
		int val=0;
		FER(j,0,n)if((i>>j)&1)val+=mm[j];
		ans=max(ans,val);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(int argc, char *argv[]){
  int m, n, from, to;
  cin >> m >> n;
  queue<int> que;
  vector<vector<int> > in(m);
  vector<vector<int> > out(m);
  for (int i = 0; i < n; i++) {
    cin >> from >> to;
    from--;to--;
    in[to].push_back(from);
    out[from].push_back(to);
  }
  for (int i = 0; i < m; i++) {
    if(in[i].empty()){
      que.push(i);
    }
  }
  vector<int> ans;
  while(!que.empty()){
    int v = que.front();que.pop();
    ans.push_back(v);
    for (int i = 0; i < out[v].size(); i++) {
      int nv = out[v][i];
      for (int j = 0; j < in[nv].size(); j++) {
        if(in[nv][j] == v){
          in[nv].erase(in[nv].begin() + j);
          if(in[nv].empty())que.push(nv);
        }
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    std::cout << ans[i] + 1<< std::endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl

using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> d1(n),d2(n);
  rep(i,n)cin>>d1[i]>>d2[i];
  bool flag=false;
  for(int i=2;i<n;++i){
    if(d1[i]==d2[i]&&d1[i-1]==d2[i-1]){
      if(d1[i-2]==d2[i-2])flag=true;
    }
  }
	if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

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

        int n = sc.nextInt();
        if (n % 10 == (n - (n % 100)) / 100)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <sstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a,b;
  cin>>a>>b;
  int ans;
  if(a >= 13) {
    ans = b;
  } else if(a >= 6) {
    ans = b / 2;
  } else {
    ans = 0;
  } 
  cout << ans << endl;

  return 0;
}


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

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int n; cin >> n;
  vector<int> p(n); rep(i,n){cin >> p[i];}
  int count=0;
  rep(i,n){if(p[i]!=i+1){count++;}}
  if (count == 0 || count == 2){cout << "YES";}
  else {cout << "NO";}

  return 0;
}


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

using namespace std;
using ll = long long int;

int main(void){
  
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++) cin >> a[i];
  
  vector<ll> sum(n);
  
  ll tmp = 0;
  for(int i = 0;i < n;i++){
    tmp += a[i];
    tmp %= 1000000007;
    sum[i] = tmp;
  }
  
  long long int ans = 0;
  
  for(int i = 0;i < n - 1;i++){
    ans += sum[i] * a[i+1];
    ans %= 1000000007;
  }
  
  cout << ans << endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> hs(n);
    for(int i=0; i<n; i++) cin >> hs.at(i);

    int pre = -1;
    string ans = "Yes";
    for(auto &h : hs)
    {
        if(pre < h) h--;
        else if(pre > h)
        {
            ans = "No";
            break;
        }
        pre = h;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10;
int a[M];
vector<int>neg,pos;
vector<pii>ans;
main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	pii maxx=mp(0,0);
	pii minn=mp(0,0);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>maxx.F)
			maxx=mp(a[i],i);
		if(a[i]<minn.F)
			minn=mp(a[i],i);
		if(a[i]<=0)neg.pb(i);
		else pos.pb(i);
	}
	bool flag=1;
	if(maxx.S==0)
		flag=0;
	if(maxx.F>abs(minn.F) && maxx.S!=0 && minn.S!=0)
	{
		for(int i=0;i<neg.size();i++)
		{
			ans.pb(mp(maxx.S,neg[i]));
			a[neg[i]]+=maxx.F;
		}
	}
	else if(maxx.S!=0 && minn.S!=0)
	{
		flag=0;
		for(int i=0;i<pos.size();i++)
		{
			ans.pb(mp(minn.S,pos[i]));
			a[pos[i]]+=minn.F;
		}
	}
	if(flag)
	{
		for(int i=2;i<=n;i++)
		{
			if(a[i]<a[i-1])
				ans.pb(mp(i-1,i)),a[i]+=a[i-1];
		}
	}
	else
	{
		for(int i=n;i>=2;i--)
		{
			if(a[i]<a[i-1])
				ans.pb(mp(i,i-1)),a[i-1]+=a[i];
			}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)cout<<ans[i].F<<" "<<ans[i].S<<endl;
}

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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long s[] = {0,0};
  vector< vector<int> > I(2);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    if(A[i] < 0)
      I[i%2].push_back(i+1);
    else
      s[i%2] += A[i];
  }
  if(*max_element(A.begin(), A.end()) < 0){
    int idx = max_element(A.begin(), A.end()) - A.begin();
    cout << A[idx] << endl << N-1 << endl;;
    ++idx;
    for(int i = N; i > idx; --i) cout << i << endl;
    for(int i = 1; i < idx; ++i) cout << 1 << endl;
    return 0;
  }
  int idx;
  if(s[0] < s[1]) idx = 1;
  else idx = 0;
  bool f = (idx == 1);
  cout << s[idx] << endl;
  vector<int> C;
  while(not I[idx].empty()){
    C.push_back(I[idx].back());
    if(I[idx].back() == N or I[idx].back() == 1) ++N;
    if(I[idx].back() == 1) f = !f;
    N -= 2;
    I[idx].pop_back();
  }
  if(f){
    C.push_back(1);
    --N;
  }
  while(N > 1){
    C.push_back(2);
    N -= 2;
  }
  cout << C.size() << endl;
  for(auto e : C) cout << e << endl;
  return 0;
}


Measured memory_bytes: 384
x=int(input())
if 400 <= x <= 599:
  print(8)
elif 600 <= x <= 799:
  print(7)
elif 800 <= x <= 999:
  print(6)
elif 1000 <= x <= 1199:
  print(5)
elif 1200 <= x <= 1399:
  print(4)
elif 1400 <= x <= 1599:
  print(3)
elif 1600 <= x <= 1799:
  print(2)
elif 1800 <= x <= 1999:
  print(1)
else:
  none

Measured memory_bytes: 9192
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 X = sc.nextInt();

        int t = 0;
        int sum = 0;
        while (sum < X) {
            ++t;
            sum += t;
        }
        _out.println(t);
    }
    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: 21972
#include <stdio.h>

int MIN(int a,int b){return a < b ? a : b;}

int main()
{
    int n,h[200000],i,j,min,ans = 0,left,right;
    scanf("%d",&n);
    for (i = 0; i < n; i++)scanf("%d",&h[i]);

    for(j = 0; j < n; j++)
    {
        for (i = 0; i < n; i++)if(h[i] != 0)break;
        left = i;
        for (i = left; i < n; i++)if(h[i] == 0)break;
        right = i;
        min = h[left];
        for (i = left + 1; i < right; i++)min = MIN(min,h[i]);
        for (i = left; i < right; i++)h[i] -= min;
        ans += min;
    }
    printf("%d",ans);
}

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

int main()

{
	int r, c;
	int s[101][101];
	cin >> r >> c;

	for (int x = 0; x < r; x++)
	{
		for (int y = 0; y < c; y++)
		{
			cin >> s[x][y];
		}
	}

	for (int x = 0; x < r; x++)
	{
		s[x][c ] = 0;
	}

	for (int x = 0; x <= c; x++)
	{
		s[r ][x] = 0;
	}

	for (int x = 0; x < r; x++)
	{
		for (int y = 0; y < c; y++)
		{
			s[x][c] += s[x][y];
		}
	}

	for (int x = 0; x < c; x++)
	{
		for (int y = 0; y < r; y++)
		{
			s[r ][x] += s[y][x];
		}
	}

	for (int x = 0; x < c; x++)
	{
		for (int y = 0; y < r; y++)
		{
			s[r ][c] += s[y][x];
		}
	}

	for (int x = 0; x < r + 1; x++)
	{
		for (int y = 0; y < c + 1; y++)
		{
			if (y != c) cout << s[x][y] << " " ;
			else if (y == c) cout<<s[x][y] << endl;
		}
	}
}



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

int main() {
	// your code goes here
	int a[3][3];
	for(int i=0;i<3;i++)
	{
	    for(int j=0;j<3;j++)
	    cin>>a[i][j];
	}
	int n;
	cin>>n;
	int x;
	while(n--)
	{
	    cin>>x;
	    for(int i=0;i<3;i++)
	    {
	        for(int j=0;j<3;j++)
	        {
	            if(a[i][j]==x)
	            a[i][j]=0;
	        }
	    }
	}
	
	int f=0;
	for(int i=0;i<3;i++)
	{
	    if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0)
	    {
	        f=1;
	        break;
	    }
	}
	for(int i=0;i<3;i++)
	{
	    if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0)
	    {
	        f=1;
	        break;
	    }
	}
	if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0)
	f=1;
	if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0)
	f=1;
	
	if(f)
	cout<<"Yes";
	else
	cout<<"No";
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>

using namespace std;

int main(){
  for(int N,T;cin>>N>>T,N|T;){
    int M[1234],L[1234],K[1234];
    for(int i=0;i<N;i++){
      cin>>M[i]>>L[i]>>K[i];
    }
    for(int no=1;;no++){
      int et[1234]={};
      int nw=no;
      bool done[1234]={};
      int nd=0;
      bool res;
      for(int i=0;;i++){
	nw+=et[i];
	for(int j=0;j<N;j++){
	  if(nw&&!done[j]&&i%(L[j]+K[j])<=L[j]){
	    if(i+M[j]>T){
	      res=false;
	      goto end;
	    }else{
	      done[j]=true;
	      et[i+M[j]]++;
	      nw--;
	      nd++;
	      if(nd==N){
		res=true;
		goto end;
	      }
	    }
	  }
	}
      }
    end:
      if(res){
	cout<<no<<endl;
	break;
      }
    }
  }
}

	      
	  

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define sz(x)       int(x.size())
//#define int         long long

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e5 + 2);
const int mod = (int)998244353;

string s;
int n, sum, f[N][3][3][2], ok;

void add(int& x, int y) {if((x += y) >= mod) x -= mod;}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> s; n = sz(s); s = ' ' + s; ok = 0; sum = s[1] - 'a';
    for(int i = 2; i <= n; ++i) ok += (s[i] != s[i - 1]), sum += s[i] - 'a';
    if(!ok) return cout << 1, 0;
    if(n == 2) return cout << 2, 0;
    if(n == 3) {
        if(s[1] != s[2] && s[2] != s[3] && s[3] != s[1]) return cout << 3, 0;
        else if(s[1] == s[3]) return cout << 7, 0;
        return cout << 6, 0;
    }
    for(int i = 0; i < 3; ++i) f[1][i][i][0] = 1;
    auto combine = [&](int x, int y) {if((x += y) >= 3) x -= 3; return x;};
    for(int i = 1; i < n; ++i) {
        for(int j = 0; j < 3; ++j) {
            for(int k = 0; k < 3; ++k) {
                for(int l = 0; l < 2; ++l) {
                    int& cur = f[i][j][k][l];
                    if(cur == 0) continue;
                    for(int x = 0; x < 3; ++x)
                        add(f[i + 1][combine(j, x)][x][l | (k == x)], cur);
                }
            }
        }
    }
    int res = (ok == n - 1); sum %= 3;
    for(int i = 0; i < 3; ++i) add(res, f[n][sum][i][1]);
    cout << res;
}


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


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
  void solve(std::istream& in, std::ostream& out)
  {
    int n, m;
    in >> n >> m;
    vector<vector<int> > a(n + 1);
    for(int i = 0; i < m; i++) {
      int from, to;
      in >> from >> to;
      a[from].push_back(to);
      a[to].push_back(from);
    }
    queue<pair<int, int> > q;
    q.push(make_pair(1, 0));
    bool canmove = false;
    while (!q.empty()) {
      auto status = q.front();
      q.pop();
      if(status.first == n) {
        canmove = true;
        break;
      }
      if(status.second == 2) {
        continue;
      }
      for (auto i : a[status.first]) {
        q.push(make_pair(i, status.second + 1));
      }
    }
    if(canmove) {
      out << "POSSIBLE\n";
    } else {
      out << "IMPOSSIBLE\n";
    }
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


int main() {
  
  ios_base::sync_with_stdio(0);
  cin.tie(0);


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}




Measured memory_bytes: 12784
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

int kakuketanosum(int n) {
	int s = 0;
	while (n > 0) {
		s += n % 10;
		n = n / 10;
	}
	/*if (s >= 10)
		s = kakuketanosum(s);
	else*/
	return s;
}
void kazusout(double* a, int n) {
	for (int i = 0; i < n - 1; i++) {
		if (*(a + i) > * (a + i + 1)) {
			int temp = *(a + i);
			*(a + i) = *(a + i + 1);
			*(a + i + 1) = temp;
		}
	}
}

int main(void) {
	int n, q;
	int  x[200000], p[200000], y[200000] = {};
	vector<pair<int, int> >a(200000);

	cin >> n >> q;
	for (int i = 0; i < n-1; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.rbegin(), a.rend());
	for (int i = 0; i < q; i++) {
		cin >> p[i] >> x[i];
	}
	for (int i = 0; i < q; i++) {
		y[p[i] - 1] += x[i];
	}
	for (int i = n - 2; i >= 0; i--) {
		y[a[i].second - 1] += y[a[i].first - 1];
	}
	for (int i = 0; i < n - 1; i++) {
		cout << y[i] << ' ';
	}
	cout << y[n - 1] << endl;
}

Measured memory_bytes: 6272
n = input(); k = input();
p = (n+1)/2 if n%2==1 else n/2
for i in range(k):
    a,b = map(int, raw_input().split())
    if p<a: a = n+1-a
    if p<b: b = n+1-b
    print (min(a,b)-1)%3+1

Measured memory_bytes: 4224
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    cout << (char)toupper(a.at(0)) << (char)toupper(b.at(0)) << (char)toupper(c.at(0)) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    if(A==B&&A!=C&&B!=C)cout<<C;
    if(A==C&&A!=B&&C!=B)cout<<B;
    if(B==C&&B!=A&&C!=A)cout<<A;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

vector<string>all;

void solve(string s,long long n,long long m){
    int len=s.size();
    string p;
    if(len==n)all.push_back(s);
    else{
        for(int i=s[len-1]-'a';i<m;i++){
            p='a'+i;
            solve(s+p,n,m);
        }
    }
    return;
}

int main() {
	long long n,m,q,ans,rans=0;
	string p;
	cin>>n>>m>>q;
	vector<int> a(q),b(q),c(q),d(q);
	rep(i,m){
	    p='a'+i;
	    solve(p,n,m);
	}
	int l=all.size();
	rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
	rep(i,l){
	    ans=0;
	    
	    
	    rep(k,q){
	        if(all[i][b[k]-1]-all[i][a[k]-1]==c[k])ans+=d[k];
	    }
	    rans=max(rans,ans);
	}
	cout<<rans;
	return 0;
}


Measured memory_bytes: 7444
s = gets.chomp
fN = 0
fW = 0
fS = 0
fE = 0
s.each_char do |c|
  case c
  when "N"
    fN = 1
  when "W"
    fW = 1
  when "S"
    fS = 1
  when "E"
    fE = 1
  end
end
puts ((fN ^ fS == 0) && (fW ^ fE == 0)) ? "Yes" : "No"


Measured memory_bytes: 1788
s = input()

if(s[0] == s[1]and s[2] == s [3] and s[0] != s[2]):
    print('Yes')
elif(s[0] == s[2] and s[1] == s [3] and s[0] != s[1]):
    print('Yes')
elif(s[0] == s[3]and s[1] == s [2] and s[0] != s[2]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.printf(" %d", i);
            } else {
                int x = i;
                while (x > 0) {
                    if (x % 10 == 3) {
                        System.out.printf(" %d", i);
                        break;
                    }
                    x /= 10;
                }
            }
        }
        System.out.println();
    }
}



Measured memory_bytes: 35836
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    int kosu = 0;
    vector<pair<ll,ll>> kumi;
    REP(i,N){
        cin >> A[i];
        if(A[i] < 0){
            kosu++;
        }
    }
    ll ans = 0;

    if(kosu == 0){//全部正の数
        sort ALL(A);
        ans = A[0];
        REPP(i,1,N-1){
            kumi.pb({ans,A[i]});
            ans -= A[i];
        }
        kumi.pb({A[N-1],ans});
        cout << A[N-1]-ans << endl;
        REP(i,kumi.size()){
            cout << kumi[i].first << ' ' << kumi[i].second << endl;
        }
    }
    else if(kosu == N){//全部負の数
        sort ALL(A);
        reverse ALL(A);
        ans = A[0];
        REPP(i,1,N){
            kumi.pb({ans,A[i]});
            ans -= A[i];
        }
        cout << ans << endl;
        REP(i,kumi.size()){
            cout << kumi[i].first << ' ' << kumi[i].second << endl;
        }
    }
    else if(kosu > 0){
        int minv = -1000000,minvnum = 0;
        sort ALL(A);
        REP(i,N){
            if(A[i] >= 0) continue;
            minv = max(minv,A[i]);
            if(A[i] == minv) minvnum = i;
        }
        ans = minv;
        REPP(i,0,N-1){//最後以外計算の対象とする
            if(i == minvnum) continue;
            if(A[i] < 0){
                kumi.pb({A[N-1],A[i]});
                A[N-1] -= A[i];
            }
            else if(A[i] >= 0){
                kumi.pb({ans,A[i]});
                ans -= A[i];
            }
        }
        kumi.pb({A[N-1],ans});
        cout << A[N-1]-ans << endl;
        REP(i,kumi.size()){
            cout << kumi[i].first << ' ' << kumi[i].second << endl;
        }
    }
}

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

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




    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110
#define WMax 110000
int N, W;
int w[Max];
ll v[Max];
ll dp[Max][WMax];

ll solve(int i, int weight) {
    if (dp[i][weight] != -1) return dp[i][weight];
    if (i == N) return 0;

    ll val = 0;
    if (weight + w[i] <= W) {
        val = v[i] + solve(i+1, weight + w[i]);
    }
    val = max(val, solve(i+1, weight));

    dp[i][weight] = val;
    return val;
}

int main(int argc, const char * argv[]) {
    N = inputValue();
    W = inputValue();
    rep(i, N) {
        w[i] = inputValue();
        v[i] = inputValue();
    }
    memset(dp, -1, sizeof(ll) * Max*WMax);

    output(solve(0, 0));

    return 0;
}

Measured memory_bytes: 94720
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    int x[m];
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }

    sort(x, x+m);

    int diff[m-1];
    for (int i = 0; i < m-1; i++) {
        diff[i] = x[i+1] - x[i];
    }

    sort(diff, diff+m-1);

    if (n >= m) {
        cout << 0 << "\n";
    } else {
        ll ans = 0LL;
        for (int i = 0; i < m - n; i++) {
            ans += (ll)diff[i];
        }
        cout << ans << "\n";
    }

    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  bool ok = false;
  for(int i = 1; i < 2000; i++){
    int x = i * 0.08;
    int y = i * 0.1;
    if(x == a && y == b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

const int mod = 1000000007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int remod(LL x) { x %= mod; return x + (x >> 63 & mod); }
const int MAXN = 210;
LL A[MAXN], B[MAXN], C[MAXN], D[MAXN], K, li[MAXN];
int n;
std::map<std::vector<LL>, std::vector<std::pair<LL, LL>>> M;
int calc(LL l, LL r) {
	int res = 0;
	for (int i = 60; ~i; --i)
		if ((r >> i & 1) != (l >> i & 1)) {
			res += !!l; break;
		} else res += r >> i & 1, l ^= (r >> i & 1) << i;
	return res;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	for (int i = 0; i <= 60; ++i) {
		for (int j = 1; j <= n; ++j)
			B[j] = A[j] >> i, li[j] = (C[j] = A[j] & (1ll << i) - 1) + 1;
		li[n + 1] = 1ll << i, li[n + 2] = 0;
		std::sort(li + 1, li + 3 + n);
		int bak = std::unique(li + 1, li + 3 + n) - li - 1;
		for (int j = 1; j < bak; ++j) {
			LL stp = K - i - calc(li[j], li[j + 1] - 1);
			for (int k = 1; k <= n; ++k)
				stp = std::min(stp, D[k] = B[k] - (C[k] < li[j]));
			for (int k = n; k > 1; --k) D[k] -= D[k - 1];
			if (stp >= 0)
			M[std::vector<LL> (D + 2, D + n + 1)].emplace_back(std::max(D[1] - stp, 0ll), D[1]);
		}
	}
	int ans = 0;
	for (auto t : M) {
		auto & v = t.second;
		std::sort(v.begin(), v.end());
		LL lst = -1;
		for (auto i : v) {
			lst = std::max(lst, i.first - 1);
			reduce(ans += remod(std::max(i.second - lst, 0ll)) - mod);
			lst = i.second;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 1010
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")

ll n, m;
ll cts[range], unlock[range];
ll dp[range][(1 << 12) + 1];

int main(){
 
    // freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
    cin >> n >> m;
    forn(i, m) {
      cin >> cts[i];
      ll x; cin >> x;
      ll combo = 0;
      forn(i, x) {
        ll t ; cin >> t;
        combo += (1LL << (t - 1));
      }
      unlock[i] = combo;
    }

    forn(i, 1 << n){
      forn(j, m + 1) dp[j][i] = INT_MAX;
    }
    dp[0][0] = 0;
    
    // forn(i, m) cout << unlock[i] << endl;
    forn1(i, m) {
      forn(j, 1 << n) dp[i][j] = min(dp[i][j], dp[i - 1][j]);

      forn(j, 1 << n) {
        ll mask1 = j | unlock[i - 1];

        dp[i][mask1] = min(dp[i][mask1], dp[i - 1][j] + cts[i - 1]);
      }
    }

    if(dp[m][(1 << n) - 1] == INT_MAX) cout << -1 << endl;
    else cout << dp[m][(1 << n) - 1] << endl;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
} 


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    int a, b;

    cin >> n >> m;

    vector<int> v(n);

    int i;

    for (i = 0; i < m; i++) {
        cin >> a >> b;

        a--;
        b--;

        v[a]++;
        v[b]++;
    }

    for (i = 0; i < n; i++) cout << v[i] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (b==0) return a;
    else{
    	return gcd(b,a%b);
    }
}
 
int main() {
	ll a,b;
  	cin >> a >> b;
  	cout << (b-a)*2+a << endl;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();

    let mut a = read_vec::<u64>();
    let b = read_vec::<u64>();

    let mut count = 0;
    for i in 0.. n {
        if a[i] > b[i] {
            count += b[i];
        } else {
            let rest = b[i] - a[i];
            count += a[i];

            if a[i+1] > rest {
                count += rest;
                a[i+1] -= rest;
            } else {
                count += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 9972
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    multiset<int> S;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        auto b = S.lower_bound(a);
        if (b != S.begin()) S.erase(prev(b));
        S.insert(a);
    }
    printf("%d\n", (int)S.size());
    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		String path = "";
		for(int i = 0; i < tx - sx; i++)
			path = path + "R";
		for(int i = 0; i < ty - sy; i++)
			path = path + "U";
		for(int i = 0; i < tx - sx; i++)
			path = path + "L";
		for(int i = 0; i < ty - sy; i++)
			path = path + "D";
		path = path + "D";
		for(int i = 0; i < tx - sx + 1; i++)
			path = path + "R";
		for(int i = 0; i < ty - sy + 1; i++)
			path = path + "U";
		path = path + "L";
		path = path + "U";
		for(int i = 0; i < tx - sx + 1; i++)
			path = path + "L";
		for(int i = 0; i < ty - sy + 1; i++)
			path = path + "D";
		path = path + "R";
		System.out.println(path);
	}
}

Measured memory_bytes: 207052
#include <stdio.h>

int main(void) {
	int a, b, A, B, x, y, tem, max;
	while(scanf("%d %d", &a, &b) != EOF){
		if(a < b){
			tem = a;
			A = b;
			B = tem;
		}
		else{
			A = a;
			B = b;
		}
		tem = 1;
		while(tem != 0){
			tem = A % B;
			A = B;
			B = tem;
		}
		x = A;
		y = a / x * b;
		printf("%d %d\n", x, y);
	}
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    int A=N/4;
    int B=N/7;
    string j;
    j="No";
    
    for (int a=0; a<=A; a++) {
        for (int b=0; b<=B; b++) {
            if (a*4+b*7==N) {
                a=A+1;b=B+1;
                j="Yes";
            }
        }
    }
    
    cout<<j;
    
    
}


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

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;
}

const ll INF = 1LL << 60;
int N;
ll h[100001];
ll dp[100001];

ll f(int i) {
    if (dp[i] < INF)
        return dp[i];
    if (i == 1)
        return 0;
    
    ll res = INF;
    chmin(res, f(i-1) + abs(h[i] - h[i-1]));
    if (i > 2)chmin(res, f(i-2) + abs(h[i] - h[i-2]));

    return dp[i] = res;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    
    for(int i = 0; i <= 100001; ++i) dp[i] = INF;

    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    /*
    dp[1] = 0;
    
    for(int i = 2; i <= N; ++i){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 2) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
    */
    /*
    for (int i = 1; i <= N; i++) {
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
    
    cout << dp[N] << endl;
    */
   cout << f(N) << endl;

    return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>
#include<string.h>

#define SUNNY 'S'
#define RAINY 'R'

int main()
{
    char weather[4];
    int curret_rain_days = 0;
    int max_rain_days = 0;

    scanf("%s", weather);

    for (int i = 0; i<3; i++)
    {
        if (weather[i] == RAINY)
        {
            curret_rain_days ++;

            if (curret_rain_days > max_rain_days)
            {
                max_rain_days = curret_rain_days;
            }
        } else {
            curret_rain_days = 0;
        }
    }

    printf("%d", max_rain_days);

    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
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; }

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

int h, w;
struct xydata {
    int x; int y; int cnt;
};

int main() {
    cin >> h >> w;
    vector< vector<char> > maseme(h, vector<char>(w, '.'));
    int white = 0; int black = 0;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> maseme.at(i).at(j);
            if(maseme.at(i).at(j) == '#') black++;
            else white++;
        }
    }

    xydata first;
    first.x = 0; first.y = 0; first.cnt = 1;
    queue<xydata> que;
    que.push(first);

    int ans = -1;
    while(!que.empty()) {
        xydata now = que.front();
        que.pop();
        if(now.x == w-1 && now.y == h-1) {
            ans = now.cnt;
            break;
        }
        for(int i = 0; i < 4; ++i) {
            int nx = now.x+dx[i]; int ny = now.y+dy[i]; int ncnt = now.cnt+1;
            if(nx >= 0 && nx < w && ny >= 0 && ny < h) {
                if(maseme.at(ny).at(nx) == '.') {
                    maseme.at(ny).at(nx) = '#';
                    xydata next;
                    next.x = nx; next.y = ny; next.cnt = ncnt;
                    que.push(next);
                }
            }
        }
    }

    if(ans == -1) {
        cout << ans << endl;
    }else {
        cout << white-ans << endl;
    }
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	k = 0
	for i in 1:n
		k += min(b[i],a[i]+a[i+1])
		a[i+1]=max(a[i+1]-max(b[i]-a[i],0),0)
	end
	println(k)
end

main()

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

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for (int i = 0; i < n; i++)cin >> t[i];
    sort(t.begin(), t.end());

    int ret = 1;
    int prev = 0;
    for (int i = 1; i < n; i++) {
        if (t[i] - t[prev] > k || i - prev + 1 > c) {
            ret++, prev = i;
        }
    }

    cout << ret << endl;
    return 0;
}

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

const int MOD=998244353;
const int MAX=200005;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  COMinit();
  
  ll ans=0;
  ll a=m;
  rep(i,n-1-k) a=a*(m-1)%MOD;
  rep(i,k+1){
    ans=(ans+COM(n-1,k-i)*a%MOD)%MOD;
    a=a*(m-1)%MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8300
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int a=0;
  	int b=0;
    for(int i = 0; i < S.length(); i++){//010101...
        if(i % 2 == 0){//奇数番目
            if(S[i] == '1'){
                a++;
            }
        } else if (i % 2 == 1){//偶数番目
            if(S[i] == '0'){
                a++;
            }
        }
    }

    for(int i = 0; i < S.length(); i++){//101010...
        if(i % 2 == 0){//奇数番目
            if(S[i] == '0'){
                b++;
            }
        } else if (i % 2 == 1){//偶数番目
            if(S[i] == '1'){
                b++;
            }
        }
    }

if(a < b){
    cout << a << endl;
}else if(a > b){
    cout << b << endl;
} else {
	cout << a << endl;
}
return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>x>>y>>n;
    if(n >= y){
        i = floor(x*(y-1)/y);        
    }else{
        i = floor(x*n/y);
    }
    cout<<i;
}    
    

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

#define watch(x) cout << (#x) << " = " << x << endl;
#define mkp make_pair
#define mkt make_tuple
#define pb push_back
#define ll long long
#define ld long double

using namespace std;

int a[500], n;
long long dp[500][500], cost[500][500];

int main(){
	scanf("%d", &n);

	for(int i = 1; i <= n; i++) {scanf("%d", &a[i]); dp[i][i] = a[i]; cost[i][i] = 0;}
	
	for(int len = 1; len <= n; len++){
		for(int i = 1; i <= n; i++){
			if(i + len > n) break;
			dp[i][i + len] = 1e18;
			int j = i + len;
			cost[i][j] = 1e18;
			for(int k = i; k < j; k++){
				ll pl = 0;
				if(cost[i][j] > cost[i][k] + cost[k + 1][j] + dp[i][k] + dp[k + 1][j]){
					cost[i][j] = cost[i][k] + cost[k + 1][j] + dp[i][k] + dp[k + 1][j];
					dp[i][j] = dp[i][k] + dp[k + 1][j];
				}
			}
		}
	}

	printf("%lld\n", cost[1][n]);

	return 0;
}

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

int main(){
    ll N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    auto itr = lower_bound(a.begin(), a.end(), (a[N-1] + 1)/2);
    auto titr = itr;
    itr++;
    titr--;
    if(itr == a.end()){
        cout << a[N-1] << " " << *titr << endl;
        return 0;
    }
    itr--;
    if(N % 2 == 1){
        if( abs(a[N-1]/2 - *titr) < abs(a[N-1]/2 + 1 - *itr)) cout << a[N-1] << " " << *titr << endl;
        else cout << a[N-1] << " " << *itr << endl;
    }else{
        if( abs(a[N-1]/2 - *titr) < abs(a[N-1]/2 - *itr)) cout << a[N-1] << " " << *titr << endl;
        else cout << a[N-1] << " " << *itr << endl;
    }
} 

Measured memory_bytes: 1152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ExchangeArgumentsTechnique solver = new ExchangeArgumentsTechnique();
        solver.solve(1, in, out);
        out.close();
    }

    static class ExchangeArgumentsTechnique {
        int n;
        Pair[] participants;
        Long[] dp;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            participants = new Pair[n];
            dp = new Long[n + 1];
            Arrays.fill(dp, Long.MAX_VALUE);
            for (int i = 0; i < n; i++) {
                participants[i] = new Pair(in.nextInt(), in.nextInt());
            }

            Arrays.sort(participants);
            dp[0] = 0L;
            for (Pair pair : participants) {
                int h = pair.height;
                int p = pair.power;
                for (int j = n - 1; j >= 0; j--) {
                    if (h >= dp[j]) {
                        dp[j + 1] = Math.min(dp[j + 1], p + dp[j]);
                    }
                }
            }

            for (int i = n; i > -1; i--) {
                if (dp[i] != Long.MAX_VALUE) {
                    out.println(i);
                    break;
                }
            }
        }

        class Pair implements Comparable<Pair> {
            int height;
            int power;

            public Pair(int height, int power) {
                this.height = height;
                this.power = power;
            }

            public int compareTo(Pair o) {
                long a = 1L * this.height + this.power;
                long b = 1L * o.height + o.power;
                return Long.compare(a, b);
            }

            public String toString() {
                return height + " " + power;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 97444
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define f first
#define s second
#define pb push_back
using namespace std;
long long const inf=1e18+5;
int const maxn=4005;
typedef long long ll;
typedef pair<int,int>P;
vector<P>p;
char s[maxn];
ll num[30];
int main(){
	int n;
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++) num[s[i]-'A']++;
	ll res = num['R'-'A']*num['G'-'A']*num['B'-'A'];
	for(int i=2;i<n;i++) for(int j=1;j<i;j++) 
		if((i+i-j<=n)&&s[i]!=s[j]&&s[i]!=s[i+i-j]&&s[j]!=s[i+i-j]) res--;
	printf("%lld\n",res);
}

Measured memory_bytes: 3828
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x, y, a, b, c, i, ans = 0;
    cin>>x>>y>>a>>b>>c;
    ll red[a], blue[b], less[c];
    ll reds = 0, blues = 0;
    for(i = 0; i < a; i++) {
    	cin>>red[i];
    }
    for(i = 0; i < b; i++) {
    	cin>>blue[i];
    	
    }
    for(i = 0; i < c; i++) {
    	cin>>less[i];
    }
    sort(red, red + a);
    reverse(red, red + a);
    sort(blue, blue + b);
    reverse(blue, blue + b);
    sort(less, less + c);
    reverse(less, less + c);
    for(i = 0; i < x; i++) {
    	reds += red[i];
    }
    for(i = 0; i < y; i++) {
    	blues += blue[i];
    }
    ans = blues + reds;
    ll redp = x - 1, bluep = y - 1, lessp = 0;
    // cout<<ans<<"\n";
    while(lessp < c) {
    	// cout<<less[lessp]<<" "<<blue[blusep]<<" "<<red[redp]<<"\n";
    	if(bluep < 0 && redp < 0) {
    		break;
    	}
    	else if(redp < 0) {
    		if(blue[bluep] < less[lessp]) {
    			ans = ans - blue[bluep] + less[lessp];
    			bluep--;
    		} else {
    			break;
    		}
    	} else if(bluep < 0) {
    		if(red[redp] < less[lessp]) {
    			ans = ans - red[redp] + less[lessp];
    			redp--;
    		} else {
    			break;
    		}
    	} else {
    		if(red[redp] < less[lessp] && red[redp] <= blue[bluep]) {
    			ans = ans - red[redp] + less[lessp];
    			redp--;
    		}
	  		else if(blue[bluep] < less[lessp] && blue[bluep] <= red[redp]) {
    			ans = ans - blue[bluep] + less[lessp];
    			bluep--;
    		} else {
    			break;
    		}
    	}
    	lessp++;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

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

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

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


class UnionFind{
public:
  vector<int> Parents;

  UnionFind(int N){
    Parents.assign(N, -1);
  }

  int root(int A){
    if(Parents[A] < 0) return A;
    return Parents[A] = root(Parents[A]);
  }

  int size(int A){
    return -Parents[root(A)];
  }

  bool connect(int A, int B){
    A = root(A);
    B = root(B);

    if(A == B) return false;

    if(size(A) < size(B)) swap (A, B);

    Parents[A] += Parents[B];
    Parents[B] = A;
    return true;
  }
};

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

  vector<int> A(M), B(M);
  for(int i = 0; i < M; i++){
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
  }

  UnionFind uf(N);

  vector<ll> ans(M);
  ans[M-1] = (ll) N * (N-1) / 2;
  ll cnt = 0;
  for(int i = M-1; i>=1; i--){
    if(uf.root(A[i]) == uf.root(B[i])){
      ans[i-1] = ans[i];
    } else {
      ans[i-1] = ans[i] - uf.size(A[i]) * uf.size(B[i]);
      uf.connect(A[i], B[i]);
    }
  }

  for(int i = 0; i < M ; i++){
    cout << ans[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3328