akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int mod = 1000000007;

// 繰り返し二乗法 n^k % mod
ll modpow(int n, int k, int mod) {
    ll ret = 1;
    ll multi = n;
    for (int i = 0; i < 31; i++) {
        if (k >> i & 1) ret = ret * multi % mod;
        multi = multi * multi % mod;    
    }
    return ret;
}

// nCmのmの最大
const int mmax = 200001;
ll com[mmax];

void combination(int n, int mod) {
    com[0] = 1;
    for (int i = 1; i < mmax; i++) {
        com[i] = (n-i+1) % mod * modpow(i, mod-2, mod) % mod * com[i-1] % mod;
    }
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    combination(n, mod);
    int64_t ans;
    ans = modpow(2, n, mod) - 1;
    ans -= com[a];
    if (ans < 0) ans += mod;
    ans -= com[b];
    if (ans < 0) ans += mod;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  vl a(3);
  rep(i, 3) cin >> a[i];
  sort(ALL(a));
  cout << a[0] * a[1] / 2 << endl;
  return 0;
}


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

//#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int n; cin >> n;
    vector<int> p(n);
    stack<int> s;
    s.push(0);
    rep(i,n){
        int m; cin >> m;
        if(i == m-1){
            s.top()++;
        }else{
            s.push(0);
        }
    }
    int ans = 0;
    while(!s.empty()){
        ans += ceiv(s.top(),2);
        s.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    long long int N, A, B;

    scanf("%lld%lld%lld", &N, &A, &B);

    if(A > B){
        long long int t = A;

        A = B;
        B = t;
    }
    if((B - A) % 2 == 0){
        printf("%lld\n", (B - A) / 2);
    }else if(A - 1 < N - B){
        printf("%lld\n", A + (B - A - 1) / 2);
    }else{
        printf("%lld\n", N - B + 1 + (B - A - 1) / 2);
    }
}

Measured memory_bytes: 128
#５００円の枚数取得
c500 = gets.chomp.to_i
#100円の枚数取得
c100 = gets.chomp.to_i
#50円の枚数取得
c50 = gets.chomp.to_i
#合計金額の枚数取得
sum = gets.chomp.to_i

#払える組み合わせを数える
count = 0
(0..c500).each do |i|
  (0..c100).each do |j|
    (0..c50).each do |k|
      count += 1  if 500 * i + 100 * j + 50 * k == sum
    end
  end
end

#出力
puts count

Measured memory_bytes: 1788
n = int(input())
a = 0
b = 0
c = 0
d = 0
for k in range(n):
  judge = input()
  if judge == "AC":
    a += 1
  elif judge == "WA":
    b += 1
  elif judge == "TLE":
    c += 1
  else:
    d += 1
print("AC x " + str(a))
print("WA x " + str(b))
print("TLE x " + str(c))
print("RE x " + str(d))


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

using namespace std;
int main(void){
    string S;
    int K;
    cin >> K;
    cin >> S;
    string COPY="";
    
    for(int i=0;i<K&&i<S.length();i++){
        COPY+=S[i];
    }
    if(COPY.length()<S.length()){
        COPY+='.';
        COPY+='.';
        COPY+='.';
    }
    cout << COPY << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
	while (1) {
		int m, mx[300] = { 0 }, my[300] = { 0 };
		cin >> m;
		if (m == 0) return 0;
		for (int i = 0; i < m; i++) {
			cin >> mx[i] >> my[i];
			if (i) {
				mx[i] -= mx[0];
				my[i] -= my[0];
			}
		}
		int n, nx[2000] = { 0 }, ny[2000] = { 0 };
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> nx[i] >> ny[i];
		}
		for (int i = 0; i < n; i++) {
			int ansx = nx[i] - mx[0];
			int ansy = ny[i] - my[0];
			bool bo = true;
			for (int j = 1; j < m; j++) {
				int sx = nx[i] + mx[j];
				int sy = ny[i] + my[j];
				int ct = 0;
				for (int k = 0; k < n; k++) {
					if (nx[k] == sx&&ny[k] == sy) ct++;
				}
				if (ct) continue;
				else {
					bo = false;
					break;
				}
			}
			if (bo) {
				cout << ansx << " " << ansy << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3108
import sys
from bisect import bisect_left
sys.setrecursionlimit(10**6)
N,*L = map(int, open(0).read().split())
A = [0]+L[:N]
dic = [[] for i in range(N+1)]
INF = 10**20
dp = [INF]*N
ans = [0]*(N+1)
for u,v in zip(*[iter(L[N:])]*2):
  dic[u].append(v)
  dic[v].append(u)
def dfs(v,p):
  i = bisect_left(dp,A[v])
  old = dp[i]
  dp[i] = A[v]
  ans[v] = bisect_left(dp,INF)
  for u in dic[v]:
    if u==p:
      continue
    dfs(u,v)
  dp[i] = old
dfs(1,-1)
for i in range(1,N+1):
  print(ans[i])

Measured memory_bytes: 345948
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
 
int main() {
  long long T;
  cin>>T;
  rep(i,T){
    long long N,M,A,B;
    cin>>N>>M>>A>>B;
    cout<<floor_sum(N,M,A,B)<<endl;
  }
}

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

const int MAX_N = 1e5+2;
int N, H[MAX_N];
ll dp[MAX_N];

void solve()
{
	memset(dp,0x3f,sizeof(dp));
	dp[1]=0;
	for(int i=1;i<=N;++i){
		if(i+1<=N) dp[i+1]=min(dp[i+1],dp[i]+abs(H[i+1]-H[i]));
		if(i+2<=N) dp[i+2]=min(dp[i+2],dp[i]+abs(H[i+2]-H[i]));
	}
	cout << dp[N] << '\n';
}

int main()
{
	cin >> N;
	for(int i=1;i<=N;++i) cin >> H[i];
	solve();
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
  int i,k;
  k=0;
  int a,b;
  int suma[99]={0};
  int sumb[99]={0};
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin>>a>>b;
      if(a>b) suma[k]=a+b+suma[k];
      if(a<b) sumb[k]=a+b+sumb[k];
      if(a==b){
        suma[k]=a+suma[k];
        sumb[k]=b+sumb[k];
      }
  }
  k++;
 }
  for (i = 0; i < k;i++) {
   cout<<suma[i]<<" "<<sumb[i]<<endl;
 }
 return 0;
}

Measured memory_bytes: 1160
N=int(input())
X=sorted(list(map(int, input().split())))
 
ans =100000000000
tmp=0
cnt=0
 
for i in range(X[0],X[-1]+1):
    for j in range(len(X)):
        tmp += (X[j]-i)**2
    if ans > tmp:
        ans =tmp
    tmp=0
print(ans)

Measured memory_bytes: 9104
n=int(input())
ans=''
if n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9:
    ans='hon'
elif n%10==0 or n%10==1 or n%10==6 or n%10==8:
    ans='pon'
else:
    ans='bon'
print(ans)

Measured memory_bytes: 61628
#include<iostream>
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long A,B,K;
  in(A,B,K);
  if(A>=K)cout<<A-K<<" "<<B<<endl;
  else cout<<0<<" "<<max(B-(K-A),0L)<<endl;
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

typedef long long ll;

vector<ll> a,b;

ll f(ll n, ll x){
  if(n == 0){
    return 1;
  }else if(x == 0){
    return 0;
  }if(x < a[n-1] + 1){
    return f(n-1, x-1);
  }else if(x == a[n-1] + 1){
    return b[n-1] + 1;
  }else{
    return b[n-1] + 1 + f(n-1, x - a[n-1] - 2);
  }
}
    

int main(){
  
  ll n,x;
  cin >> n >> x;
  
  a.push_back(1);
  b.push_back(1);
  for(int i=1; i<=n; i++){
    a.push_back(2 * a[i-1] + 3);
    b.push_back(2 * b[i-1] + 1);
  }
  
  cout << f(n, --x) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
         
using namespace std;
 
#define ll  long long
#define mod 1000000007
#define pb push_back
#define pie 3.141592653589



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

 

    ll i,n,n2,m,t,j,l,r,pos,mpos,f=0,k,p,n1,z,q,x,y,x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>n>>k;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<ll> dp(n,0);
    dp[0]=0;
    
    for(i=1;i<n;i++){
        dp[i]=LONG_MAX;
        for(j=1;j<=k;j++){
             if(i-j>-1)
             dp[i]= min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
    }
      
        
    cout<<dp[n-1];



  return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n,t,e;
	cin>>n>>t>>e;
	vi x(n);
	REP(i,n){
		cin>>x[i];
	}
	int ans=-2;
	REP(i,n){
		if(t%x[i]<=e||x[i]-t%x[i]<=e){
			ans=i;
			break;
		}
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

string mcxi = "mcxi";

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

    while(n --){

        int res = 0;
        
        rep(i, 2){
            string in; cin >> in;
            rep(j, 4){
                int diff = in.find(mcxi[j]);
                if(!~diff) continue;

                diff = in[diff - 1] - '0';
                if(diff < 0 || 9 < diff) diff = 1;
                res += diff * (int)pow(10., 3 - (double)j);
            }
        }
        string ans;

        rep(i, 4){
            int val = res % 10;
            res /= 10;

            if(val){
                ans.pb(mcxi.at(3 - i));
                if(val != 1) ans.pb(val + '0');
            }
        }
        reverse(ALL(ans));
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> data(n);
  for ( int i = 0 ; i < n ; i++ ) {
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  int ans=0;
  for ( int i = 0 ; i < k ; i++ ) {
    ans += data.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    int n, q;
    string s;
    cin >> n >> q >> s;
    int c[n + 1];
    c[0] = 0;
    for (int i = 1; i <= n; i++){
        if (s.substr(i - 1, 2) == "AC")
            c[i] = c[i - 1] + 1;
        else
            c[i] = c[i - 1];
    }
    for (int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << c[r - 1] - c[l - 1] << endl;
    }
}

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

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

  int total = A + B + C;
  int maxVal = max(A, max(B, C));
  int diff = maxVal * 3 - total;
  int ans = diff / 2 + 2 * (diff % 2);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))

dp = [0] * N

dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])


Measured memory_bytes: 13928
import java.util.Scanner;

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

        final int MPERH = 60;
        final int SPERM = 60;

        int S = scanner.nextInt();

        int h = S / (MPERH * SPERM);
        int m = (S % (MPERH * SPERM)) / SPERM;
        int s = S % SPERM;

        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 26232
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
#include<iomanip>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a;
  string b;
  cin >> a >> b;
  rep(i, b.length()) {
    rep(j, a) { b[i]++;
      if (b[i] == '[') {
        b[i] = 'A';
      }
    }
  }
  cout << b;
}

/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll n, max=0;
    cin>>n;
    int i;

    for(i=n; i>0; i--){
        if(sqrt(i) == int(sqrt(i))){
            max = i;
            cout<<max;
            return 0;
        }
    }




}





























Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
	int dp[1001][1001];
	int w[1001],v[1001],n,W;
	char s;
	int k=1;
	while(1){
		cin>>W>>n;
		if(W==0)break;
		for(int i=0;i<n;i++){
			cin>>v[i]>>s>>w[i];
		}
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++){
			for(int j=0;j<=W;j++){
				if(w[i]>j)dp[i+1][j]=dp[i][j];
				else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
			}
		}
		cout<<"Case "<<k<<":"<<endl;
		cout<<dp[n][W]<<endl;
        for(int i=0;i<=W;i++){
            if(dp[n][W]==dp[n][i]){
                cout<<i<<endl;;
                break;
            }
        }
		k++;
	}
}

Measured memory_bytes: 5088
function main(arg) {
	arg = arg.split("\n")[0]
	var text = ""

	for (var i = 0; i < arg.length; i++) {
		if (arg[i] === "1") {
			text += "9"
		} else {
			text += "1"
		}
	}
	console.log(text)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
import java.io.*;
import java.util.StringTokenizer;

public class Main {


  private void solve(InputReader in, PrintWriter out) {
    int n = in.nextInt();
    int w = in.nextInt();
    int h = in.nextInt();
    int count = 0;
    for (int i = 0; i < n; i++) {
      int a = in.nextInt();
      int b = in.nextInt();
      if (a >= w && b >= h) count++;
    }
    out.println(count);
  }


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

  private void run() {

    try (InputReader in = new InputReader(System.in);
         PrintWriter out = new PrintWriter(System.out)) {
      solve(in, out);
    }
  }


  static class InputReader implements AutoCloseable {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    @Override
    public void close() {
    }
  }

}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    int n,z,w;
    cin >> n >> z >> w;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    if(n == 1) cout << abs(w-a[0]) << endl;
    else cout << max(abs(a[a.size()-1]-a[a.size()-2]),abs(a[a.size()-1]-w)) << endl;
}


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

using namespace std;

vector< vector<char> > a(55, vector<char>(55));
vector< vector<int> > mp(55, vector<int>(55));
int bb, ww;

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

bool range(int x, int y, int h, int w) {
	if (0 <= x && x < w && 0 <= y && y < h) {
		return true;
	}
	return false;
}

int cc;

void count(int x, int y, int h, int w) {
	for (int i = 0; i < 4; i++) {
		if (range(x + dx[i], y + dy[i], h, w)) {				
			if (mp[y+dy[i]][x+dx[i]] == -1) {
				if (a[y + dy[i]][x + dx[i]] == 'B') {
					bb = 1;
				}
				else if (a[y + dy[i]][x + dx[i]] == 'W') {
					ww = 1;
				}
			}
			else {
				cc++;
				mp[y + dy[i]][x + dx[i]] = -1;
				count(x + dx[i], y + dy[i], h, w);
			}
		}
	}
	return;
}

int main() {
	int w, h;
	while (cin >> w >> h) {
		if (w == 0 && h == 0) {
			break;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> a[i][j];
				if (a[i][j] == '.') {
					mp[i][j] = 0;
				}
				else {
					mp[i][j] = -1;
				}
			}
		}
		int b2, w2;
		b2 = w2 = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				bb = ww = cc = 0;
				if (mp[i][j] != -1) {
					mp[i][j] = -1;
					cc = 1;
					count(j, i, h, w);
					//cout << bb << ' ' << ww << ' ' << cc << endl;
					if (bb == 1 && ww == 1) {

					}
					else if (bb == 1) {
						b2 += cc;
					}
					else if (ww == 1){
						w2 += cc;
					}
				}
			}
		}
		cout << b2 << ' ' << w2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3280
def insertionSort(n, A, g):
    global cnt
    for i in range(g, n):
        temp = A[i]
        j = i - g
        while j >= 0 and A[j] > temp:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = temp
    return A


def shellSort(A, n):
    global m
    global G

    h = 1
    while True:
        if h > n:
            break
        G.append(h)
        h = 3 * h + 1
    G.reverse()
    m =len(G)

    for i in range(m):
        insertionSort(n, A, G[i])


if __name__ == "__main__":
    n = int(input())
    A = [int(input()) for i in range(n)]
    G = []
    m = 0
    cnt = 0
    shellSort(A, n)
    print(m)
    print(*G)
    print(cnt)
    for i in range(n):
        print(A[i])

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

typedef long long ll;
typedef long double ld;

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

    int N, M;
    cin >> N >> M;

    vector<vector<char> > A(N, vector<char>(N));
    vector<vector<char> > B(M, vector<char>(M));

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

    for(int i = 0; i < M; i++) {
        for(int j = 0; j < M; j++) {
            cin >> B[i][j];
        }
    }

    for(int i = 0; i <= N - M; i++) {
        for(int j = 0; j <= N - M; j++) {
            bool checker = false;
            for(int k = 0; k < M; k++) {
                for(int l = 0; l < M; l++) {
                    if(B[k][l] != A[i + k][j + l]) {
                        checker = true;
                        break;
                    }
                }
                if(checker) break;
            }
            if(checker) continue;

            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
import collections
n = int(input())
s = []
for _ in range(n):
    s_ = input()
    s.append(s_)
s_c = collections.Counter(s)
maxl = max(s_c.values())
ns = [k for k, v in s_c.items() if v == maxl]
for i in sorted(ns):
    print(i)

Measured memory_bytes: 35572
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;


namespace io{
    const int L = (1 << 20) + 1;
    
    char buf[L], *S , *T, c;
     
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
    
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
    
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
    
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
        
        if(!a)*--outs = '0';
        else 
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
        
        if(x)
            *--outs = x;
        
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int maxN = 100010;
int a[maxN];
int p[maxN];
int tree[2*maxN];          //有负数的情况 
int n;
ll ans;
int lowbit(int x)
{
	return x&(-x);	
} 
void add(int x,int rel)
{
	int i = (x + n+ 1);
	for(;i<=2*n+2;i+=lowbit(i))
	{
		tree[i] += rel;
	}
}
ll sum(int x)
{
	int i = (x + n+ 1);
	ll s = 0;
	for(;i; i -= lowbit(i))
	{
		s += (ll)tree[i];
	}	
	return s;
} 
bool check(int x)
{
	for(int i=1;i<=n;i++)
	{
		if(a[i] >= x)
			p[i] = 1;
		else
			p[i] = -1;
		p[i] += p[i-1];
	}  //计算前缀和 
	for(int i=0;i<=2*n+2;i++)
	{
		tree[i] = 0;
	}
	ll tot = 0;
	add(0,1);
	for(int i=1;i<=n;i++)
	{
		tot += sum(p[i]);
		add(p[i],1);	
	}
	
	if(tot >= ans)
		return true;
	else
		return false;
}
int main()
{
	n = inp();

	ans = 1ll * n*(n+1)/2;
	ans = (ans/2);
	for(int i=1;i<=n;i++)
	{
		a[i] = inp();	
	}
	if(n == 1)
	{
		printf("%d\n",a[1]);
		return 0;
	}
	int L = 1,R = 1e9;
	int cnt = 0;
	while(L<=R)
	{
		int mid = (L+R)/2;
		if(check(mid))
		{
			cnt = mid;
			L = mid + 1;
		}
		else
		{
			R = mid - 1;
		}
	}
	printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

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

    vector<ll> cumsum(N);
    vector<ll> cumxor(N);
    cumsum[0] = A[0];
    cumxor[0] = A[0];
    for(int i=1;i<N;i++){
        cumsum[i] = A[i] + cumsum[i - 1];
        cumxor[i] = A[i] ^ cumxor[i - 1];
    }

    ll ans = 0;
    for(int l=0;l<N;l++){
        int rl = l, rr = N;
        while(rr - rl > 1){
            int r = (rl + rr) / 2;
            assert(r < N);
            if((cumxor[r] ^ (l == 0 ? 0 : cumxor[l - 1])) == cumsum[r] - (l == 0 ? 0 : cumsum[l - 1])){
                rl = r;
            }else{
                rr = r;
            }
        }
        ans += (rl - l + 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s.find("AC") != string::npos)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int n;
double dp[3000][3000];
vector<double> v;
double calc(int idx, int sum) {
	if (idx == n) {
		if (sum > n / 2)
			return 1.0;
		return 0.0;
	}
	double &ret = dp[idx][sum];
	if (ret > -1)
		return ret;
	ret = v[idx] * calc(idx + 1, sum + 1) + (1 - v[idx])*calc(idx + 1, sum);
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	printf("%.15f\n", v[0] * calc(1, 1) + (1 - v[0])*calc(1, 0));
	return 0;
}

Measured memory_bytes: 70912
#include <limits.h>
#include <math.h>
#include <stdio.h>

int main(void) {
  int n, ans, x;
  int flag = 0;
  int t = 0;
  int y;
  // double x;
  scanf("%d", &n);
  x = n - (n * 0.09);
  while (x <= n || t <= n) {
    x++;
    t = x * 1.08;
    if (t == n) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    printf("%d\n", x);
  } else {
    printf(":(\n");
  }

  return 0;
}

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

typedef long long int ll;

ll n;
ll a[100002][3];
ll dp[100002][3];

ll func(ll i,ll j)
{
	if(i==n-1)
	{
		dp[i][j]=a[i][j];
		return a[i][j];
	}
	if(dp[i][j]!=-1)
		return dp[i][j];
	dp[i][j] = a[i][j]+max(func(i+1,(j+1)%3),func(i+1,(j+2)%3));
	return dp[i][j];
}

int main()
{
	ios::sync_with_stdio(0);
	ll n,i;
	cin >> n;	
	for(i=0;i<n;i++)
	{
		cin >> a[i][0] >> a[i][1] >> a[i][2];
		dp[i][0]=dp[i][1]=dp[i][2]=-1;
	}
	ll ans = max(func(0,0),func(0,1));
	ans = max(ans,func(0,2));
	cout << ans << "\n";
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}
int N;
vint G[111];

int dist[111];
int degma[111];
void dfs(int v,int p,int d){
    dist[v]=d;
    
    int deg=G[v].size();
    if(p!=-1)deg--;
    chmax(degma[d],deg);
    for(auto u:G[v]){
        if(u==p)continue;
        dfs(u,v,d+1);
    }
}



signed main(){
    cin>>N;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    dfs(0,-1,0);
    int ter=max_element(dist,dist+N)-dist;
    dfs(ter,-1,0);

    int di=*max_element(dist,dist+N);

    di++;
    int ans=(di+1)/2;

    int leaf=numeric_limits<int>::max();
    rep(i,N){
        memset(degma,0,sizeof(degma));
        dfs(i,-1,0);
        if(*max_element(dist,dist+N)+1>ans)continue;
        int tmp=1;
        for(int i=0;i<ans-1;i++)tmp*=degma[i];
        chmin(leaf,tmp);
    }

    rep(i,N)rep(j,N){
        if(i==j)continue;
        memset(degma,0,sizeof(degma));
        memset(dist,0,sizeof(dist));
        dfs(i,j,0);
        if(*max_element(dist,dist+N)+1>ans)continue;
        memset(dist,0,sizeof(dist));
        dfs(j,i,0);
        if(*max_element(dist,dist+N)+1>ans)continue;
        int tmp=1;
        for(int i=0;i<ans-1;i++)tmp*=degma[i];
        tmp*=2;
        chmin(leaf,tmp);
    }
    cout<<ans<<" "<<leaf<<endl;
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
n, k = map(int, input().split())
# 選ぶ数が違う時絶対に違う
# 1..N の中で和が同じにならない組み合わせを引いたらいい
# 解説AC  k ... n+1 について最大、最小をとってその間は全部作れる
ans = 0
mod = 10 ** 9 + 7
for i in range(k, n + 2):
    mi = (i - 1) * i // 2
    ma = (2 * n - i + 1) * i // 2
    # print(i, (ma - mi + 1))
    ans += (ma - mi + 1) % mod
print(ans % mod)


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

const int N = 1e5 + 100;

int ns, nt, dp[4000][4000];
string s,t;

int main(){
    # ifdef FILEs
        freopen( "input.txt", "r" ,stdin );
        freopen( "output.txt", "w", stdout );
    # endif
    ios_base::sync_with_stdio(false);
    
    cin >> s >> t;
    
    ns = s.size();
    nt = t.size();
    
    for( int i = 0; i < ns; i ++ ){
        for( int j = 0; j < nt; j ++ ){
            if( s[i] == t[j] ){
                dp[i][j] = 1;
                if( i > 0 && j > 0 ){
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
            }
            if( i > 0 ){
                dp[i][j] = max( dp[i][j], dp[i-1][j] );
            }
            if( j > 0 ){
                dp[i][j] = max( dp[i][j], dp[i][j-1] );
            }

        }
    }
    int x = 0, y = 0;
    for( int i = 0; i < ns; i ++ ){
        for( int j = 0; j < nt; j ++ ){
            if( dp[i][j] > dp[x][y] ){
                x = i;
                y = j;
            }
        }
    }
    string ans;
    while( x >= 0 && y >= 0 && dp[x][y] > 0 ){
        if( s[x] == t[y]  ){
            ans += s[x];
            x --;
            y --;
        }else if( x > 0 && dp[x-1][y] == dp[x][y] ){
            x--;
        }else if( y > 0 && dp[x][y-1] == dp[x][y] ){
            y--;
        }
    }
    reverse( ans.begin(), ans.end() );
    cout << ans;
    return 0;   
}   

Measured memory_bytes: 47360
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;

int main(void) {

  int n;
  cin >> n;
  int ans[n];
  for(int i = 0; i < n; i++) {
    int b;
    cin >> b;
    ans[b - 1] = i + 1;
  }
  for(int i = 0; i < n - 1; i++) {
    cout << ans[i] << " ";
  }
  cout << ans[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 3968
program ccc
implicit none

integer :: n, a, b, c, i, j, k, res1, res2
integer :: a1,a2,b1,b2,c1,c2,d1,d2
integer,allocatable,dimension(:) :: l

read*, n,a,b,c
allocate(l(n))
read*, l

res2=1000000

do i=0,2**n-1
 
 do j=0,2**n-1
 a1=0
 b1=0
 c1=0
 d1=0
 a2=0
 b2=0
 c2=0
 d2=0
 res1=0
  
  do k=0,n-1
  if(btest(i,k)) then
   if(btest(j,k)) then
   a1=a1+l(k+1)
   a2=a2+1
   else
   b1=b1+l(k+1)
   b2=b2+1
   end if
  else
   if(btest(j,k)) then
   c1=c1+l(k+1)
   c2=c2+1
   else
   d1=d1+l(k+1)
   d2=d2+1
   end if
  end if
  end do
  
 if(a2==0) cycle
 if(b2==0) cycle
 if(c2==0) cycle
 res1=res1+(a2+b2+c2-3)*10
 res1=res1+abs(a-a1)+abs(b-b1)+abs(c-c1)
 res2=min(res1,res2)

 end do
end do

write(*,'(i0)') res2

end program

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

int main() {
    int n;
    cin >> n;
    while (n--) {
        string str;
        cin >> str;
        unordered_set<string> s;
        for (int i = 0; i < str.size(); i++) {
            string f = str.substr(0, i);
            string rf(f.rbegin(), f.rend());
            string l = str.substr(i);
            string rl(l.rbegin(), l.rend());
            s.insert(f + l);
            s.insert(l + f);
            s.insert(rf + l);
            s.insert(rl + f);
            s.insert(f + rl);
            s.insert(l + rf);
            s.insert(rf + rl);
            s.insert(rl + rf);
        }
        cout << s.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
def main():
    K = int(input())
    if K in [1,7]:
        print(1)
        return
    if K == 2:
        print(-1)
        return
    
    k = 7 % K
    current = k
    count = 1
    foot_print = set()
    while True:
        count += 1
        current = (k + (current * 10)) % K
        if current == 0:
            print(count)
            return
        if current in foot_print:
            break
        foot_print.add(current)

    print(-1)
    

if __name__ == '__main__':
    main()


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

bool
solve(vector<int> & xs, int i, int m) {
  auto x = xs[i];

  if (m == 0) return true;  
  if (m < 0 || i == (int)xs.size() ) return false;
  
  return solve(xs, i+1, m) || solve(xs, i+1, m-x);
}
  
  
int
main() {
  // O(2^n) where n <= 20
  int n;
  cin >> n;
  vector<int> xs;
  for (int i=0; i<n;++i) {
    int x;
    cin >> x;
    xs.push_back(x);
  }
  int mx;
  cin >> mx;
  for (int i=0; i<mx; ++i) {
    int m;
    cin >> m;
    auto res = solve(xs, 0, m);
    if (res) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}


#if 0
Local Variables:
quickrun-option-cmd-alist: ((:command . "clang++")
			    (:exec    . ("%c -std=c++11 -o %n %s -Wall -Wextra -Werror -D__MAIN__"
					 "%n "))
                            (:remove  . ("%n")))
  End:
#endif

Measured memory_bytes: 3132
#include<iostream>
#include<complex>
#include<vector>

using namespace std;

typedef complex<long double> P;
typedef vector<P> Polygon;

long double cross(P a,P b){
  return (conj(a)*b).imag();
}

double area(const Polygon &p){
  double a=0;
  for(int i=0;i<p.size();i++){
    a+=cross(p[(i+1)%p.size()],p[i]);
  }
  return fabs(a)/2;
}

P intersection(P a1,P a2,P b1,P b2){
  P a=a2-a1;
  P b=b2-b1;
  return a1+a*cross(b,b1-a1)/cross(b,a);
}
  
Polygon cut(P a,P b,const Polygon &p){
  int n=p.size();
  vector<double> c(n);
  for(int i=0;i<n;i++){
    c[i]=cross(b-a,p[i]-a);
  }
  Polygon r;
  for(int i=0;i<n;i++){
    if(c[i]>=0){
      r.push_back(p[i]);
    }
    if(c[i]*c[(i+1)%n]<0){
      r.push_back(intersection(a,b,p[i],p[(i+1)%n]));
    }
  }
  return r;
}


int main(){
  for(int N;cin>>N,N;){
    Polygon p;
    for(int i=0;i<N;i++){
      double x,y;
      cin>>x>>y;
      p.emplace_back(x,y);
    }
    double wa=area(p);
    double l=1e-5,r=acos(0)*2+1e-5;
    Polygon lp=cut(P(0,0),polar(2.,l),p),rp=cut(P(0,0),polar(2.,r),p);
    double la,ra;
    la=area(lp);
    ra=area(rp);
    for(int i=0;i<1000;i++){
      double m=(l+r)/2;
      auto mp=cut(P(0,0),polar(2.,m),p);
      double ma=area(mp);
      if(ma/wa==.5){
	l=m;
	break;
      }else if((la/wa-.5)*(ma/wa-.5)>=0){
	l=m;
	la=ma;
      }else{
	r=m;
	ra=ma;
      }
    }
    cout.precision(15);
    auto ans=polar(2.,l);
    cout<<fixed<<ans.real()<<' '<<ans.imag()<<endl;
  }
}

Measured memory_bytes: 1312
#include<bits/stdc++.h>
using namespace std;
int main(void) {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        bool f = false;
        int x = i;
        if(x %3 == 0) f = true;
        while(x > 0){
            if(x % 10 == 3) f = true;
            x /= 10;
        }
        if(f) cout << ' ' << i; 
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main() {
    ll h, w, ans;
    cin >> h >> w;


    
    /**
     * Alguns exemplos:
     * 1. par e par: 2 * 2 = 4               (sempre par)
     * 2. ímpar e par: 3 * 6 = 18            (sempre par)
     * 3. par e ímpar: 4 * 1 = 4             (sempre par)   
     * 4. ímpar e ímpar: 3 * 3 = 9           (sempre ímpar)

     * Caso precise +1 quando ambos são ímpares, basta:
     * ans = (h*w + 1)/2
     * Funciona pois, (par+1)/2 = par/2

    */

    if (h == 1 || w == 1) {
        ans = 1;
    }
    else {
        ans = (h*w+1)/2;
    }
    // else if (h % 2 == 1 && w % 2 == 1) {
    //     ans = (h*w) / 2 + 1;
    // }
    // else {
    //     ans = (h*w) / 2;
    // }

    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=sorted(([sorted(list(input()))for i in range(n)]))+["1"]
d=0
e,r=1,""
for i in a:
    if r!=i:
        r=i
        d+=(e*(e-1))//2
        e=1
    else:
        e+=1
print(d)

Measured memory_bytes: 26144
#include<cstdio>
#include<cstring>
#include<algorithm>
const int M=1e5+7;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,k,mx,s[M],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++) k=read(),s[k]++,mx=std::max(mx,k);
	for(int i=0;i<=mx;i++) ans=std::max(ans,s[i-1]+s[i]+s[i+1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    }

    static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

}


Measured memory_bytes: 21844
def resolve():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans=0
    minus=0
    for i in range(k+1):
        for j in range(i+1):
            if j<=n:
              for t in range(j+1):
                w=sorted(v[:j-t] + v[n -t:])
                for l in w[:i-j]:
                    if l<0:
                       minus+=l
                ans=max(ans,(sum(w)-minus))
                minus=0
            else:
                for t in range(j + 1):
                    w = sorted(v)
                    for l in w[:i - j]:
                        if l < 0:
                            minus += l
                    ans = max(ans, (sum(w) - minus))
                    minus = 0
    print(ans)
resolve()

Measured memory_bytes: 50780
#include<iostream>
#include<cmath>
#include<complex>
using namespace std;

complex<double> p[300];

complex<double> core(int a,int b){
  complex<double> res,mid,norm;

  mid = (p[a]+p[b]) / 2.0;

  norm = (p[a] - p[b]) * complex<double>(0,1);
  norm = norm / abs(norm);
  norm = norm * sqrt(1.0 - abs(mid-p[a])*abs(mid-p[a]));

  res = norm + mid;
  return res;
}
  

int main(){
  int n;
  complex<double> o;
  int max,tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)cin >> p[i].real() >> p[i].imag();

    max = 1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i!=j && abs(p[i]-p[j]) < 2.0){
	  o = core(i,j);
	  tmp = 2;
	  for(int k=0;k<n;k++){
	    if(k!=i && k!=j){
	      if(abs(o-p[k])<1.0)tmp++;
	    }
	  }
	  if(max < tmp)max = tmp;
	}
      }
    }
    cout << max << endl;
  }
}

Measured memory_bytes: 980
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String t="";
		for(int i=s.length()-1;i>=0;i--){
			t+=s.charAt(i);
		}
		if(s.equals(t))System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL N;
int main() {
  cin >> N;
  VEC<LL> T(N), A(N);
  REP(i, 0, N) { cin >> T[i] >> A[i]; }
  LL t = T[0];
  LL a = A[0];
  REP(i, 1, N) {
    LL mul = max((a + A[i] - 1) / A[i], (t + T[i] - 1) / T[i]);
    a = mul * A[i];
    t = mul * T[i];
    // DUMP(a,t);
  }
  cout<<a+t<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
using ll = long long;

int n, a[210000], t;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i), t ^= a[i];
	printf("%d", a[0] ^ t);
	for (int i = 1; i < n; i++)
		printf(" %d", a[i] ^ t);
	printf("\n");
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 5e3 + 100;
const int mod = 1e9+ 7;
int dp1[N][N];//dp1[i][j] dentoes number of ways to i moves
			  //such that after i moves length is equal to j
int dp2[N][N];//dp[i][j] dentoes number of ways to have a string of length j
			  //after i moves just such that length was always greater than 	
			  //equal to zero 
inline int add(int i , int j){
	i += j;
	if(i >= mod) i -= mod;
	return i;
}
inline int mul(int a , int b){
	return a*1ll*b%mod;
}
int power(int x , int y){
	int res = 1;
	while(y){
		if(y&1)
			res = mul(res , x);
		x = mul(x , x);
		y >>= 1;
	}
	return res;
}

int pwr[N];
int main(){
	fio; cout<<fixed<<setprecision(25);	

	dp1[0][0] = 1;
	dp2[0][0] = 1;
	pwr[0] = 1;
	for(int i = 0 ;i < N-1 ; ++i){
		pwr[i+1] = mul(2 , pwr[i]);
		if(i != 0) assert(dp2[i][0] == 0);
		for(int j = 0;j <= i ; ++j){
			if(j == 0)
				dp1[i+1][j] = add(dp1[i+1][j] , dp1[i][j]);
			else
				dp1[i+1][j-1] = add(dp1[i+1][j-1] , dp1[i][j]);
			dp1[i+1][j+1] = add(dp1[i+1][j+1] , mul(2 , dp1[i][j]));
			dp2[i+1][j+1] = add(dp2[i+1][j+1] , dp2[i][j]);
			if(j >= 2) dp2[i+1][j-1] = add(dp2[i+1][j-1] , dp2[i][j]);
		}
	}	

	int n; string s;
	cin >> n >> s;
	int ans = 0;
	for(int i = 0;i <= n ; ++i){
		if(i+s.size() > n) break;
		if((n-i-s.size())%2 == 0)
		ans = add(ans ,mul(dp1[i][0] , mul(dp2[n-i][s.size()] , pwr[(n-i-s.size())/2])));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 201856