akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

    ll N; cin >> N ;
    vector<ll> a;
    rep(i,N){
        ll inp; cin >> inp;
        a.pb(inp);
    }
    sort(all(a));
    ll ans1 = a[a.size() -1];
    cout << ans1 << " ";

    ll ans2 = 0;
    ll ans = ans1;
    rep(i,N-1){
        ll num = min(a[i], ans1-a[i]);
        if(num >= ans2){
            ans2 = num;
            ans = a[i];
        }
        
    }
    cout << ans << endl;
    
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define N 1000099
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define LL long long
using namespace std;
int n;
LL a, b;
LL gcd(LL x, LL y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}
bool check(LL x)
{
    for (LL i = 2; i * i <= x; i++)
    {
        if (x % i == 0) return 0;
    }
    return 1;
}
int cal(LL x)
{
    int res = 0;
    for (LL i = 1; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            if (check(i)) res++;
            if (x / i != i && check(x / i)) res++;
        }
    }
    return res;
}
int main()
{
    cin >> a >> b;
    cout << cal(gcd(a, b)) << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    FOR(i,1,10){
        FOR(j,1,10){
            if(i*j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        string S; getline(cin, S);
        rep(i, S.size()) {
            if ('a' <= S[i] && S[i] <= 'z') S[i] = S[i] - 'a' + 'A';
            else if ('A' <= S[i] && S[i] <= 'Z') S[i] = S[i] - 'A' + 'a';
        }
        cout << S << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3148
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    
    numbers = list(range(1, n+1))

    ans = 0
    for i in numbers:
        for j in numbers:
            if j <= i:
                continue
            k = x - (i + j)
            if j < k and k <= n:
                ans += 1
    print(ans)


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N, x, half;
    cin >> N;
    half = N/2;
    vector<ll> vec_A, vec_B, A(100010, 0), B(100010, 0);
    REP(i, N) {
        cin >> x;
        if (i%2 == 0) {
            vec_A.push_back(x);
            A[x]++;
        } else {
            vec_B.push_back(x);
            B[x]++;
        }
    }
    
    // calculation
    ll res_A = 0, a, res_B = 0, b;
    REP(i, 100010) {
        if (res_A < A[i]) {
            res_A = A[i];
            a = i;
        }
        if (res_B < B[i]) {
            res_B = B[i];
            b = i;
        }
    }
    
    ll sec_A = 0, sA, sec_B = 0, sB;
    REP(i, 100010) {
        if (i != a) {
            if (sec_A < A[i]) {
                sec_A = A[i];
            }
        }
    }
    REP(i, 100010) {
        if (i != b) {
            if (sec_B < B[i]) {
                sec_B = B[i];
            }
        }
    }
    
    
    
    if (a == b) {
        ll res;
        if (res_A > res_B) {
            // A はそのまま, B は２番目に大きい
            cout << (half - res_A) + (half - sec_B) << "\n";
        } else if (res_A == res_B){
            // 大きい方を変えたほうがいい
            cout << (half - res_A) + (half - (sec_A >= sec_B ? sec_A: sec_B)) << "\n";
        } else {
            // A は２番目に大きい, B はそのまま
            cout << (half - sec_A) + (half - res_B) << "\n";
        }
    } else {
        cout << (half - res_A) + (half - res_B) << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 2812
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int p = a+b;
        int m=a-b;
        int x=a*b;
        int max = Math.max(p, Math.max(m, x));
        System.out.println(max);
    }

}

Measured memory_bytes: 22996
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }

    Scanner kbd = new Scanner(System.in);

    void run(){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n==0) break;

	    int[] ice = new int[10];
	    for(; n>0; n--){
		ice[kbd.nextInt()]++;
	    }

	    for(int i=0; i<ice.length; i++){
		if(ice[i]==0)
		    System.out.println("-");
		else{
		    while(ice[i]>0){
			System.out.print("*");
			ice[i]--;
		    }
		    System.out.println();
		}
	    }
	}
    }
}

Measured memory_bytes: 53940
from collections import deque

N, Q = map(int, input().split())
table = [[] for i in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  table[a].append(b)
  table[b].append(a)
task = [0]*N
point = [-1]*N
point[0] = 0
for i in range(Q):
  p,x = map(int, input().split())
  p -= 1
  task[p] += x
H = deque()
H.append(0)

while H:
  p = H.popleft()
  point[p] += task[p]
  for np in table[p]:
    if point[np] == -1:
      H.append(np)
      point[np] = point[p]

for i in range(N):
  print(point[i])


Measured memory_bytes: 58880
#include <cstdio>
#include <vector>

const int MAXN = 2e5 + 5;
int n, q, u, v, p, x;
int add[MAXN];
std::vector<int> con[MAXN];

void ins(int start, int end) {
    con[start].push_back(end);
    con[end].push_back(start);
}

void dfs(int cur, int father) {
    for (int i = 0; i < con[cur].size(); ++i) {
        int nxt = con[cur][i];
        if (nxt != father) {
            add[nxt] += add[cur];
            dfs(nxt, cur);
        }
    }
}

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i < n; ++i) {
        scanf("%d%d", &u, &v);
        ins(u,v);
    }
    for (int i = 1; i <= q; ++i) {
        scanf("%d%d", &p, &x);
        add[p] += x;
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) {
        printf("%d ", add[i]);
    }
    return 0;
}

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

int main(){
	vector<string> v = {"Sunny", "Cloudy", "Rainy"};
  	string s;
  	cin>>s;
  	int i;
  	for (i=0; i<3; i++)
      if (v[i]==s) break;
  	i=(i+1)%3;
  	cout<<v[i];
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int mod=1e9+7;
int a[70];
ll dp[70][2][2];
ll dfs(int pos,bool limit=1,bool add=0)
{
	if(pos==-1) return add==0;
	ll &ret=dp[pos][limit][add];
	if(ret!=-1) return ret;
	ret=0;
	int up=limit?a[pos]:1;
	if(up==1)
	{
		if(add)
			ret=(ret+dfs(pos-1,limit,1))%mod;// 1 1
		else{
			ret=(ret+dfs(pos-1,limit,0))%mod;// 1 0
			ret=(ret+dfs(pos-1,limit,1));// 0 0
		}
	}
	if(add){
		ret=(ret+dfs(pos-1,limit&&up==0,0))%mod;//1 1
		ret=(ret+dfs(pos-1,limit&&up==0,1))%mod;//0 1
	}
	else{
		//ret=(ret+dfs(pos-1,limit&&up==0,0))%mod;//0 1
		ret=(ret+dfs(pos-1,limit&&up==0,0))%mod;// 0 0
	}
	return ret;
}
int solve(ll x)
{
	memset(dp,-1,sizeof(dp));
	int pos=0;
	while(x)
	{
		a[pos++]=x%2;
		x/=2;
	}
	return dfs(pos-1);
}
int main()
{
	ll n;
	cin>>n;
	cout<<solve(n)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
#define INF INT_MAX/4
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  {
    for(int j=0;j<vertex;j++) {
      if(graph[start][j]<INF/2 && graph[j][j]<0) {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
      }
    }
  }
  
  for(int i=0;i<vertex;i++) {
    if(graph[start][i]>=INF/2) {
      cout << "INF" << endl;
    } else {
      cout << graph[start][i] << endl;
    }
  }
  return 0;
}
 
inline int fastmin(int a, int b) {
  return (((a-b)>>31)&(a-b))+b;
}

int mymin_slow(int a, int b) __attribute__((noinline));
int mymin_slow(int a, int b) {
  int t;
  if (a < b) {
    t = a;
  } else {
    t = b;
  }
  return t;
}
 
void check()
{
  for(int k=0;k<vertex;k++) {
    for(int i=0;i<vertex;i++) {
      int gik= graph[i][k];
      for(int j=0;j<vertex;j++) {
        graph[i][j]= fastmin(graph[i][j], gik+graph[k][j]);
      }
    }
  }
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
        {
          if(i==j)
            {
              graph[i][j]=0;
            }
          /*else
            {
            graph[i][j]=INF;
            }*/
        }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
    dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
      {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
      }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
      for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }  
      cout << endl;    
      }*/
   
 
}

Measured memory_bytes: 5300
n=int(input())
ans=set()
ans.add(n)
i=2
x = 1
while x * x <= n-1 :
  if (n-1) % x == 0:          
    ans.add(x)
    ans.add((n-1)//x)
  x += 1
while i*i<=n:
  t=n
  while t%i==0:
    t/=i
  if t%i==1:
    ans.add(i)
  i+=1
print(len(ans)-1)

Measured memory_bytes: 66656
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b;
  cin >> a >> b;
  int ans=1+(a-1)/2;
  if (ans>=b) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll S=0,i;string N;cin>>N;
  REP(i,N.size()){S+=N.at(i)-'0';S%=9;}
  if(S%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}


Measured memory_bytes: 3204
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //単語w
        String w = sc.next();
        //単語wを小文字変換
        w = w.toLowerCase();
        //検索回数
        int count=0;

        while(true){
            //文字列t
            String t = sc.nextLine();
            //"END_OF_TEXT"という文字列が文章の終わり
            if(t.equals("END_OF_TEXT")) break;
            //文字列tを小文字変換
            t = t.toLowerCase();
            //文字列tを半角スペースで分割して配列に登録
            String[] list = t.split(" ");
            //配列内の要素を順番に取得
            for(String str: list){
                //単語wと等しい場合、検索回数を加算
                if(str.equals(w)) count++;
            }
        }
        //検索回数を出力
        System.out.println(count);
    }

}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

#define OK { cout << "POSSIBLE\n"; exit(0); }
#define NG { cout << "IMPOSSIBLE\n"; exit(0); }

int main() {
  int N, K; cin >> N >> K;
  vector<unsigned> a(N); cin >> a;
  if (N == 1 && a[0] == K) OK;
  unsigned g = a[0];
  REP(i, 1, N) {
    if (a[i] == K) OK;
    g = __gcd(g, a[i]);
  }
  if (*max_element(a.begin(), a.end()) > K && K % g == 0) OK;
  NG;
}


Measured memory_bytes: 640
def count_inv(lst):
    ret = 0
    for i in range(len(lst)):
        for j in range(i + 1, len(lst)):
            if lst[i] > lst[j]:
                ret += 1
    return ret


def count_smaller_elements(lst):
    ret = 0
    for i in range(len(lst)):
        for j in range(len(lst)):
            if i != j and lst[i] > lst[j]:
                ret += 1
    return ret


def main():
    N, K = map(int, input().split())
    lst_A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7

    a = count_inv(lst_A)
    num1 = a * K % MOD

    b = count_smaller_elements(lst_A)
    num2 = b * (K * (K - 1) // 2) % MOD

    ans = (num1 + num2) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int A[10][10], Vis[10][10];
int N, M, fl;
inline int safe_getchar()
{
	char ch = getchar();
	while (ch != '#' && ch != '.') ch = getchar();
	return ch == '#';
}
inline void dfs(int x, int y)
{
	if (Vis[x][y]) return ;
	Vis[x][y] = 1;
	if (x == N && y == M) { fl = 1;Vis[x][y] = 2; return ;}
	int sum = 0;
	if (A[x + 1][y]) dfs(x + 1, y), ++sum;
	if (A[x][y + 1]) dfs(x, y + 1), ++sum;
	if (fl) Vis[x][y] = 2;
	if (sum == 2)
	{
		puts("Impossible");
		exit(0);
	}
}
int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
			A[i][j] = safe_getchar();
	dfs(1, 1);
	if (!fl)
	{
		puts("Impossible");
		return 0;
	}
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
			if (Vis[i][j] != 2 && A[i][j])
			{
				puts("Impossible");
				return 0;
			}
	puts("Possible");
	return 0;
}

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

class Chess{
public:
    void drawBoard(int h,int w){
        string s1 = "#.";
        for (int j=1;j<=h;j++){
            for (int i=1;i<=w;i++){
                cout << s1[(i+j)%2];
            }
            cout << endl;
        }
    }
};

int main(){
    int h,w;
    Chess *cs;

    cin >> h >> w;
    while ( not ( h==0 && w ==0 )) {
        cs= new Chess();
        cs->drawBoard(h,w);
        delete cs;
        cout << endl;
        cin >> h >> w;
    }
}




Measured memory_bytes: 3148
#include<vector>
#include<iostream>
#include<cstddef>

using si = std::int32_t;
si main(){

	si n, k;
	std::cin >> n >> k;

	si max_ = ( n - 1 ) * ( n - 2 ) / 2;
	if( max_ < k )
	{
		std::cout << -1 << "\n";
		return 0;
	}
	
	/*
	if( n == 3 && k == 1)
	{
		std::cout
			<< 2 << "\n"
			<< 1 << " " << 2 << "\n"
			<< 2 << " " << 3 << "\n";
		return 0;
	}*/

	std::cout << n*(n-1)/2 - k << "\n";
	if( k == max_ )
		for( si i{ 1 }; i < n; ++i )
			std::cout << 1 << " " << i + 1 << "\n";
	else

		for( si i{}; i<n; ++i )
			for( si j{}; j < i; ++j )
			{
				if( k > 0 && (i - j != 1 ||i-j != n-1) )
					--k;
				else
					std::cout << i + 1 << " " << j + 1 << "\n";
			}

	return 0;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int a[] = new int[103];
		int i, j, res = 0;

		for (i = 0; i < N; i++) {
			a[i] = scanner.nextInt();
		}
		LinkedList<Integer> list = new LinkedList<>();
		int R = Math.min(N, K);
		for (int A = 0; A <= R; A++) {
			for (int B = 0; B <= R - A; B++) {
				if (A == B && B == 0)
					continue;
				list.clear();
				for (i = 0; i < A; i++) {
					list.add(a[i]);
				}
				for (j = 0; j < B; j++) {
					list.add(a[N - 1 - j]);
				}
				Collections.sort(list);
				i = 0;
				while (i < K - (A + B) && i < A + B && list.get(i) < 0) {
					i++;
				}
				int s = 0;
				for (; i < A + B; i++) {
					s += list.get(i);
				}
				res = Math.max(s, res);
			}
		}
		String out = String.valueOf(res);

		System.out.println(out);
	}

}

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

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

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    int N = s.size();
    int ans = inf;

    int tile = 0;
    REP(i,N) {
        if (i % 2 == 0) {
            if (s[i] == '0') tile ++;
        }
        else {
            if (s[i] == '1') tile ++;
        }
    }
    ans = tile;
    tile = 0;
    REP(i,N) {
        if (i % 2 == 0) {
            if (s[i] == '1') tile ++;
        }
        else {
            if (s[i] == '0') tile ++;
        }
    }
    ans = min(tile,ans);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
/*@author hussein zayed ;
        ___  ___
       |\  \|\  \
       \ \  \_\  \
        \ \   ___ \USSEIN
         \ \  \\ \ \
          \ \__\\ \_\
           \|__| \|__|
    ****************************************
    */

    #include <bits/stdc++.h>
    using namespace std;
    #define fr for(int i=0;i<n;++i)
    #define fr1 for(int i=1;i<=n;++i)
    #define cinA for(int i=0;i<n;++i){cin>>arr[i];}
    #define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
    #define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
    #define ll long long
    #define lnarray sizeof(arr)/sizeof(*arr)
    #define vi vector<int>
    #define vs vector<string>
    void Fast()
    {
        ios_base :: sync_with_stdio( 0 ) ;
        cin.tie( 0 ) ;
        cout.tie( 0 ) ;
    }
    inline int RD()
    {
        int i ;
        cin>>i;
        return i;
    }

    inline float RF()
    {
        float i ;
        cin>>i;
        return i;
    }

    inline double RDO()
    {
        double i ;
        cin>>i;
        return i;
    }

    inline string RS()
    {
        string i ;
        cin>>i;
        return i;
    }

    inline ll RLL()
    {
        ll i ;
        cin>>i;
        return i;
    }



    ll sumSet(ll n)
    {
        return (1ll*n*(n+1))/2;
    }
    string s;


    bool isPrime(int n)
    {
        if(n==1)
            return false;
        for(int i=2; i*i<=n; ++i)
        {
            if(n%i==0)
                return false;
        }
        return true;
    }
    int sumDigit(int n){
    int sum =0;
      while (n != 0)
        {
            sum+=  n % 10;
            n = n / 10;
        }
        return sum;
    }

    ll power2(int n){
      ll ans=(1<<n);
      return ans;
    }

    ll sumpow2(ll n){
     ll sum=(n*(n+1)*(2*n-1))/6;
     return sum;
    }

       map<string,int>mp;

    int main(){
        Fast();
    //freopen("output.txt" , "w" , stdout);
     int n=RD();
     ll ans=0,cont=0,v;
     string s;
     while(n--){
      cin>>s;
      sort(s.begin(),s.end());
      mp[s]++;
     }
   map<string ,int> ::iterator  it;
 it=mp.begin();
 for(it;it!=mp.end();it++){
  v=it->second;
  cont=(v*(v-1))/2;
  ans+=cont;
  }
  cout<<ans;

    }


Measured memory_bytes: 11264
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	if (n % 2 == 1) {
		cout << "0\n";
	} else {
		int ans = 0;
		n /= 2;
		while (n > 0) {
			ans += n / 5;
			n /= 5;
		}
		cout << ans << "\n";
	}
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n;
        int[] ary;
        double m, a2, sub;
        while(true){
            n = scanner.nextInt();
            if(n == 0)break;
            ary = new int[n];
            m = 0;
            a2 = 0;
            for(int i = 0; i < n; i++){
                ary[i] = scanner.nextInt();
                m += ary[i];
            }
            m /= n;
            for(int i = 0; i < n; i++){
                sub = ary[i] - m;
                a2 += sub*sub;
            }
            a2 /= n;
            System.out.println(Math.sqrt(a2));

        }

    }
}



Measured memory_bytes: 31100
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a * b % 2 != 0)
    {
        cout << "Odd" << endl;
    }
    else
    {
        cout << "Even" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = uint_fast16_t; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
)X";
stringstream iss{text};
#endif

class CountOrder
{
	ll N{0};
	vector<ll> p, q;
	void inp( ) {
		iss >> N; p.resize(N); q.resize(N);
		rep(n, N) { iss >> p[n]; }
		rep(n, N) { iss >> q[n]; }
		//for_each(begin(p), end(p), [](auto x) { cout << x << "\n"; });
	}
	void change( ) {
		long long sa{0};
		if (p > q) swap(p, q);
		do {
			if (p == q) break;
			++sa;
		} while (next_permutation(begin(p), end(p)));
		p(sa);
	}
public:
	void procedures( ) {
		inp( );
		change( );
	}
};
//https://atcoder.jp/contests/abc145/tasks/abc145_c
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class CountOrder a; a.procedures( );
}

Measured memory_bytes: 3628
using System;
using System.Linq;

namespace C___Prison
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var m = int.Parse (input[1]);
            var l = new int[m];
            var r = new int[m];
            var ans = 0;
            for (var i = 0; i < m; i++)
            {
                input = Console.ReadLine ().Split (' ');
                l[i] = int.Parse (input[0]);
                r[i] = int.Parse (input[1]);
            }
            ans = r.Min () - l.Max () + 1;
            if (ans >= 0)
            {
                Console.WriteLine (ans);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}

Measured memory_bytes: 15820
s = gets.chomp.split(//).map{|s| s.to_sym}
size = s.size
(size-1).times do |i|
  if s[i] == :R && s[i+1] == :L
    s[i] = :X
    s[i+1] = :Y
  end
end

ans = Array.new(size, 0)
count = 0
xpos = -1
right = true
size.times do |i|
  c = s[i]
  if (c == :R || c == :X) && i != 0 && s[i-1] == :L # L->R/X
    if xpos >= 0
      ans[xpos] += ((1.0 * count)/2).ceil.to_i
      ans[xpos+1] += count/2
      xpos = -1
      count = 0
    end
  end
  if c == :R
    count += 1
  elsif c == :L
    count += 1
  elsif c == :X
    count += 2
    ans[i] += count/2
    ans[i+1] += ((1.0 * count)/2).ceil.to_i
    count = 0
    xpos = i
  end
end

if xpos >= 0
  ans[xpos] += ((1.0 * count)/2).ceil.to_i
  ans[xpos+1] += count/2
  xpos = -1
  count = 0
end


# puts s.split(//).join(' ')
puts ans.join(' ')


Measured memory_bytes: 11516
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

bool cp(pair<ll,ll> a,pair<ll,ll> b){
	if(a.fi<b.fi) return(1);
	else if(a.fi>b.fi) return(0);
	else{
		if(a.se<=b.se) return (1);
		return(0);
	}
}

int main()
{
	ll n;
	cin>>n;
	vector<pair<ll,ll>> v;
	
	forn(i,n){
		ll l,r;
		cin>>l>>r;
		v.pb(mp(l-r,l+r-1));
	}
	sort(v.begin(),v.end(),cp);

	/*forn(i,n){
		cout<<v[i].fi<<" "<<v[i].se<<endl;
	}*/
	ll x=0,ans=0;
	for(ll i=1;i<n;i++){
		if(v[i].fi<=v[x].se) //Think greedily and try the make the [l...r] right as  small as possible
		{
			ans++;
			if(v[i].se<=v[x].se) x=i;
		}
		else x=i; //Before i there is no contradiction..so the problem reduces to the similar problem starting from i
	}
	cout<<(n-ans);
}

Measured memory_bytes: 2420
/***********************************************
	Author：		StupidTurtle
	Date：		2017.12.06
	Email：		31601359@std.zucc.edu.cn 
***********************************************/ 

#include <iostream>
#include <algorithm>

using namespace std;

int n , a , b ;

int main (void){
	
	cin >> n >> a >> b ;
	cout << min ( n * a , b ) ;
	return 0;
}

Measured memory_bytes: 256
w,h,n = map(int,input().split())
ww=hh=0
for _ in [0]*n:
    x,y,a = map(int,input().split())
    if a == 1:
        ww = max(ww,x)
    elif a == 2:
        w = min(w,x)
    elif a == 3:
        hh = max(hh,y)
    else:
        h = min(h,y)
print((w-ww)*(h-hh)*(w>ww)*(h>hh))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll, int> pl;
const ll N = 1e5 + 100;
const ll MOD = 1e9+7;

int n, m;




int main() {
  int flag = 0;
	cin>>n>>m;
  for(int i=0;i<=n;i++) {
  	int j = n - i;
    if(m == 2 * i + 4 * j) {
    	flag = 1;
      break;
    }
  }
if(flag == 0) {
	cout<<"No"<<endl;
}else {
	cout<<"Yes"<<endl;
}
    return 0;
}


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

#define IOS ios::sync_with_stdio(0)
#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 2e6;
long long int a[N];

int main () {
    IOS;
    long long int n, k;
    cin >> n >> k;
    for(int i = 0 ; i < k ; i++ ) cin >> a[i];
    sort(a,a+k);
    long long int ans = 0;
    for(int i = 0 ; i < k - 1  ; i++ ) ans=max(ans,a[i+1]-a[i]);
    ans=max(ans,a[0]+n-a[k-1]);
    cout << n-ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    if(k > n / 2){
        cout << -1 << endl;
        return 0;
    }

    for(int i=0; i<k; ++i){
        if(i > 0)
            cout << endl;
        int a = i;
        for(int j=1; j<n; ++j){
            int b = a;
            if(j % 2 == 0)
                b += j;
            else
                b += n - j;
            b %= n;
            printf("%d %d\n", a+1, b+1);
            a = b;
        }
    }

    return 0;
}

Measured memory_bytes: 884
N,A,B=map(int,input().split())

if A*B<N or A+B-1>N:
    print(-1)
    exit()

rev=(B>A)
A,B=max(A,B),min(A,B)
B-=1
M=N
ans1=[]
ans2=[]
while M>0:
    if len(ans1)==len(ans2):
        temp=[i for i in range(M+1-A,M+1)]
        ans1.append(temp)
        M=M-A
        A-=1
    else:
        temp=[i for i in range(M+1-B,M+1)]
        temp=temp[::-1]
        ans2.append(temp)
        M=M-B
        B-=1

ans2=ans2[::-1]
res=[]
for L in ans1:
    res+=L
for L in ans2:
    res+=L

res=[val for val in res if val>0]
if rev:
    res=res[::-1]
print(*res)


Measured memory_bytes: 134796
//It doesn't matter as long as you rise to the top - Katsuki Bakugo
#include<bits/stdc++.h>
using namespace std;
     
     
#define Fast_as_duck ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define rev(i,st,n) for(int i = st; i >= n ; i--)
#define ss second
#define ff first
#define ll long long 

typedef pair <int , int> pii;

const int N = 1e5 + 10 , mod =  1000000007;

int visited[2*N];

void dfs(std::vector<int> path[] , int u , int val ,  int visited[] ){
    visited[u] = val;
    // cout << u << " " << visited[u] << "\n";
    forn(i,0,(int)path[u].size()){
        if(visited[path[u][i]]== 0){
            dfs(path , path[u][i] , val , visited );
        }
    }
}

void solve(){

    int n , m ; cin >> n >> m;

    std::vector<int> frnd[n+1];
    int x , y;
    forn(i,0,m){
        cin >> x >> y;
        frnd[x].pb(y);
        frnd[y].pb(x);
    }

    // cout << "ans from here\n\n\n";

    // std::vector<int> visited(n+1 , 0);
    int val = 0;

    forn(i,0,n){
        if(visited[i+1] == 0){  

            val++;
            visited[i+1] = val;  
            // cout << "dfs " << val << "\n";
            dfs(frnd , i+1 , val , visited);
        }
    }

    std::vector<int> ans(val+1 , 0);



    forn(i,1,n+1){
        // cout << visited[i] << " ";
        ans[visited[i]]++;
    }

    sort(ans.begin() , ans.end());
        
    cout << ans.back() << "\n";
    

    
    
        


}

int main(){
    Fast_as_duck;

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    int t = 1; 
    
    // cin >> t;
    

    while(t--){
        solve();
    }




    return 0;
}
      
       


Measured memory_bytes: 24700
#include<bits/stdc++.h>
using namespace std;
int a[111];
int main(){
    int n;
    cin>>n;
    int sum=0;
    for(int j=0;j<n;j++){
        cin>>a[j];
    }
    sort(a,a+n);
    for(int k=0;k<n;k++){
        sum+=a[k];
    }
     if(sum%10!=0){
         cout<<sum<<endl;
         return 0;
     }
    for(int i=0;i<n;i++){
        if(a[i]%10!=0){
            cout<<sum-a[i]<<endl;
            return 0;
        }
        else{
        }
    }
    cout<<0<<endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    map<int, vector<int>> frs;
    for(int i=0; i<M; i++)
    {
        int A, B;
        cin >> A >> B;
        frs[A-1].push_back(B-1);
        frs[B-1].push_back(A-1);
    }
    map<int, vector<int>> brs;
    for(int i=0; i<K; i++)
    {
        int C, D;
        cin >> C >> D;
        brs[C-1].push_back(D-1);
        brs[D-1].push_back(C-1);
    }

    vector<int> used(N, -1);
    vector<set<int>> groups;
    for(int i=0; i<N; i++)
    {
        if(used.at(i) != -1) continue;
        queue<int> q;
        q.push(i);
        used.at(i) = groups.size();
        set<int> gr;
        gr.insert(i);
        while(!q.empty())
        {
            int cp = q.front();
            q.pop();
            for(auto fr : frs[cp])
            {
                if(used.at(fr) != -1) continue;
                q.push(fr);
                used.at(fr) = used.at(i);
                gr.insert(fr);
            }
        }
        groups.push_back(gr);
    }

    for(int i=0; i<N; i++)
    {
        set<int> &gr = groups.at(used.at(i));
        int ans = gr.size() - frs[i].size() - 1;
        for(int br : brs[i])
        {
            if(gr.count(br)) ans--;
        }
        if(i != N-1) cout << ans << ' ';
        else cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 31480
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn abs(x: i32) -> i32 {
    if x > 0 {
        x
    } else {
        -x
    }
}

fn main() {
    let v: Vec<i32> = read_vec();
    let n = v[0];
    let m = v[1];

    let ab: Vec<Vec<i32>> = read_vec2(n as u32);
    let cd: Vec<Vec<i32>> = read_vec2(m as u32);

    let mut e: Vec<i32> = vec![];

    for i in 0..n {
        let mut d_min: i32 = abs(ab[i as usize][0] - cd[0][0]) + abs(ab[i as usize][1] - cd[0][1]);
        let mut p: i32 = 0;
        for j in 1..m {
            let tmp = abs(ab[i as usize][0] - cd[j as usize][0])
                + abs(ab[i as usize][1] - cd[j as usize][1]);
            if tmp < d_min {
                d_min = tmp;
                p = j;
            }
        }
        e.push(p);
    }

    for i in e {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		long ans = 1;
		long []A = new long[N];
		for(int a = 0; a < N; a++){
			A[a] = stdIn.nextLong();
		}
		for(int b = 0; b < N; b++){
			if(A[b] == 0){
				ans = 0;
				break;
			}
			else if(A[b] > (long)Math.pow(10, 18)/ans){
				ans = -1;
			}
			else{
				ans *= A[b];
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}

Measured memory_bytes: 61908
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s;

int main(){
  cin >> n;
  long long a[n]; rep(i,n) cin >> a[i];
  long long sum = 0;
  long long href = 0;
  rep(i,n) sum += a[i];
  int i=0;
  while(href + a[i] < sum/2){
    href += a[i]; i++;
  }
  // cout << sum << href << "\n";
  cout << min(abs((sum-href)-href),abs((sum-(href+a[i]))-(href+a[i]))) << "\n";
}

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

#define loop(i,a,b) for(int i=a;i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int const B = 1024;
template<class T>
struct RMQ {
    int n;
    enum : T { inf = INT_MAX };
    vector<T> Bmin;
    vector<vector<T>> dat;
    RMQ(int n_){
        n = n_;
        if(n%B) n += B-n%B;
        dat.assign(n/B,vector<T>(B,inf));
        Bmin.assign(n/B,inf);
    }
    void set(int k, T x){
        get(k) = x;
        Bmin[k/B] = inf;
        rep(i,B) Bmin[k/B] = min(Bmin[k/B], get(k/B*B+i));
    }
    int & get(int k){
        return dat[k/B][k%B];
    }
    int rmq(int l, int r){
        T res = inf;
        if(l/B != r/B){
            while(l%B) res = min(res, get(l++));
            while(r%B) res = min(res, get(--r));
            loop(i,l/B,r/B) res = min(res, Bmin[i]);
        } else {
            while(l<r) res = min(res, get(l++));
        }
        return res;
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    RMQ<int> rmq(n);
    rep(i,q){
        int c,x,y;
        cin >> c >> x >> y;
        if(c) cout << rmq.rmq(x,y+1) << endl;
        else rmq.set(x,y);
    }
}

Measured memory_bytes: 1524
#include<stdio.h>
int main(void){
  char b;
  scanf("%c",&b);
  if(b=='A'){
    printf("T\n");
  }
  else if(b=='T'){
    printf("A\n");
  }
  else if(b=='G'){
    printf("C\n");
  }
  else if(b=='C'){
    printf("G\n");
  }
return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

    private void run() {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int res;
        if (K % 2 == 0) {
            res = (K/2)*(K/2);
        } else {
            res = (K/2+1)*(K/2);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 21844
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, K;
    cin >> n >> K;
    vector<vector<long long>> X(n, vector<long long>(3, 0));
    for (int i = 0; i < n; ++i) {
        cin >> X[i][0] >> X[i][1] >> X[i][2];
    }

    int m = 3;
    int M = 1 << m;

    const long long INF = 1LL << 60;
    vector<vector<long long>> dp(K + 1,  vector<long long>(M, -INF));
    for (int i = 0; i < M; ++i) {
        dp[0][i] = 0;
    }


    long long res = -INF;
    for (int i = 0; i < n; ++i) {
 
        for (int k = K - 1; k >= 0; --k) {
            for (int j = 0; j < M; ++j) {
                if (dp[k][j] <= -INF) {
                    continue;
                }

                long long ans = dp[k][j];
                for (int s = 0; s < 3; ++s) {
                    if (j & (1 << s)) {
                        ans += X[i][s];
                    } else {
                        ans -= X[i][s];
                    }
                }
                dp[k + 1][j] = max(dp[k + 1][j], ans);
            }
        }
    }

    for (int i = 0; i < M; ++i) {
        res = max(res, dp[K][i]);
    }
    cout << res  << '\n';

    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <stdlib.h>
#include <stdio.h>

int *read_array(int n)
{
    int *array;
    int i,m;
    array = new int[n];
    for(i=0;i<n;i++){
        scanf("%d",&m);
        array[i] = m;
    }

    return array;
}

void print_array(int *array, int n)
{
    int i;
    for(i=0;i<n;i++){
        if(i!=n-1){
            printf("%d ",array[i]);
        }else{
            printf("%d",array[i]);
        }
    }
    printf("\n");
    return;
}

int main()
{
    int i,n,v,j;
    int *A;
    scanf("%d",&n);
    A = read_array(n);
    print_array(A,n);
    //printf("\n");
    
    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;
        print_array(A,n);
    }

    delete [] A;
    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){
  if(*(long long*)a > *(long long*)b) return 1;
  return -1;
}

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

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

  qsort(S, N+1, sizeof(long long), compare_int);

  long long ans = 0,cnt = 1;
  for (int i = 0; i < N; i++) {
    if(S[i] == S[i + 1]){
      cnt++;
    } else {
      ans += cnt*(cnt - 1) / 2;
      cnt = 1;
    }
  }
  ans += cnt*(cnt - 1)/2;

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int N;

int x[100], y[100];
bool checked[100];

void check(int h, int w) {
    for(int i = 0; i < N; i++) {
        if(h == y[i] and w == x[i]) checked[i] = true;
    }
}

void solve() {
    int h = 10;
    int w = 10;
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        checked[i] = false;
    }
    check(h, w);
    int M;
    cin >> M;
    while(M--) {
        char d;
        int k;
        cin >> d >> k;
        while(k--) {
            if(d == 'N') h++;
            if(d == 'S') h--;
            if(d == 'E') w++;
            if(d == 'W') w--;
            check(h, w);
        }
    }
    string ans = "Yes";
    for(int i = 0; i < N; i++) {
        if(!checked[i]) ans = "No";
    }
    cout << ans << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3040
use std::io::prelude::*;
use std::str::FromStr;

fn main() {
    let stdin = std::io::stdin();
    let mut handle = stdin.lock();
    let mut string = String::new();
    handle.read_to_string(&mut string).unwrap();
    let mut splits = string.split_whitespace();
    let num1: u32 = u32::from_str_radix(splits.next().unwrap().as_ref(), 16).
                                 unwrap();
    let num2: u32 = u32::from_str_radix(splits.next().unwrap().
                                 as_ref(), 16).unwrap();
    if num1 < num2 {
        println!("<");
    } else if num1 == num2 {
        println!("=");
    } else {
        println!(">");
    }
}


Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let s: Vec<u8> = read::<String>().into_bytes();
    let half = s.len() / 2;
    for i in 0..s.len() {
        if s[i] != s[s.len() - 1 - i] {
            println!("No");
            return;
        }
        
        if i < half && s[i] != s[half - i - 1] {
            println!("No");
            return;
        }

        if i > half && s[i] != s[s.len() - i + half] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}



Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter, defaultdict
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import queue
import bisect
MOD = 10**9 + 7
from logging import getLogger, StreamHandler, DEBUG, WARNING
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
# handler.setLevel(WARNING)
# logger.setLevel(WARNING)
logger.addHandler(handler)
def main():
    INF = 10 ** 7
    n, m = getList()
    kempa = [[] for i in range(3 * n)]
    costs = [INF for i in range(3 * n)]
    for _ in range(m):
        u, v = getList()
        kempa[3 * u - 3].append(3 * v - 2)
        kempa[3 * u - 2].append(3 * v - 1)
        kempa[3 * u - 1].append(3 * v - 3)

    # =================--探索===================
    s, t = getList()
    deq = deque()
    deq.append(3 * s - 3)
    costs[3 * s - 3] = 0
    while(deq):
        tmp = deq.popleft()
        tcost = costs[tmp]
        for nxt in kempa[tmp]:
            if costs[nxt] > tcost + 1:
                deq.append(nxt)
                costs[nxt] = tcost + 1
    # =================--探索===================
    # print(costs)
    if costs[t * 3 - 3] == INF:
        print(-1)
    else:
        print(costs[t * 3 - 3] // 3)

if __name__ == "__main__":
    main()

Measured memory_bytes: 85768
#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 main () {
  ios::sync_with_stdio(0);
  cin.tie(0);

  char a;
  cin >> a;

  if (isupper(a)) {
    cout << "A" << endl;
  }

  else if (islower(a)) {
    cout << "a" << endl;
  }
  return 0;
}


Measured memory_bytes: 3604