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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> X(N), Y(N), P(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i] >> P[i];
  }
  vector<vector<int>> XS(1 << N, vector<int>(N, 1 << 28));
  vector<vector<int>> YS(1 << N, vector<int>(N, 1 << 28));
  for (int bit = 0; bit < (1 << N); bit++) {
    for (int i = 0; i < N; i++) {
      XS[bit][i] = min(XS[bit][i], abs(X[i]));
      YS[bit][i] = min(YS[bit][i], abs(Y[i]));
      if ((bit >> i) & 1) {
        for (int j = 0; j < N; j++) {
          XS[bit][j] = min(XS[bit][j], abs(X[i] - X[j]));
          YS[bit][j] = min(YS[bit][j], abs(Y[i] - Y[j]));
        }
      }
    }
  }
  vector<int64_t> ZS(N + 1, INT64_C(1) << 49);
  for (int bitx = 0; bitx < (1 << N); bitx++) {
    int mask = ((1 << N) - 1) ^ bitx;
    for (int bity = ((1 << N) - 1) & mask;; bity = (bity - 1) & mask) {
      int a = __builtin_popcount(bitx), b = __builtin_popcount(bity);
      int64_t res = 0;
      for (int i = 0; i < N; i++) {
        res += static_cast<int64_t>(P[i]) * min(XS[bitx][i], YS[bity][i]);
      }
      ZS[a + b] = min(ZS[a + b], res);
      if (bity == 0) break;
    }
  }
  for (int i = 0; i < N + 1; i++) {
    cout << ZS[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 9800
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    string S;
    cin >> N;
    cin >> S;
    
    bool B[31415][11]={};
    bool C[31415][11]={};
    bool valid[1020]={};
    REP(i,N){
        if(i!=0){
            REP(j,10){
                B[i][j]=B[i-1][j];
            }
            B[i][S[i-1]-'0']=1;
        }
    }
    RREP(i,N){
        if(i!=N-1){
            REP(j,10){
                C[i][j]=C[i+1][j];
            }
            C[i][S[i+1]-'0']=1;
        }
    }
    REP(i,N){
        if(i==0)continue;
        if(i==N-1)continue;
        int b=S[i]-'0';
        REP(a,10){
            REP(c,10){
                if(B[i][a]==1 && C[i][c]==1){
                    valid[a*100+b*10+c]=1;
                }
            }
        }
    }
    int Ans=0;
    REP(i,1000){
        if(valid[i]){
            Ans++;
            //cout << i << endl;
        }
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int main() {
	int i, j, k;
	cin >> i >> j >> k;
	if ((i < k && k < j) || (j < k && k < i)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//# pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#define out(i,a,now) for(int i=a.be[now],to=a.v[i];~i;i=a.ne[i],to=a.v[i])
#define fo(i,a,b) for(i=(a);i<=(b);i++)
#define max(a,b) ((a)<(b)?(b):(a))
#define min(a,b) ((a)<(b)?(a):(b))
#define mp(a,b) make_pair(a,b)
#define qk(x) memset(x,0,sizeof(x))
#define RG register
#define gs(x) (tr[tr[x].f].son[1]==x)
#define lb(x) (x&(-x))
#define mid ((l+r)>>1)
#define SF scanf
#define PF printf
#ifdef Mogician
#endif
using namespace std;
typedef long long LL;
typedef double DB;
template <class T> void cmax(T &a,T b)
{
    a=max(a,b);
}
template <class T> void cmin(T &a,T b)
{
    a=min(a,b);
}
template <class T> void swp(T &a,T &b)
{
	T temp=a; a=b; b=temp;
}
string s;
const LL maxn=310000;
LL e[maxn],w[maxn];
int main()
{
	LL n;
	SF("%lld\n",&n);
	cin>>s;
	LL i;
	fo(i,1,n)
	if (s[i-1]=='W') w[i]++;
	else e[i]++;
	fo(i,1,n) e[i]+=e[i-1];
	for(i=n;i>=1;i--) w[i]+=w[i+1];
	LL ans=INT_MAX>>1;
	fo(i,1,n) cmin(ans,(i-1)-e[i-1]+(n-i)-w[i+1]);
	PF("%lld",ans);
}

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

main(){
	vector<int>a(3);
	rep(i,3) cin>>a[i];
	sort(a.begin(),a.end());
	if((a[2]-a[0]-a[2]+a[1])%2==0)cout<<a[2]-a[1]+(a[2]-a[0]-a[2]+a[1])/2<<endl;
	else cout<<2+a[2]-a[1]+(a[2]-a[0]-a[2]+a[1])/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a[4];
	int b[4];
	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]) != EOF){
		int hit = 0;
		int blow = 0;
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
				if(a[i] == b[j]){
					blow++;
				}
			}
			if(a[i] == b[i]){
				hit++;
				blow--;
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

Measured memory_bytes: 1024
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

x = read()
p = read()

p *= 0.01


if x % 2 == 0:
  print((x // 2) / p)
else:
  y = x // 2
  print(1 + p * y / p + (1 - p) * (y + 1) / p)


Measured memory_bytes: 3940
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i <= Math.max(a, b); i++) {
            if (a % i == 0 && b % i == 0) {
                list.add(i);
            }
        }
        // 出力
        System.out.println(list.get(list.size() - k));
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
struct team{
	int id,ac,p;
	int pp[11];
};

bool comp(const team &a,const team &b){
	if(a.ac==b.ac){
		if(a.p==b.p)return a.id<b.id;
		return a.p<b.p;
	}
	return a.ac>b.ac;
}

int it,p,r;
team t[51];
int main(void){
	while(1){
		scanf("%d%d%d",&it,&p,&r);
		if(r==0)break;
		memset(t,0,sizeof(t));
		for(int i=0;i<it;i++)t[i].id=i+1;
		for(int i=0;i<r;i++){
			int ti,pi,time;
			string str;
			scanf("%d%d%d",&ti,&pi,&time);
			cin >> str;
			ti--;
			if(str=="CORRECT"){
				t[ti].ac++;
				t[ti].p+=t[ti].pp[pi]*1200+time;
			}else{
				t[ti].pp[pi]++;
			}
		}
		sort(t,t+it,comp);
		for(int i=0;i<it;i++){
			printf("%d %d %d\n",t[i].id,t[i].ac,t[i].p);
		}
	}
	return 0;
}

Measured memory_bytes: 1272
import math 
  
# A function to print all prime factors of  
# a given number n 
def primeFactors(n): 
      
    # Print the number of two's that divide n 
    while n % 2 == 0: 
        arr[2] = arr[2] + 1 
        n = int(n / 2)
          
    # n must be odd at this point 
    # so a skip of 2 ( i = i + 2) can be used 
    for i in range(3,int(math.sqrt(n))+1,2): 
          
        # while i divides n , print i ad divide n 
        while n % i== 0: 
            arr[i] = arr[i] + 1  
            n = int(n / i)
              
    # Condition if n is a prime 
    # number greater than 2 
    if n > 2: 
        arr[n] = arr[n] + 1  

# for n in range(0,101):
arr = [0] * 101
wow = [0] * 5
result = 0
n = int(input())

for i in range(2,n+1):
    primeFactors(i)

# count = 0
for i in arr:
    # if i != 0:
    #     print(count, i)
    # count = count + 1
    if i > 1: wow[0] = wow[0] + 1
    if i > 3: wow[1] = wow[1] + 1
    if i > 13: wow[2] = wow[2] + 1
    if i > 23: wow[3] = wow[3] + 1
    if i > 73: wow[4] = wow[4] + 1

# for i in wow:
#     if i != 0:
#         print(i)

x = wow[4]
y = wow[3] * (wow[0] - 1)
z = wow[2] * (wow[1] - 1)
a = wow[1] * (wow[1] - 1) * (wow[0] - 2) // 2
result = wow[4] + wow[3] * (wow[0] - 1) + wow[2] * (wow[1] - 1) + wow[1] * (wow[1] - 1) * (wow[0] - 2) // 2
print(result)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair <int,int> pii;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef long long int lli;
typedef vector <lli> vlli;
typedef vector <vlli> vvlli;
typedef vector <string> vs;
typedef vector <bool> vb;

#define rep(i, n) for( i = 0; i < (n); ++i)
#define repA(i, a, n) for( i = a; i <= (n); ++i)
#define repD(i, a, n) for( i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sortr(x) sort(x.begin(),x.end(),greater <int> ())
#define mod 1000000007
#define ff first
#define ss second
#define fill(a,c)  memset(a, c, sizeof (a))
#define formap(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.first<<" , "<<it.second<<endl;} cerr<<endl
#define PI  3.14159265358979323846
#define pb push_back

string con (int x){
    string ans(6,'0');
    int i=0;
    while (x>0){
        if (x%2)ans[i]='1';
        x=x/2;
        i++;
    }
    return ans;
}

int find (string x,string y,vs &s){
    int i,j,k=0,n=s.size(),m=s[0].size();
    for (i=0;i<6;i++){
        if (x[i]=='1'){
            for(j=0;j<m;j++){
                if (s[i][j]=='#')k++;
            }
        }
        
        if (y[i]=='1'){
            for  (j=0;j<n;j++){
                if (s[j][i]=='#')k++;
            }
        }
    }
    for  (i=0;i<6;i++){
        for(j=0;j<6;j++){
            if  (x[i]=='1'&& y[j]=='1'){
                if (s[i][j]=='#')k--;
            }
        }
    }
    return k;
}






int main() {
	cin.sync_with_stdio(0);cin.tie(0);
    cin.exceptions(cin.failbit);
    
    int i,j,k,n,m,cnt=0,ans;
    cin>>n>>m>>k;
    vs s(n);
    string a,b;
    rep(i,n)cin>>s[i];
    rep(i,n){
        rep(j,m){
            if (s[i][j]=='#')cnt++;
        }
    }
    ans=0;
    if (cnt<k);
    else{
        int d=cnt-k;
        for (i=0;i<pow(2,n);i++){
            for (j=0;j<pow(2,m);j++){
                a=con(i);b=con(j);
                if (find(a,b,s)==d)ans++;
            }
        }
    }
    cout<<ans;
    
    
    
    
    
   
   
   
	return 0;
}


Measured memory_bytes: 4088
# solution 3
import heapq
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
s = set()
heapq.heappush(Q, (-A[0]-B[0]-C[0], 0, 0, 0))
for n in range(K):
    q, i, j, k = heapq.heappop(Q)
    print(-q)
    if i < X-1 and (i+1, j, k) not in s:
            heapq.heappush(Q, (- A[i+1] - B[j] - C[k], i+1, j, k))
            s.add((i + 1, j, k))
    if j < Y-1 and (i, j+1, k) not in s:
            heapq.heappush(Q, (- A[i] - B[j+1] - C[k], i, j+1, k))
            s.add((i, j + 1, k))
    if k < Z-1 and (i, j, k+1) not in s:
            heapq.heappush(Q, (- A[i] - B[j] - C[k+1], i, j, k+1))
            s.add((i, j, k + 1))

Measured memory_bytes: 4976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		sc.close();
		int res = 0;
		for (int i=0; i<s.length(); i++) {
			if(s.charAt(i) != t.charAt(i)) res++;
		}
		System.out.println(res);
	}

}

Measured memory_bytes: 41216
def write_line(w, pattern)
  result = []
  w.times do |i|
    result.push(pattern[0]) if i.odd?
    result.push(pattern[1]) if i.even?
  end
  result.join
end

def write(h, w)
  h.times do |n|
    puts write_line(w, %w[# .]) if n.odd?
    puts write_line(w, %w[. #]) if n.even?
  end
  puts ''
end

def func
  loop do
    h, w = gets.split.map(&:to_i)
    break if [h, w].all? { |n| n == 0 }

    write(h, w)
  end
end

func


Measured memory_bytes: 7480
#include<stdio.h>

int main(){
	int rank[4];
	int M;
	int A,B,C;	
	rank[0]=rank[1]=rank[2]=0;
	for(A=0;A<10;A++){
		scanf("%d",&M);
		for(B=0;B<3;B++)
			if(rank[B]<M){
				for(C=2;C>=B;C--)
					rank[C+1]=rank[C];
				rank[B]=M;
				break;
			}
	}
	printf("%d\n%d\n%d\n",rank[0],rank[1],rank[2]);
	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

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

    vector<ll> acum(n+1);
    vector<ll> bcum(m+1);
    rep(i,n) acum[i+1] = acum[i] + a[i];
    rep(i,m) bcum[i+1] = bcum[i] + b[i];
    int ans = 0;
    rep(i,n+1) {
        ll r = k - acum[i];
        if (r >= 0) {
            auto itr = upper_bound(all(bcum), r);
            int j = itr - bcum.begin()-1;
            ans = max(ans, i+j);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9544
#include <stdio.h>

int main(void) {
	int i,a[3000],b[3000],c,m;
	
	
	for(i=0;i<3000;i++){
		scanf("%d %d\n",&a[i],&b[i]);
		if(a[i] > b[i]){
			m = a[i];
			a[i] = b[i];
			b[i] = m;
		}
		if(a[i] == 0 && b[i] == 0){
			c = i;
			break;
		}
	}
		
	for(i=0;i<c;i++){
		printf("%d %d\n",a[i],b[i]);
	}
	return 0;
}



Measured memory_bytes: 2020
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;

    vector<ll> D1(n), D2(n);
    rep(i, n) cin >> D1[i] >> D2[i];
    
    ll res = 0;
    rep(i, n) {
        if (D1[i] == D2[i]) {
            res++;
        }
        else {
            res = 0;
        }

        if (res >= 3) {
            put("Yes");
            return;
        }
    }
    put("No");
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3620
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5+7, mod = 1e9+7;
int n, k;
int a[N];
int main()
{
    scanf("%d%d",&n,&k);
   	for(int i = 0;i < n;++i)	scanf("%d",&a[i]);
    sort(a,a + n);

    int res = 1;
    int l = 0,r = n - 1;
    int sign = 1;
    if (k % 2)
    {
        res = a[r--];
        --k;
        if(res < 0) sign = -1;
    }
    while(k)
    {
        ll x = (ll)a[l] * a[l + 1], y = (ll)a[r - 1] * a[r];
        if(x * sign > y * sign)
        {
            res = x % mod * res % mod;
            l += 2;
        }
        else
        {
            res = y % mod * res % mod;
            r -= 2;
        }
        k -= 2;
    }
    printf("%d\n",(res + mod) % mod);

    return 0;
}


Measured memory_bytes: 4004
s = list( input())
l = len(s)
K = int( input())
for i in range(l-1):
    if s[i] == "a":
        continue
    if ord("z") - ord(s[i]) + 1 <= K:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"
s[l-1] = chr( ( ord(s[l-1]) - ord("a") + K)%26 + ord("a"))
print("".join(s))


Measured memory_bytes: 4156
#include <iostream>
#include <cstdio>

using namespace std;

const int P=1000000007;
const int N=2005;

int f[N][N][2];
int n,K,ans;

inline void update(int &x,int y){(x+=y)%=P;}

int main()
{
	//freopen("solitaire.in","r",stdin),freopen("solitaire.out","w",stdout);
	scanf("%d%d",&n,&K);
	f[n+1][0][0]=1;
	for (int i=n+1;i>=2;--i)
	{
		for (int j=n-1;j>=0;--j) update(f[i][j][0],f[i][j+1][0]);
		for (int j=0;j<=n;++j)
			for (int k=0;k<2;++k)
				if (f[i][j][k])
				{
					update(f[i-1][j+1][1],f[i][j][k]);
					update(f[i-1][j][0],f[i][j][k]);
				}
	}
	ans=f[1][n-K][0];
	for (int i=1;i<=n-K-1;++i) (ans<<=1)%=P;
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 31616
n = int(input())
ps = list(map(int, input().strip().split()))

count = 0
for i in range(n):
    if ps[i] == i + 1:
        count += 1
        if i < n - 1:
            ps[i], ps[i + 1] = ps[i + 1], ps[i]
        else:
            ps[i], ps[i - 1] = ps[i - 1], ps[i]

print(count)


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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    map<int, int> card;
    for ( int i = 0; i < N; i++ ) {
        int a;
        cin >> a;
        card[a]++;
    }

    int left_one = 0, left_two = 0;
    for ( auto cur = card.begin(); cur != card.end(); cur++ ) {
        int n_card = cur->second;

        /* 同じ数のカードを3枚選ぶことで2枚ずつ減らせる
         * 偶数枚なら最後に必ず2枚残り、奇数枚なら1枚残る */
        if ( n_card % 2 == 0 ) left_two++;
        else left_one++;
    }

    /* 2枚残っているカードが偶数組あれば、それらをすべて1枚にできる
     * 奇数組ならば left_one から 1組犠牲にする */
    int ans;
    if ( left_two % 2 == 0 ) ans = left_one + left_two;
    else ans = left_one + left_two - 1;

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


Measured memory_bytes: 8176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,cnt=0;
  cin>>n;
  int a[n];
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    if(i%2!=0){
      if(a[i]%2!=0)
      {
        //cout<<i<<" "<<a[i]<<endl;
        cnt++;
      }
    } 
  }
  cout<<cnt<<endl;
  return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  char a; cin >> a;
  if('a' <= a && a <= 'z') cout << 'a' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 3636
import std.stdio;
import std.string;
import std.conv;

void main(){

    int ans1=0,ans2=0;
    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	auto n = split(chomp(s),',');
	int x = to!int(n[0]);
	int y = to!int(n[1]);
	int z = to!int(n[2]);
	if(x==0||y==0||z==0)continue;
	if(x*x+y*y==z*z)ans1++;
	else if(x==y&&x+y>z)ans2++;
    }
    writef("%d\n",ans1);
    writef("%d\n",ans2);
}

Measured memory_bytes: 2408
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, K = lr()
    c = [1]*N
    for i in range(K):
        d = ir()
        A = lr()
        for j in range(d):
            c[A[j]-1] = 0
    print(sum(c))
resolve()

Measured memory_bytes: 66868
import java.util.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        Long H = sc.nextLong();
        int count = 0;
        Long ans = 0L;
        while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        }
        System.out.println(ans);
    }
}

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

int main() {
	string S, T;
	cin >> S >> T;
	int N = S.size(), M = T.size();
	int ANS = 10000000;
	for (int i = 0; i < N - M + 1; i++) {
		string U = S.substr(i, M);
		int COUNT = 0;
		for (int j = 0; j < M; j++) {
			if (T[j] != U[j]) COUNT++;
		}
		ANS = min(ANS, COUNT);
	}
	cout << ANS << endl;
}

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

long long dp[2][3003];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&k);

        for(i=1;i<=n;i++)
        {
            scanf("%lld %lld",&a,&b); vct.push_back(make_pair(a,b));
        }


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

        long long idx,cap;

        for(idx=n-1;idx>=0;idx--)
        {
            for(cap=1;cap<=k;cap++)
            {
                fr=idx%2; sc=(idx+1)%2; a=vct[idx].first; b=vct[idx].second;

                p=0; q=0;

                if(idx==n-1 || cap-a<=0){  p=b; }
                else{  p=b+dp[sc][cap-a];   }

                if(idx!=n-1){  q=dp[sc][cap];  }

                dp[fr][cap]=max(p,q);


            }
        }

        printf("%lld\n",dp[0][k]);








    return 0;
}





Measured memory_bytes: 3912
#include <iostream>

using namespace std;

int main(void){
    int i,j,k,l;
    int b,h;
    char data1[5],data2[5];
    
    while(1){
   
        cin>>data1,cin>>data2;
        if(data1[0]=='0'&&data2[0]=='0')break;
       
        b=0;
        h=0;
    

        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                if(i!=j){
                    if(data1[i]==data2[j]){
                        b++;
                }
            }else{
                if(data1[i]==data2[j]){
                    h++;
                }
            }
        }
    }
        cout<<h<<" "<<b<<endl;
    }
    return(0);
}

Measured memory_bytes: 1140
using CompLib.Util;
using System;
using System.Collections.Generic;
using System.Text;

public class Program
{
    int H, W, D;
    int[][] A;
    int Q;
    int[] L, R;
    public void Solve()
    {
        var sc = new Scanner();
        H = sc.NextInt();
        W = sc.NextInt();
        D = sc.NextInt();

        A = new int[H][];
        for (int i = 0; i < H; i++)
        {
            A[i] = sc.IntArray();
            for (int j = 0; j < W; j++)
            {
                A[i][j]--;
            }
        }
        Q = sc.NextInt();

        L = new int[Q];
        R = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            L[i] = sc.NextInt() - 1;
            R[i] = sc.NextInt() - 1;
        }

        var sb = new StringBuilder();

        var y = new int[H * W];
        var x = new int[H * W];

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                y[A[i][j]] = i;
                x[A[i][j]] = j;
            }
        }

        var sum = new List<int>[D];
        for (int i = 0; i < D; i++)
        {
            sum[i] = new List<int>();
            sum[i].Add(0);
            for (int j = i + D; j < H * W; j += D)
            {
                int dx = Math.Abs(x[j - D] - x[j]);
                int dy = Math.Abs(y[j - D] - y[j]);

                sum[i].Add(sum[i][sum[i].Count - 1] + dx + dy);
            }
        }

        for (int i = 0; i < Q; i++)
        {
            int m = L[i] % D;

            int ll = L[i] / D;
            int rr = R[i] / D;

            sb.AppendLine((sum[m][rr] - sum[m][ll]).ToString());
        }

        Console.Write(sb.ToString());
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 28400
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int n;
    cin >>n;
    vector<int> ans(n);

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

    for(int a:ans){
        cout << a << endl;
    }

}
   

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    vector<int> x(5);
    for(int i = 0; i < 5; ++i) {
        cin >> x[i];
    }
    for(int i = 0; i < 5; ++i) {
        corner(!x[i],i+1);
    }
    
    return 0;
}


Measured memory_bytes: 3636
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if A[i] > B[i]:
        ans += B[i]
    else:
        ans += (A[i] + (A[i+1] - max(A[i+1] - (B[i]-A[i]), 0)))
        A[i+1] = max(A[i+1] - (B[i]-A[i]), 0)

print(ans)

Measured memory_bytes: 19116
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    string ans;
    for(int i=0;i<2*n;i++){
        if(i%2) ans[i]=t[i/2];
        else ans[i]=s[i/2];
    }
     for(int i=0;i<2*n;i++) cout<<ans[i];
return 0;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, K;
    cin >> N >> K;
    ll count = K;
    REP(i, N - 1) {
        count *= (K - 1);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

s = deque(input())
t = deque(input())
ans = 0
for i in range(0,len(s)):
    tmp = s.pop()
    s.appendleft(tmp)
    if s == t:
        ans = 1

if ans == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3316
#include<stdio.h>

int main (void)
{
    int N,i,j,k,v;

    scanf("%d",&N);
    int A[N];
    for(i=0;i<N;i++)
    {
        scanf("%d",&A[i]);
    }

    for(k=0;k<N;k++)
    {
       printf("%d",A[k]); 
       if(k!=N-1) printf(" ");
    }

    for(i=1;i<N;i++)
    {
        v=A[i];
        j=i-1;
        while(j>=0 && A[j]>v)
        {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;

        printf("\n");        
        for(k=0;k<N;k++)
        {
           printf("%d",A[k]); 
           if(k!=N-1) printf(" ");
        }
    }
    printf("\n");

}


Measured memory_bytes: 2688
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    int n;
    cin >> n;
    ll sum = 0;
    REP(i, 1, n)sum += i;
    for(int i = n; i >= 1; i--){
        if(sum - i < n){
            cout << i << endl;
            n -= i;
        }
        sum -= i;
        if(n <= 0)break;
    }
}



Measured memory_bytes: 3156
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	
	//配列の要素数
	int n;
	//配列Aの最後の要素を示す変数
	int x;
	//交換のための変数
	int swap;
	//partition発見のための変数
	int i;
	//要素が格納される配列
	int[] A;
	
	public void input() {
		n = sc.nextInt();
		A = new int[n];
		for(int i=0; i<n; i++) A[i] = sc.nextInt();
	}
	
	public void partition() {
		x = A[n-1];
		i = -1;
		for(int j=0; j<n-1; j++) {
			if(A[j] <= x) {
				i++;
				swap = A[i];
				A[i] = A[j];
				A[j] = swap;
			}
		}
		swap = A[i+1];
		A[i+1] = A[n-1];
		A[n-1] = swap;
	}
	
	public void output() {
		for(int j=0; j<n; j++) {
			if(j == n-1) System.out.print(A[j]);
			else if(j == i+1 ) System.out.print("["+A[j]+"] ");
			else System.out.print(A[j]+" ");
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.partition();
		obj.output();
	}
}




Measured memory_bytes: 69776
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long
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; }}

using namespace std;

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

    int ans = 0;
    while (N >= pow(K, ans)) {
        ++ans;
    }

    cout << ans << endl;
} 


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

ll fact(const ll &n) {
    ll ret = n;

    if (n != 1) ret *= fact(n - 1);

    return ret;
}

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

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

    int a, b;

    cin >> a >> b;

    if (b < a) Out(a - 1);
    else Out(a);

    return 0;
}


Measured memory_bytes: 256
//author : Yogi79

#include<bits/stdc++.h>
using namespace std;

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   long n,k;
   cin>>n>>k;
   long long dp[n+1],a[n+1];
   fill(dp,dp+n+1,10000000000);

   for(int i=1;i<n+1;i++)
    cin>>a[i];

dp[1]=0;

    for(int i=2;i<n+1;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>0)
           dp[i] = min(dp[i],dp[i-j] + abs(a[i-j]-a[i])); 
        }
    }
cout<<dp[n];
}

Measured memory_bytes: 1792
score = []
count = 0
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    else:
        count += 1
        total = m + f
        if m == -1 or f == -1:
            score.append('F')
        elif total >= 80:
            score.append('A')
        elif 65 <= total < 80:
            score.append('B')
        elif 50 <= total < 65:
            score.append('C')
        elif 30 <= total < 50:
            if r >= 50:
                score.append('C')
            else:
                score.append('D')
        elif total < 30:
            score.append('F')
for i in range(count):
    print(score[i])



Measured memory_bytes: 5596
MOD = (1e+9 + 7).to_i

def chcek(n, m, a)
  (m - 1).times do |i|
    if a[i + 1] - a[i] == 1 then
      return false
    end
  end
  return true
end

def main(argv)
  (n, m) = gets.chomp.split(' ').map(&:to_i)
  
  a = [-1] * m
  m.times {|i| a[i] = gets.chomp.to_i}

  a.uniq!
  m = a.size

  unless chcek(n, m, a) then
    puts 0.to_s
    return
  end
  
  dp = [0] * (n + 2)
  dp[0] = 1
  dp[1] = 1
  n.times do |i|
    dp[i + 2] = dp[i + 1] + dp[i]
  end

  c = 1
  k = 0
  m.times do |i|
    c = (c * dp[(a[i] - 1) - k]) % MOD

    k = a[i] + 1
  end
  c = (c * dp[n - k]) % MOD
  
  puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 436732
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

string s;
int L,i;
inline void solve(){
  IN(s);
  L=s.size();
  REP(i,L)if(!(i&1))cout<<s[i];
  cout<<endl;
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 592
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC125
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).OrderBy(x => x).ToArray();
            int res = 0;
            int lastidx = -1;
            for (int i = 0; i < N; i++)
            {
                if (A[i] < 0)
                {
                    res++;
                    lastidx = i;
                }
                else
                {
                    break;
                }
            }
            long ressum = 0;
            if ((res % 2) == 0)
            {
                for (int i = 0; i < N; i++)
                {
                    if (A[i] < 0)
                    {
                        ressum -= A[i];
                    }
                    else
                    {
                        ressum += A[i];
                    }
                }
            }
            else
            {
                for (int i = 0; i < N; i++)
                {
                    if (i == lastidx)
                    {
                        if ((i + 1 < N) && ((-A[i]) > A[i + 1]))
                        {
                            ressum -= A[i];
                            ressum -= A[i + 1];
                            i++;
                            continue;
                        }
                        else
                        {
                            ressum += A[i];
                            continue;
                        }
                    }
                    if (A[i] < 0)
                    {
                        ressum -= A[i];
                    }
                    else
                    {
                        ressum += A[i];
                    }
                }
            }
            Console.WriteLine(ressum);
        }
    }
}

Measured memory_bytes: 30172
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

% 1, 1+A-1, 1+2*A-2, ...
main :-
    get_number(A, B),
    X is (B - 1 + A-2) div (A - 1),
    writeln(X).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8244
#include <iostream>
using namespace std;
long long n,m,x,total=0;
int main() {
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>x;total+=x*(i+1)*(n-i)*(j+1)*(m-j);
		}
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 3104
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(long long a, long long b){
    if(a < b) {
        REP(i, b) {
            cout << a;
        }
        cout << endl;
    }else { 
        REP(i, a) {
            cout << b;
        }
        cout<< endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

using ll = long long;

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

    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100 * (10 - n) << endl;
    }

    return 0;
}


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


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

map<ll, ll> mp;

ll rec(ll n) {
    if (n == 1)
        return 1;
    if (mp[n] > 0)
        return mp[n];
    return mp[n] = 1 + rec(n / 2) * 2;
}

int main() {
    ll h;
    cin >> h;
    cout << rec(h) << endl;

    return 0;
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let xs =
        List.map (fun _ -> reads id) [1..n]
        |> List.zip [1..n]
        |> List.map (fun (i, [s;p]) -> (s, int p, i))
    List.groupBy (fun (s,_,_) -> s) xs
    |> List.sortBy fst
    |> List.collect (snd >> List.sortByDescending (fun (_,p,_) -> p))
    |> List.iter (fun (_,_,i) -> printfn "%i" i)
    0

Measured memory_bytes: 15580
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string get_unique(string str) {
  string sort_str = str;
  std::sort(sort_str.begin(), sort_str.end());
  sort_str.erase(std::unique(sort_str.begin(), sort_str.end()), sort_str.end());
  return sort_str;
}

int main() {
  int N = 0;
  std::cin >> N;
  std::string str;
  std::string str_1;
  std::string str_2;
  std::string uni_str_1;
  std::string uni_str_2;
  std::cin >> str;
  std::vector<int> Ascee_vec(N, 0);

  int Max_count = 0;
  for (int i = 0; i < str.size(); i++) {
    str_1 = str.substr(0, i);
    str_2 = str.substr(i);

    uni_str_1 = get_unique(str_1);
    uni_str_2 = get_unique(str_2);

    int tmp_counter = 0;
    for (int i = 0; i < uni_str_1.size(); i++) {
      for (int j = 0; j < uni_str_2.size(); j++) {
        if (uni_str_1[i] == uni_str_2[j]) {
          tmp_counter += 1;
        }
      }
    }
    if (Max_count < tmp_counter) {
      Max_count = tmp_counter;
    }
  }
 std::cout << Max_count << std::endl;

  return 0;
}


Measured memory_bytes: 888