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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

string C(string x);
string D(string x);
string S(string x);
string L(string x);

int main()
{
    string s;
    while(cin >>s,(s!="."))
    {
        int ct=0;
        rep(i,s.size()) ct+=(s[i]=='?');

        int lim=1;
        rep(i,ct) lim*=26;

        string ans(100,'z');

        rep(mask,lim)
        {
            int t=mask;
            string im(ct,' ');
            rep(i,ct)
            {
                im[i]='A'+t%26;
                t/=26;
            }

            int c=0;
            string ss=s;
            rep(i,ss.size())
            {
                if(ss[i]=='?') ss[i]=im[c++];
            }

            ans=min(ans,C(ss));
        }

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

string C(string x)
{
    if(x[0]=='[')
    {
        int br=0;
        int idx=0;
        while(idx<x.size())
        {
            if(x[idx]=='[') ++br;
            else if(x[idx]==']') --br;

            if(br==0) break;
            ++idx;
        }

        string a=S(x.substr(0,idx+1));

        string b="";
        if(idx+1!=x.size()) b=D(x.substr(idx+1));

        return a+b;
    }
    else
    {
        //Letter

        int idx=0;
        while(idx<x.size())
        {
            if('A'<=x[idx] && x[idx]<='Z') break;
            ++idx;
        }

        string a=S(x.substr(0,idx+1));
        string b=D(x.substr(idx+1));

        return a+b;
    }
}

string D(string x)
{
    if(x=="") return x;
    return C(x);
}

string S(string x)
{
    if(x[0]=='[')
    {
        //reverse
        string r=C(x.substr(1,x.size()-2));
        reverse(all(r));

        return r;
    }
    else return L(x);
}

string L(string x)
{
    if(x[0]=='+')
    {
        string r=L(x.substr(1));

        if(r[0]=='Z') r[0]='A';
        else ++r[0];

        return r;
    }
    else if(x[0]=='-')
    {
        string r=L(x.substr(1));

        if(r[0]=='A') r[0]='Z';
        else --r[0];

        return r;

    }
    else return x;
}

Measured memory_bytes: 1240
h,w,k = gets.split.map(&:to_i)
table = []
h.times do
  table << gets.chomp.chars
end

$ans = 0
(0..('1' * h).to_i(2)).each do |i|
  table2 = table.dup

  i.to_s(2).rjust(h, '0').chars.each.with_index do |bit1, i1|
    if bit1 == '1'
      table2[i1] = ['x'] * w
    end
  end

  (0..('1' * w).to_i(2)).each do |j|
    table3 = table2.dup

    j.to_s(2).rjust(w, '0').chars.each.with_index do |bit2, i2|
      if bit2 == '1'
        tmp = table3.transpose.dup
        tmp[i2] = ['x'] * h
        table3 = tmp.transpose
      end
    end

    cnt = 0
    table3.each do |row|
      row.each do |point|
        if point == '#'
          cnt += 1
        end
      end
    end

    $ans += 1 if cnt == k
  end

end

puts $ans

Measured memory_bytes: 14456
n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i in range(n):
    if i % 2 == 0:
        v0.append(v[i])
    else:
        v1.append(v[i])
v0.sort()
v1.sort()
l = [[0,-2]]
r = [[0,-1]]
hoge = v0[0]
count = 0
for i in v0:
    if i == hoge:
        count += 1
    else:
        l.append([count,hoge])
        hoge = i
        count = 1
l.append([count,hoge])
hoge = v1[0]
count = 0
for i in v1:
    if i == hoge:
        count += 1
    else:
        r.append([count,hoge])
        hoge = i
        count = 1
r.append([count,hoge])
l.sort(reverse = True)
r.sort(reverse = True)
if l[0][1] != r[0][1]:
    print(n-l[0][0]-r[0][0])
else:
    print(min(n-l[1][0]-r[0][0],n-l[0][0]-r[1][0]))

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

int main() {
  long long mod = 998244353;
  long long N;
  cin >> N;
  vector<char> s(10);
  vector<string> S(N,"0000000000");
  for (int i=0; i<N; i++) {
    for (int j=0; j<10; j++) {
      cin >> s[j];
    }
    sort(s.begin(),s.end());
    for (int j=0; j<10; j++) {
      S[i][j] = s[j];
    }
  }
  sort(S.begin(),S.end());
  long long ans = 0;
  long long val = 1;
  
  for (int i=0; i<N-1; i++) {
    if (S[i] == S[i+1]) {
      ans += val;
      val++;
    }
    else {
      val = 1;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

int main()
{
        string s1,s2,s3;
        cin >> s1 >> s2 >> s3;

        char a, b, c;
        a = s1[0];
        b = s2[0];
        c = s3[0];
        a = (a - 'a') + 'A';
        b = (b - 'a') + 'A';
        c = (c - 'a') + 'A';
        cout << a << b << c << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e18;
const double PI=3.1415926535897932;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

vec BIT(ll a){
    vec ret;
    ll K=a;
    rep(i,60){
        ret.pb(K%2);
        K/=2;
    }
    return ret;
}

ll ruijou(ll n, ll k){
    if(!k) return 1;
    ll a=ruijou(n,k/2);
    a=(a*a);
    return k%2 ? (a*n): a;
}

ll Solve(){
    ll N; cin>>N;
    vec d(N);
    rep(i,N) cin>>d[i];
    ll Nim=0;
    REP(i,2,N) Nim^=d[i];
    ll A=d[0]+d[1];
    //cout<<Nim<<' '<<A<<endl;
    if(A<Nim) return -1;
    
    ll B=A-Nim;
    if(B%2) return -1;
    B/=2;
    
    vec n=BIT(Nim), b=BIT(B);
    vec ans(60,-1);
    ll ANS=0;
    for(int i=59; i>=0; i--){
        if(b[i]){
            if(n[i]) return -1;
            ans[i]=1;
            ANS+=ruijou(2,i);
        }
        else{
            if(!n[i]) ans[i]=0;
        }
    }
    if(ANS>d[0]) return -1;
    for(int i=59;i>=0;i--){
        if(ans[i]==-1){
            if(ANS+ruijou(2,i)<=d[0]) ANS+=ruijou(2,i);
        }
    }
    if(!ANS) return -1;
    return d[0]-ANS;
    

    
}
int main(){
    //cout<<(4294967296^ 8589934594)<<endl;
    cout<<Solve()<<endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
	int n,i,sum;
	scanf("%d",&n);
	int a[n+10];
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	sum=0;
	for(i=1;i<n-1;i++)
	{
		if(a[i]<a[i+1]&&a[i]>a[i-1])
		sum++;
		else if(a[i]>a[i+1]&&a[i]<a[i-1])
		sum++;
	} 
	printf("%d\n",sum);
}

Measured memory_bytes: 888
/*
* @author:  codancer
* @createTime:  2020-05-02, 20:21:33
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int N,M,Q;
int a[100],b[100],c[100],d[100];
int ans=0;
int all[100];
void dfs(int x,int id){
	if(id==N+1){
		int now=0;
		for(int i=1;i<=Q;i++){
			if(all[b[i]]-all[a[i]]==c[i]) now+=d[i];
		}
		ans=max(ans,now);
		return ;
	}
	all[id]=x;
	for(int i=x;i<=M;i++){
		dfs(i,id+1);
	}
	all[id]=0;
}
int main(){
	cin>>N>>M>>Q;
	rep(i,1,Q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{

    private static boolean snake_A(String snake)
    {
	if(snake.charAt(snake.length()-1) != '~')
	    return false;

	if(snake.charAt(snake.length()-2) != '=')
	    return false;

	if(!snake.substring(0,2).equals(">'"))		
	    return false;

	if(snake.indexOf("#") == -1)
	    return false;


	if(snake.indexOf("#") > snake.indexOf("~"))
	    return false;

	if(snake.indexOf("#")-snake.indexOf("'") != snake.indexOf("~")-snake.indexOf("#"))
	    return false;

	int left,right;
	left = right = 0;
	for(int i=2;i<snake.indexOf("#");i++)
	    {
	
		if(snake.charAt(i) == '=')
		    left++;
		else 
		    {
			return false;
		    }
	    }

	for(int i=snake.indexOf("#")+1;i<snake.indexOf("~");i++)
	    {
	
		if(snake.charAt(i) == '=')
		    right++;
		else 
		    return false;
	    }	

	
	if(left != right)
	    return false;

	return true;
    }

    private static boolean snake_B(String snake)
    {

	if(!snake.substring(snake.length()-2,snake.length()).equals("~~"))
	    return false;

	if(snake.charAt(snake.length()-3) != '=')
	    return false;
 
	if(!snake.substring(0,2).equals(">^"))
	    return false;

	int cnt = 0;
	for(int i=2;i<snake.indexOf("~");i+=2)
	    {
		if(snake.substring(i,i+2).equals("Q="))
		    cnt++;
		else 
		    return false;
	    }

	if(cnt < 1)
	    return false;
	
	return true;
    }


      public static void main(String args[])throws IOException{
	  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	  
	  int n;
	  n = Integer.parseInt(in.readLine());

	  while(n-- > 0)
	      {
		  String snake = in.readLine();
		 
		  if(snake_A(snake))
		      {
			  System.out.println("A");
		      }
		  else if(snake_B(snake))
		      {
			  System.out.println("B");
		      }
		  else
		      {
			  System.out.println("NA");
		      }


	      }
      }

}

Measured memory_bytes: 11000
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,N,Q,l,r;
  cin>>N>>Q;
  vec v(N);
  rep(i,N){
    cin>>v[i];
  }
  vsort(v);
  while(Q--){
    cin>>l>>r;
    auto itr=lower_bound(all(v),l);
    auto itrs=upper_bound(all(v),r);
    cout<<itrs-itr<<endl;
  }
  return 0;
}


Measured memory_bytes: 3640
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define PRINT
#define LCERR
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    int good_distances(const vector<vector<int>>& points) {
        const int N = points.size();
        if (points.empty()) return 0;
        const int D = points[0].size();
        int cnt = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = i + 1; j < N; ++j) {
                int dist = 0;
                for (int d = 0; d < D; ++d) {
                    dist += int(pow(points[i][d] - points[j][d], 2));
                }
                if (is_sq(dist)) {
                    cnt += 1;
                }
            }
        }
        return cnt;
    }
private:

    bool is_sq(int x) {
        return int(pow(x, 0.5) + 0.5) * int(pow(x, 0.5) + 0.5) == x;
    }
};

int solve() {
    Solution solution;
    // handle IO here
    int N, D;
    cin >> N >> D;
    vector<vector<int>> points(N, vector<int>(D, 0));
    for (int i = 0; i < N; ++i) {
        for (int d = 0; d < D; ++d) {
            cin >> points[i][d];
        }
    }
    cout << solution.good_distances(points) << endl;
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		System.out.println((a + b) * h / 2);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 8788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vecInt = vector<int>;
using vecLong = vector<long long>;
#define rep(i,l,n) for(int i=l;i<n;i++)

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int D;
    cin >> D;
    vecInt c(26);
    rep(i,0,26) cin >> c[i];
    vector<vecInt> s(D,vecInt(26));
    rep(i,0,D) rep(j,0,26) cin >> s[i][j];
    vecInt t(D);
    rep(i,0,D) cin >> t[i];
    ll score = 0l;
    vecInt last(26);
    rep(i,0,D){
        score += s[i][t[i]-1];
        last[t[i]-1] = i + 1;
        rep(j,0,26){
            if (j==t[i]-1) continue;
            score -= c[j] * ((i + 1) - last[j]);
        }
        cout << score << endl;
    }
    return 0;
}

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

int main(){
int n,ans=0;cin>>n;
vector<string> g(n),g2(n);rep(i,n)cin>>g[i];
rep(i,n){
rep(j,n)g2[(j+i)%n]=g[j];
bool f=true;
rep(p,n){rep(q,p){if(g2[p][q]!=g2[q][p]){f=false;}}}
if(f)ans += n;
}
cout<<ans<<endl;return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll arr[10] , mark [10] = { 0 } , flag = 0;
    map <int , int> c;
    for(int i = 1;i<=9;i++)
    {
        cin>>arr[i];
        c[arr[i]]= i;
    }
	ll q;
	cin>>q;
	while(q--)
	{
	    ll m ;
	    cin>>m;
	    mark[c[m]] = 1;
	}
	/*for(int i = 1 ;i < 10;i++)
	{
	    cout<<mark[i]<<" ";
	    if(i%3==0)
	    cout<<endl;
	}*/
    if(mark[1]==mark[5]&&mark[5]==mark[9]&&mark[1]==1)
	flag =1;
	else if(mark[3]==mark[5]&&mark[5]==mark[7]&&mark[3]==1)
	flag = 1;
	else if(mark[1]==mark[3]&&mark[3]==mark[2]&&mark[1]==1)
	flag = 1;
	else if(mark[4]==mark[5]&&mark[5]==mark[6]&&mark[4]==1)
	flag = 1;
	else if(mark[7]==mark[8]&&mark[8]==mark[9]&&mark[7]==1)
	flag = 1;
	else if(mark[1]==mark[4]&&mark[4]==mark[7]&&mark[1]==1)
	flag = 1;
	else if(mark[2]==mark[5]&&mark[8]==mark[2]&&mark[2]==1)
	flag = 1;
	else if(mark[3]==mark[6]&&mark[3]==mark[9]&&mark[3]==1)
	flag = 1;
	if(flag==0)
	{
	    cout<<"No";
	} else {
	    cout<<"Yes";
	}
}

Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
bool delta(int a, int b, int wa, int wb, int tp, int tn)
{
	int eng = tn - tp;
	int mhd = abs(wa-a) + abs(wb-b);
	if(eng>=mhd && ((eng-mhd)%2 == 0))
		return true;
	return false;
}
int main()
{
	int x=0, y=0, tn=0, gx, gy, tp=0;
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d%d%d", &tn, &gx, &gy);
		if(delta(x, y, gx, gy, tp, tn))
			continue;
		else{
			puts("No");
			return 0;
		}
		x = gx, y = gy, tp = tn;
	}
	puts("Yes");
	return 0;
}

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

int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  if(a[0]==a[1] and a[1] != a[2]) cout << "Yes";
  else if (a[0]!=a[1] and a[1]==a[2]) cout << "Yes";
  else cout << "No";
}


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

struct Node{
    int k;
    int *c;
    int p;
};

int main(void){
    int n,i,j,id,k,depth;
    Node node[100000];
    
    cin>>n;
    
    for(i=0;i<n;i++){
        node[i].p=-1;
    }
    
    for(i=0;i<n;i++){
        cin>>id>>k;
        node[id].k=k;
        node[id].c=(int*)malloc(sizeof(int)*k);
        for(j=0;j<k;j++){
            cin>>node[id].c[j];
            node[node[id].c[j]].p=id;
        }
    }
    
    for(i=0;i<n;i++){
        id=i;
        k=node[i].k;
        depth=0;
        while(node[id].p!=-1){
            id=node[id].p;
            depth++;
        }

        printf("node %d: parent = %d, depth = %d, ",i,node[i].p,depth);
        if(node[i].p==-1){
            printf("root, ");
            
            if(k==0){
                printf("[]\n");
                return 0;
            }
            
            printf("[");
            for(j=0;j<k-1;j++){
                printf("%d, ",node[i].c[j]);
            }
            printf("%d]",node[i].c[k-1]);
        }
        else if(k>0){
            printf("internal node, ");
            printf("[");
            for(j=0;j<node[i].k-1;j++){
                printf("%d, ",node[i].c[j]);
            }
            printf("%d]",node[i].c[k-1]);
        }
        else{
            printf("leaf, []");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

const int MAX_N = 13;
const int MAX_M = 1e3 + 10;
const int INF = 1e9;

// dp[i][j] := i + 1番目以降の鍵は購入せずに状態jにするために必要な最小費用
int dp[MAX_M][1 << (MAX_N)];

int main(){
    int N, M; cin >> N >> M;
    vector<int> a(M+1), b(M), d(M+1);
    rep(i, 0, M){
        cin >> a[i+1] >> b[i];
        int tmp = 0;
        rep(j, 0,b[i]){
            int t; cin >> t; t--;
            tmp += 1 << t;
        }
        d[i+1] = tmp;
    }

    // dp初期化
    rep(i, 0, MAX_M){
        rep(j, 0, 1 << MAX_N){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    rep(i, 1, M + 1){
        for(int j = 0; j < 1 << N; j++){
            dp[i][j] = dp[i-1][j];
        }
        for(int j = 0; j < 1 << N; j++){
            dp[i][j|d[i]] = min(dp[i][j|d[i]], dp[i-1][j] + a[i]);
        }
    }

    /* rep(i, 0, M + 1){
        cout << i << " ";
        rep(j, 0, 1 << N){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    } */
    if(dp[M][(1 << N) - 1] == INF) cout << -1 << endl;
    else cout << dp[M][(1 << N) - 1] << endl;

}

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

int main() {
  uint64_t a, b, x;
  cin >> a >> b >> x;
  if (a != 0) {
    cout << b/x - (a-1)/x << endl;
  }
  else if (a == 0) {
    cout << b/x + 1 << endl;
  }
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

vector<int> ans(10e5+5, -1);
using Graph = vector<vector<int>>;
Graph g(10e5+5);
int dfs(int node ) {
    if(ans[node] > -1) return ans[node];
    int mx = 0;
    rep(i, g[node].size()){
        mx = max(mx, dfs(g[node][i]) + 1);
    }
    ans[node] = mx;
    return mx;
}

int main() {

    int n,m; cin >> n >> m;
    //Graph g(n+1);
    for (int i = 0; i < m; ++i) {
        int from, to;
        cin >> from >> to;
        g[from].push_back(to);
    }

    int ret = 0;
    for(int i=1; i <= n; i++) {
        if(ans[i] == -1) ret = max(ret, dfs(i));
    }

    cout << ret << endl;

    return 0;
}


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

int main(){
//srandom((unsigned long)time(NULL));
int a,b;
cin>>a>>b;
for(int i=1;i<1500;i++){
    if(i*8/100==a && i*10/100==b){
        cout<<i<<endl;
        return 0;
    }
}
cout<<-1<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int memo[210000], A[210000];

int main(){
  int N;
  cin >> N;
  for(int i = 0; i <= N; i++){
    memo[i] = INF;
  }
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  reverse(A, A + N);
  for(int i = 0; i < N; i++){
    int pos = distance(memo, upper_bound(memo, memo + N, A[i]));
    memo[pos] = A[i];
  }
  cout << distance(memo, lower_bound(memo, memo + N, INF)) << endl;
  return 0;
}


Measured memory_bytes: 1792
n,m,k = map(int, input().split())

from collections import deque

an = list(map(int, input().split()))

bn = list(map(int, input().split()))

accum_a = [0]
accum_b = [0]


for a_i in range(0,len(an)):

    sumCandidate = accum_a[-1] + an[a_i]
    if sumCandidate > k:
        break
    accum_a.append(sumCandidate)

for b_i in range(0,len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)

j = len(accum_b) - 1
ans = 0
for i in range(len(accum_a)):

    if accum_a[i] > k:
        break

    while accum_b[j] > k - accum_a[i]:
        j -= 1

    ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 137652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {
  int N, A, B, C, D, result;
  int i;
  scanf ("%d %d",  &A, &B);
  
  if ((A<10)&&(B<10)) result = A*B;
  else result = -1;
  
  
  printf("%d", result);
  return 0;
}




Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
const int N = 1<<18;
multiset<int> st; int n;
int s[N];
bool check(){
    for(int i=0;i<n;++i){
        for(int j=0;j<(1<<i);++j){
            auto it=st.lower_bound(s[j]);
            if(it==st.begin()) return false; it--;
            s[j+(1<<i)]=*it; st.erase(it);
        }
    }
    return true;
}

int main(){
    scanf("%d",&n); st.clear();
    for(int i=0;i<(1<<n);++i) scanf("%d",&s[i]);
    sort(s,s+(1<<n));
    for(int i=0;i<(1<<n)-1;++i) st.insert(s[i]); 
    s[0]=s[(1<<n)-1];
    if(check()) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
	ll n, w;
	cin>>n>>w;
	ll x, y;
	vplli v(n+1);
	ll dp[n+1][w+1] = {};
	forn(i, 1, n+1){
		cin>>x>>y;
		v[i] = mp(x, y);
	}
	forn(i, 1, n+1) {
		forn(j, 1, w+1){
			if(j - v[i].F >= 0) {
				dp[i][j] = max(v[i].S + dp[i-1][j - v[i].F], dp[i-1][j]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 82544
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

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

    int n, k, x, y;
    cin >> n >> k >> x >> y;

    int ans = min(n, k) * x;
    ans += max(0ll, n - k) * y;
    cout << ans << endl;
}


Measured memory_bytes: 256
a = input()
if a[0] == a[1] and a[2] == a[3] and a[0] != a[2]:
  print("Yes")
elif a[0] == a[2] and a[1] == a[3] and a[0] != a[1]:
  print("Yes")
elif a[0] == a[3] and a[1] == a[2] and a[0] != a[1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
#include<string.h>
#include<algorithm>
#include<cctype>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
char a[100005];
int main()
{
	scanf("%s",&a);
	int length=strlen(a),cou=0;
	for(int i=0;i<length/2;i++){
		if(a[i]!=a[length-1-i])cou++;
	}printf("%d\n",cou);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;

const int INF = 1000000000;

int main() {
    ios::sync_with_stdio(0);

    int N;
    cin >> N;

    vector<vector<int> > costs(N, vector<int>(N, 0));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            cin >> costs[i][j];
        }
    }

    vector<int> dp(1<<21, INF);
    priority_queue<pair<int,int> > q;
    {
        int init = 0;
        for(int i = 0; i < N; ++i) {
            init |= (i&7) << (i*3);
        }
        q.push(make_pair(0, init&07777777));
    }
    while(!q.empty()) {
        int cost = -q.top().first;
        int state = q.top().second;
        q.pop();

        if(dp[state] <= cost) continue;
        dp[state] = cost;

        if(N == 8) {
            bool contains[8] = {0};
            for(int i = 0; i < 7; ++i) {
                contains[(state>>(3*i))&7] = true;
            }
            int rem = 0;
            while(contains[rem]) ++rem;
            state |= rem << 3*7;
        }

        for(int i = 0; i < N; ++i) {
            int ni = (state>>(3*i))&7;
            for(int j = 0; j < N; ++j) {
                if(i == j) continue;

                int nj = (state>>(3*j))&7;
                int newstate = state;
                newstate &= ~(7<<(3*i));
                newstate &= ~(7<<(3*j));
                newstate |= ni<<(3*j);
                newstate |= nj<<(3*i);
                newstate &= 07777777;
                int newcost = cost + costs[ni][nj];
                if(dp[newstate] > newcost) {
                    q.push(make_pair(-newcost, newstate));
                }
            }
        }
    }

    int ans = 0;
    for(vector<int>::iterator it = dp.begin(); it != dp.end(); ++it) {
        if(*it != INF) {
//            cout << oct << (it-dp.begin()) << ' ' << dec << *it << endl;
            ans = max(ans, *it);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15000
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
//ll bp(ll x, ll p){
//    ll res = 1;
//    while(p){
//        if(p & 1)
//            res = res * x % mod;
//        x = x * x % mod;
//        p >>= 1;
//    }
//    return res;
//}
//ll C(ll n, ll k){
//    if(k == 0)
//        return 1;
//    if(k < 0 || k > n)
//        return 0;
//    return f[n] * rf[k] % mod * rf[n - k] % mod;
//}
//f[0] = rf[0] = 1;
//    for(int i = 1; i < 500009; i++)
//        f[i] = f[i - 1] * i % mod, rf[i] = bp(f[i], mod - 2);
ll n;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    ll oldn = n;
    if(n == 1) {
        cout<<0;
        return 0;
    }
    int res = 0;
    for(int pr = 2;pr <= sqrt(oldn);pr++) {
        if(n % pr == 0) {
            int cnt = 0;
            while(n % pr == 0) {
                n /= pr;
                cnt++;
            }
            int l = 1, r = 1000;
            while(l <= r) {
                int m = (l + r)/ 2;
                if(m * (m + 1) / 2 <= cnt)
                    l = m + 1;
                else
                    r = m - 1;
            }
            res += (l - 1);
        }
    }
    if(n > 1)
        res++;
    cout<<res;
}
/*
 2
 ((
 )))(
 */


Measured memory_bytes: 3700
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 100100;

vector<int> E[MAX];
int d[MAX];

void dfs(int x) {
  for (int y: E[x]) {
    if (d[y] == 0) {
      d[y] = d[x] + 1;
      dfs(y);
    }
  }
}

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  REP(i, M) {
    int a, b;
    scanf("%d %d", &a, &b); --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  d[0] = 1;
  dfs(0);

  int cnt1 = 0;
  REP(i, N) {
    if (d[i]%2) cnt1++;
  }

  bool odd_cycle = false;
  REP(x, N) for (int y: E[x]) {
    if ((d[x] + d[y]) % 2 == 0) {
      odd_cycle = true;
    }
  }

  llint total = 0;
  if (odd_cycle) {
    total = N * 1LL * (N - 1) / 2;
  } else {
    total = cnt1 * 1LL * (N - cnt1);
  }

  total -= M;
  printf("%lld\n", total);
  return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int r, D, x2000;
	cin >> r >> D >> x2000;
	for (int i = 0; i < 10; i++) {
		x2000 = r * x2000 - D;
		cout << x2000<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> ss(n);
    for (auto& s : ss) {
        cin >> s;
    }
    int q;
    cin >> q;
    int ans = 0;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (binary_search(begin(ss), end(ss), t)) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1524
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r=sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		for(int i=0; i<10; i++){
			x=r*x-d;
			System.out.println(x);
		}
	}
}


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

int main(){
  string s;
  cin >> s;
  if(s=="ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

#ifndef CODE_
#include "f:/kyopro/code.c"
#define CODE_
#endif

i64 c;

typedef i64 data_merge_sort;

static inline i32 merge_sort_cmp(data_merge_sort *const x,data_merge_sort *const y){
    if(*x<=*y) return 1;
    return 0;
}

static void merge_sort_rec(data_merge_sort *const a,i64 const n,data_merge_sort *const d){
    if(n<2LL) return;
    c+=n;
    i64 const m=n/2LL;
    merge_sort_rec(a,m,d);
    merge_sort_rec(&a[m],n-m,&d[m]);
    i64 l=0LL,r=m,k=0LL;
    if(merge_sort_cmp(&a[m-1LL],&a[n-1LL])){
        while(l<m){
            if(merge_sort_cmp(&a[l],&a[r])) d[k++]=a[l++];
            else d[k++]=a[r++];
        }
        while(r<n) d[k++]=a[r++];
    }
    else{
        while(r<n){
            if(merge_sort_cmp(&a[l],&a[r])) d[k++]=a[l++];
            else d[k++]=a[r++];
        }
        while(l<m) d[k++]=a[l++];
    }
    for(i64 i=0LL;i<n;++i) a[i]=d[i];
    return;
}

static inline void merge_sort(data_merge_sort *const a,i64 const n){
    data_merge_sort *d=(data_merge_sort *)calloc(n,sizeof(data_merge_sort));
    merge_sort_rec(a,n,d);
    free((void *)d);
}

i32 cmp(const void *x,const void *y){
    if(*(i64 *)x<*(i64 *)y) return 1;
    if(*(i64 *)x>*(i64 *)y) return -1;
    else return 0;
}

i32 main(void){
    i64 n;
    scanf("%lli",&n);
    i64 *a=(i64 *)calloc(n,sizeof(i64));
    for(i64 i=0LL;i<n;++i) scanf("%lli",&a[i]);
    merge_sort(a,n);
    --n;
    for(i64 i=0LL;i<n;++i) printf("%lli ",a[i]);
    printf("%lli\n",a[n]);
    printf("%lli\n",c);
    // qsort(a,n,sizeof(i64),cmp);
    return 0;
}



Measured memory_bytes: 9052
program kadai
    implicit none
    integer  ::  N
real(8),allocatable  ::  x(:),y(:)
integer  ::  i,kake,j
real(8)  ::  kyori
real(8)  ::  ans

read(*,*) N

allocate(x(N))
allocate(y(N))

do i=1,N
    read(*,*) x(i),y(i)
end do

kyori=0
do i=1,N-1
    do j=i+1,N
        kyori = kyori + (sqrt((x(i)-x(j))**2+(y(i)-y(j))**2))
    end do
end do

ans = kyori*2/(N)
write(*,*) ans

stop
contains
end program kadai

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

#define MAX_N 1000005

using namespace std;


int n,k;
int rank[MAX_N + 1];
int tmp[MAX_N + 1];
int sa[MAX_N + 1];


bool compare_sa(int i, int j)
{
	if(rank[i] != rank[j]) 
	{
		return rank[i] < rank[j];
	}
	else
	{
	int ri =( i + k <= n )? rank[i + k] : -1;
	int rj =( j + k <= n )? rank[j + k] : -1;
	return ri < rj;
	}
}

void construct_sa(string s,int* sa)
{
	n = s.length();
	
	for(int i = 0; i <= n;i++)
	{
		sa[i] = i;
		rank[i] = i < n ? s[i] : -1;
	}
	
	for(k = 1;k <= n ; k *= 2)
	{
		sort(sa,sa + n + 1,compare_sa);
		
		tmp[sa[0]] = 0;
		for(int i = 1; i <= n; i++)
		{
			tmp[sa[i]] = tmp[sa[i -1]] + (compare_sa(sa[i - 1],sa[i]) ? 1 : 0);
		}
		for(int i = 0;i <= n;i++)
		{
			rank[i] = tmp[i];
		}
	}
}

bool contain(string s,int* sa, string t)
{
	int a = 0,b = s.length();
	while(b - a > 1)
	{
		int c = (a + b) / 2;
		
		if(s.compare(sa[c],t.length(),t) < 0) a = c;
		else b = c;
	}
	
	return (s.compare(sa[b], t.length(),t) == 0);
	
}


int main()
{
	string S;
	int N;
	
	
	cin >> S; 
	cin >> N;
	
	construct_sa(S,sa);
	
	for(int i = 0 ;i < N;i++)
	{
		string T;
		cin >> T;
		if(contain(S,sa,T)) cout << 1 << endl;
		else cout << 0 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 16532
#include <iostream>

int main()
{
	int a, b;

	std::cin >> a >> b;

	int max = a + b;

	if( max < a - b)
	{
		max = a - b;
	}

	if(max < a * b)
	{
		max = a * b;
	}

	std::cout << max << std::endl;
}

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

#define ll long long int

using namespace std;

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

    vector<ll> A(n);
    vector<ll> B(m);
    for (auto & a : A) cin >> a;
    for (auto & b : B) cin >> b;

    ll res = 0;

    ll a = 0;
    ll sum = 0;
    while (sum <= k && a < n) {
        sum += A[a];
        ++a;
    }
    if (sum > k) {
        sum -= A[a-1];
        --a;
    }
    res = max(res, a);
    //cerr << a << ", 0" << endl;

    ll b = 0;
    while (a >= 0 && b < m) {
        sum += B[b];
        ++b;
        while (sum > k && a >= 0) {
            sum -= A[a-1];
            --a;
        }
        if (sum <= k) {
            //cerr << a << ", " << b << endl;
            res = max(res, a + b);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 6424
def read(): return list(map(int, input().split()))

M = 100000
n = int(input())
seat = [0 for i in range(M)]

for i in range(n):
    l, r = read()
    l -= 1
    r -= 1
    for j in range(l, r+1):
        seat[j] = 1

print(sum(seat))

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int x;
    cin >> x;
    int sum = 0;
    int i = 0;

    do
    {
        i++;
        sum += i;
    } while (x > sum);

    OP(i);
    return 0;
}

Measured memory_bytes: 256
'use strict'

const main = (INPUT) => {
  const N = INPUT.split('\n')[0].split(' ').map(n => Number(n))
  const ans = []
  ans[0] = N[0] * N[2] - N[1]
  for (let i = 1; i < 10; i++) {
    ans[i] = N[0] * ans[i - 1] - N[1]
  }
  for (let i = 0; i < ans.length; i++) {
    console.log(ans[i])
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for(auto v:(V))cout<<v<<" "
inline int GCD(int a, int b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    if (N % 2 == 0)
    {
        cout << (N*N-2*N)/2 << endl;
    }
    else
    {
        cout << (N * N - 2 * N + 1) / 2 << endl;
    }
    repb(i, 1, N)
    {
        repb(j, i+1, N+1)
        {
            if (N % 2 == 0)
            {
                if (i+j != N+1)
                {
                    cout << i << " " << j << endl;
                }
            }
            else
            {
                if (i + j != N)
                {
                    cout << i << " " << j << endl;
                }
            }
            
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
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 long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  int sum = 0;
  int ma = 0;
  rep(i, n){
    int p; cin >> p;
    sum += p;
    chmax(ma, p);
  }

  int ans = (sum-ma) + ma/2;
  cout << ans << endl;

  return 0;
}


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

#define INF (1<<18)


int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    int ans = 0;
    rep(i,n){
        if(i == a[a[i]-1]-1) ans++;
        
    }

    cout<<ans/2<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    
    int h,w ; cin >> h >> w;
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<vector<int>> fi(h+5, vector<int>(w+5, 0));
    int color=0;

    rep(i, h){
        if(i%2==0) rep(j, w){
            fi[i][j]=color+1;
            --a[color];
            if(a[color]==0) ++color;

        }
        else reprev(j, w){
            fi[i][j]=color+1;
            --a[color];
            if(a[color]==0) ++color;
        }
    }

    rep(i, h){
        rep(j, w){
            if(j) cout << ' ';
            cout << fi[i][j];
        }
        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String args[]) {
       ///値を取得
       Scanner sc = new Scanner(System.in);
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       
       //出力
       if(a + b == c || a + c == b || b + c == a ) {
       System.out.println("Yes");
       } else {
           System.out.println("No");
       }
    }
}

Measured memory_bytes: 35332
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int n, q;
	long long sum = 0;
	cin >> n;
	map<int, int> a;
	for (int i = 0; i < n; i++)
	{
		int temp;
		cin >> temp;
		sum += temp;

		auto lb = a.lower_bound(temp);

		if (lb != a.end() && temp == lb->first)
			lb->second++;
		else
			a.insert(lb, {temp, 1});
	}
	cin >> q;
	vector<int> b(q), c(q);
	for (int i = 0; i < q; i++)
		cin >> b[i] >> c[i];
	for (int i = 0; i < q; i++)
	{
		auto it = a.find(b[i]);
		if (it != a.end())
		{
			int count = it->second;
			sum += ((long long) count) * (c[i] - b[i]);
			a.erase(it);

			auto lb = a.lower_bound(c[i]);

			if (lb != a.end() && c[i] == lb->first)
				lb->second += count;
			else
				a.insert(lb, { c[i], count });
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 6960
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string f(int x){
  string res;
  for(;x;){
    res += (char)((x % 10) + '0');
    x /= 10;
  }
  reverse(all(res));
  return res;
}

string solve(string s){
  int i, j, cnt = 0;
  string res;
  s += " ";
  for(i = 0;i < s.size() - 1;++i){
    cnt++;
    if(s[i] != s[i + 1]){
      res += f(cnt) + s[i];
      cnt = 0;
    }
  }
  return res;
}

signed main(void){
  int i, j;
  for(int testcase = 0;;testcase++){
    int(n);
    if(!n)break;
    string s;
    sc(s);
    rep(i, n)s = solve(s);
    pri(s);


//*/

//*/ break;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  set<int> d;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    d.insert(x);
  }
  
  cout << d.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int A,B,C;
    int i, j;

    scanf("%d %d %d",&A, &B, &C);

    if ((A == B && B != C )|| (A == C && A != B) || (B == C && A != B))
    {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    
}

Measured memory_bytes: 128