akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N,M,K;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M>>K;
	for (int32_t i = 0; i <= N; i++)
	{
		for (int32_t j = 0; j <= M; j++)
		{
			int32_t res = i*M + j*N - i*j*2;

			if (res == K) {
				out << "Yes" << endl; return 0;
			}
		}
	}
	out << "No" << endl; return 0;

	return 0;
}
#endif


Measured memory_bytes: 888
N = int(input())
S = []
S.append([0,0,0])
for _ in range(N):
    S.append(list(map(int, input().split())))
#print(S)
cnt = 0
for i in range(len(S)-1):
  time = S[i+1][0]-S[i][0]
  distance = abs(S[i+1][1]-S[i][1])+abs(S[i+1][2]-S[i][2])
  if distance>time or distance%2 != time%2:
    print('No')
    break
  else:
    cnt+=1
if cnt == len(S)-1:
  print('Yes')


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

int main(){
	int x, y;
	int a, b, r;
	int gcd;
	
	cin >> x >> y;
	
	if(x > y){
		a = x;
		b = y;
	}else {
		a = y;
		b = x;
	}
	
	do{
		r = a % b;
		gcd = a = b;
		b = r;
	}while(b != 0);
	
	cout << gcd << endl;
	return 0;
}

Measured memory_bytes: 1160
import math
N, D = map(int,input().split())
X = [list(map(int, input().split())) for _ in range(N)]

def check(i, j):
    dis = 0
    for k in range(D):
        dis += (X[i][k] - X[j][k])**2
    
    if int(math.sqrt(dis))**2 == dis:
        return 1
    else:
        return 0

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += check(i, j)
print(ans)


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

int n;
char w[50][100];
int len[50];
int main(){
	while(scanf("%d",&n),n){
		for(int i=0;i<n;i++)
			scanf(" %s",w[i]),len[i]=strlen(w[i]);
		int min=0;
		for(int k=0;k<n;k++){
			int a=0,b=0,c=0,d=0,e=0;
			bool E=false,A=false;
			while(a<=5&&b<=7&&c<=5&&d<=7&&e<=7&&E==false){
				 bool f=false;
				for(int m=k;m<n;m++){
					if(a!=5){
						a=a+len[m];
						if(A==false){
							min=m;
							A=true;
						}
						continue;
					}
					if(a==5&&b!=7){
						b=b+len[m];
						continue;
					}
					if(b==7&&c!=5){
						c=c+len[m];
						continue;
					}
					if(c==5&&d!=7){
						d=d+len[m];
						continue;
					}
					if(d==7&&e!=7){
						e=e+len[m];
						continue;
					}
					if(e==7){
						E=true;
						break;
					}
					f=true;
					break;
				}
				if(f)break;
			}
			if(E==true){
				break;
			}
		}
		printf("%d\n",min+1);
	}
}


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

int main(void) {
    int n;
    cin >> n;
    int ans = 1e9;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        int cnt = 0;
        while (a % 2 == 0) {
            a /= 2;
            cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	char c;
	cin>>c;
	if(c-'a'>=0&&c-'a'<26)
	cout<<'a';
	else
	cout<<'A';
	return 0;
}

Measured memory_bytes: 3632
def triangle(a, b, c):
    return (a + b > c and b + c > a and c + a > b)

def differ_num(a,b,c):
    return not (a == b or b == c or c == a)

N = int(input())
L = list(map(int,input().split()))
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1 ,N):
            if triangle(L[i],L[j],L[k]) and differ_num(L[i],L[j],L[k]):
                ans += 1

print(ans)

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

int main(){
	int n,sum=0,check=1000;
	std::cin>>n;

	std::vector<int> a(n);
	for (int& x : a) {
		std::cin >> x;
	}

	std::vector<int> b(n);
	for (int& x : b) {
		std::cin >> x;
	}

	std::vector<int> c(n-1);
	for (int& x : c) {
		std::cin >> x;
	}

	for (int i = 0; i < n; i++) {
		sum += b[a[i] - 1];


		if (a[i]==check+1) {
			sum += c[check-1];
		}
		check = a[i];

		//std::cout << sum << std::endl;
	}

	std::cout<<sum<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Point
{
	double x, y;

	Point() : x( 0 ), y( 0 )
	{
		return;
	}

	Point( double x, double y ) : x( x ), y( y )
	{
		return;
	}

	Point operator + ( const Point &a ) const
	{
		return Point( x + a.x, y + a.y );
	}

	Point operator - ( const Point &a ) const	{
		return Point( x + ( -a.x ), y + ( -a.y ) );
	}

	Point operator * ( const double &a ) const
	{
		return Point( x * a, y * a );
	}

	Point operator / ( const double &a ) const
	{
		return Point( x / a, y / a );
	}

	bool operator < ( const Point &a ) const
	{
		return x == a.x ? y < a.y : x < a.x;
	}
};

double distance( const Point &a, const Point &b )
{
	return sqrt( pow( a.x - b.x, 2. ) + pow( a.y - b.y, 2. ) );
}

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

	double x, y;
	char d;

	vector< Point > ps;

	while ( cin >> x >> d >> y )
	{
		ps.PB( Point( x, y ) );
	}

	const int N = ps.size();

	double res = 0;

	REP( i, 1, N - 1 )
	{
		double a = distance( ps[0], ps[i] );
		double b = distance( ps[0], ps[ i + 1 ] );
		double c = distance( ps[ i ], ps[ i + 1 ] );
		double z = ( a + b + c ) / 2;

		res += sqrt( z * ( z - a ) * ( z - b ) * ( z - c ) );
	}

	cout.precision( 7 );
	cout << fixed;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N =1e5+5;
const ll inf=1e15;
ll a[N][3],dp[N][3],n;


int main()
{
    ios_base::sync_with_stdio(false);

	cin>>n;forn(i,n)forn(j,3){cin>>a[i][j];dp[i][j]=0;}
	forn(j,3)dp[0][j]=a[0][j];
	for(int i=1;i<n;i++)
	{
		forn(j,3)forn(k,3)if(j!=k)dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
	}
	forn(j,3)dp[n-1][0]=max(dp[n-1][0],dp[n-1][j]);
	cout<<dp[n-1][0]<<endl;
}


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

using namespace std;

int p[100001];

int main () {
	int n;
	cin >> n;     
	string s, t;
	cin >> s >> t;      
	s = t + '#' + s;
	for (int i = 1;i < s.size ();i ++) {
		int j = p[i - 1];                                                                     
		while (j > 0 && s[i] != s[j]) {
			j = p[j - 1];
		}
		if (s[i] == s[j]) {
			j ++;
		}
		p[i] = j;
	}
	cout << 2 * n - p[s.size () - 1];
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

    int cnt = 1, up_down = 0;
    rep(i, n-1){
        if(up_down == 0){
            if(A[i+1] > A[i]) up_down = 1;
            else if(A[i+1] < A[i]) up_down = -1;
        }else if(up_down == 1){
            if(A[i+1] >= A[i])continue;
            else{
                cnt++; up_down = 0;
            }
        }else if(up_down == -1){
            if(A[i+1] <= A[i]) continue;
            else{
                cnt++; up_down = 0;
            }
        }
    }
    cout << cnt << ln;
}

    


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define MAX 100010

int main(){
  int n, k;
  int v[MAX], dp[MAX];
  int tmp;
  while(cin >> n >> k){
    if(n == 0 && k == 0) break;
    memset(v, 0, sizeof(v));
    memset(dp, 0, sizeof(dp));
    bool is_0 = false;
    
    for(int i = 0 ; i < k ; i++){
      cin >> tmp;
      if(tmp == 0){
	is_0 = true;
	continue;
      }
      v[tmp] = 1;
      dp[tmp] = 1;
    }
    
    int ans = 0;
   
    for(int i = 0 ; i < n ; i++){
      if(v[i] == v[i+1] && v[i] == 1) dp[i+1] = dp[i] + 1;
      ans = max(ans, dp[i+1]);
    }
  
    if(is_0){
      for(int i = 1 ; i <= n ; i++){
	if(v[i] == 0){
	  v[i] = 1;
	  int cnt = 1, t1 = i-1, t2 = i+1;
	  while(v[t1] == 1){
	    t1--;
	    if(t1 < 0) break;
	    cnt++;
	  }
	  while(v[t2] == 1){
	    t2++;
	    if(t2 > n+1) break;
	    cnt++;
	  }
	  v[i] = 0;
	  ans = max(ans, cnt);
	}
      }
    }
    cout << ans << endl;    
  }
  return 0;
}

Measured memory_bytes: 1948
def sol():
    n,k=map(int,input().split())
    ans=0
    for i in range(1,n+1):
        f=0
        while 1:
            if i>=k:
                break
            i*=2
            f+=1
        ans+=(1/n)*(1/(2**f))
    print(ans)

if __name__=="__main__":
    sol()


Measured memory_bytes: 39024
#include<bits/stdc++.h>
#define FOR(i,n) for(long long i=0;i<n;i++)
#define SFOR(i,a,b) for(long long i=a;i<b;i++)
#define RFOR(i,a,b) for(long long i=b;i>a;i--)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll sw=5,x,ans=0,cnt=0;
  cin>>x;
  cnt+=(x/11)*2;
  x%=11;
  while(x>0){
    if(sw==5){ x-=6; sw=6;}
    else{x-=5;sw=5;}
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int a,b;
signed main(){
	cin>>a>>b;
	if((a+b)%2==1)puts("IMPOSSIBLE");
	else cout<<(a+b)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N + 1), v(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
        }
    }
    cout << dp[N][W] << endl;
}



Measured memory_bytes: 80256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


double f(pii a,pii b){
    return sqrt(pow(a.first-b.first,2)+pow(a.second-b.second,2));
}

signed main(){
    FASTER;
    int n;cin>>n;
    vii v(n);cin>>v;
    sort(all(v));
    
    double ans=0;
    do{
        for(int i=0;i<n-1;i++){
            ans+=f(v[i],v[i+1]);
        }
    }while(next_permutation(all(v)));
    
    int la=1;
    for(int i=1;i<=n;i++){
        la*=i;
    }
    
    cout<<fixed<<setprecision(10)<<ans/la;
}

Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
ll a[200000];

int main(){
	cin >> n;
	rep(i,n)cin >> a[i];
	vector<ll> vl;
	rep(i,n)vl.push_back(a[i] - (i+1));
	sort(ALL(vl));
	ll ans = 0;
	ll num = vl[n/2];
	rep(i,n)ans += abs(vl[i] - num);
	if(n % 2 == 0){
		num = vl[n/2+1];
		ll sum = 0;
		rep(i,n)sum += abs(vl[i] - num);
		ans = min(ans,sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3956
#import numpy as np
H, W = map(int, input().split())
S = [0]*H
counth = [[0]*W for _ in range(H)]  
countw = [[0]*W for _ in range(H)]

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      if counth[i][j]==0:
        b=False
        for k in range(j,W):
          if S[i][k]=='#':
            b = True
            break
        if b==False:
          k+=1
        #print(S[i][j:],l)
        for l in range(j,k):
          #print(i,j,l)
          counth[i][l]=k-j
      if countw[i][j]==0:
        b=False
        for k in range(i,H):
          if S[k][j]=='#':
            b=True
            break
        if b==False:
          k+=1
        #print(S[i:][j],m)
        for l in range(i,k):
          #print(i,j,l)
          countw[l][j]=k-i
      #print(i,j,count)
#print(counth,countw)
maxim = 0
for i in range(H):
  for j in range(W):
    maxim = int(max(maxim,counth[i][j]+countw[i][j]-1))
print(maxim)

Measured memory_bytes: 124380
n = int(input())
H = list(map(int, input().split()))

dp = [10 ** 12] * (n)
dp[0] = 0
dp[1] = abs(H[1] - H[0])

for i in range(1, n-1):
  dp[i+1] = min(dp[i] + abs(H[i+1] - H[i]), dp[i-1] + abs(H[i+1] - H[i-1]))
  
ans = dp[n-1]

print(ans)

Measured memory_bytes: 13976
from collections import OrderedDict, deque


def main():
    n = int(input())
    edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
    tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.
    coloring = OrderedDict()
    for e in edges:
        a, b = e[0] - 1, e[1] - 1
        tree[a].append(b)
        tree[b].append(a)
        coloring[(a, b)] = 0

    q = deque()
    q_append = q.append
    q_popleft = q.popleft
    seen = [False] * n
    q_append(0)
    col_count_by_v = [set() for _ in range(n)]
    while len(q):
        new_v = q_popleft()
        seen[new_v] = True
        color_i = 1  # One-based index.
        for adj in tree[new_v]:
            if seen[adj]:
                continue
            q_append(adj)
            while color_i in col_count_by_v[new_v]:
                color_i += 1
            coloring[(new_v, adj)] = color_i
            col_count_by_v[new_v].add(color_i)
            col_count_by_v[adj].add(color_i)
            color_i += 1

    print(len(set(coloring.values())))
    for c in coloring.values():
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 95068
var
 n,i,j,t,s:longint;
 a:array[1..300] of longint;
begin
 readln(n);
 for i:=1 to n*2 do read(a[i]);
 for i:=1 to n*2-1 do 
  for j:=i+1 to n*2 do 
   if a[i]<a[j] then 
    begin
     t:=a[i];
     a[i]:=a[j];
     a[j]:=t;
    end;
  j:=1;
  for i:=1 to n do
   begin
    s:=s+a[j+1];
    j:=j+2;
   end;
  write(s);
end.

Measured memory_bytes: 128
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    
    int n=II();
    if(n%2==0) cout << n << endl;
    else cout << n*2 << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k, n, i, m, ans;
    cin>>k>>n;
    vector <int> a(n);
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());

    m = 0;
    ans= a[n-1] - a[0];
    m = a[0];

    for(i=1; i<n; i++)
    {
        ans = min(ans, k+ m - a[i]);
        m = a[i];
    }

    cout<<ans<<endl;

    return 0;
}


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

int main(){
    int N;
    int score1=0, score2=0;
    cin >> N;
    vector<int> a;
    for (int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end(), greater<int>());
    for (int i = 0; i < a.size(); i++){
        if(i % 2 == 0){
            score1 += a[i];
        }else{
            score2 += a[i];
        }
    }
    cout << score1 - score2 << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for(int i = 1; i <= b; i++) {
    if(a*i%b==c) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

int readInt(){
  return readln.chomp.to!int;
}

int[] readInts(){
  return readln.chomp.split.to!(int[]);
}

void main(){
  auto len = readInts().sort();
  int ret = len[0] * len[1] / 2;
  
  writeln(ret);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	for(int n,sum;scanf("%d%d",&n,&sum),n;){
		int a[20000];
		rep(i,n) scanf("%d",a+i);

		sort(a,a+n);

		int ans=0;
		rep(i,n) ans+=n-(upper_bound(a+i+1,a+n,sum-a[i])-a);
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 804
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    rs = sorted(zip(a, b))
    bs = sorted(zip(c, d))
    for bx, by in bs:
        mi = -1
        my = -1
        for i, (rx, ry) in enumerate(rs):
            if not (rx < bx and ry < by):
                continue
            if my < ry:
                mi = i
                my = ry
        if mi != -1:
            del rs[mi]
    print(N - len(rs))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (N)  # type: "List[int]"
    d = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, a, b, c, d)


if __name__ == '__main__':
    main()


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

struct NODE{
    int vertex;
    int dist;
    int kenkenpa;//0,1,2
};

queue<NODE> bfs_queue;

int N,M;
vector<int> graph[100005];
int S,T;
int dist[100005][3];

int jump_one_time(int current_kenkenpa){
    return (current_kenkenpa+1)%3;
}

int main(){

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

    cin>>N>>M;
    for(int i=1;i<=M;i++){
        int shenbenftq,shenbenxzy;
        cin>>shenbenftq>>shenbenxzy;
        graph[shenbenftq].push_back(shenbenxzy);
    }
    cin>>S>>T;

    memset(dist,-1,sizeof(dist));
    dist[S][0]=0;
    NODE start_node;
    start_node.kenkenpa=0;
    start_node.dist=0;
    start_node.vertex=S;
    bfs_queue.push(start_node);

    while(!bfs_queue.empty()){
        int current_vertex=bfs_queue.front().vertex;
        int current_dist=bfs_queue.front().dist;
        int current_kenkenpa=bfs_queue.front().kenkenpa;
        bfs_queue.pop();
        for(int edge_index=0;edge_index<graph[current_vertex].size();edge_index++){
            int next_vertex=graph[current_vertex][edge_index];
            if(dist[next_vertex][jump_one_time(current_kenkenpa)]==-1){
                dist[next_vertex][jump_one_time(current_kenkenpa)]=current_dist+1;
                NODE next_node;
                next_node.kenkenpa=jump_one_time(current_kenkenpa);
                next_node.dist=current_dist+1;
                next_node.vertex=next_vertex;
                bfs_queue.push(next_node);
            }
        }
    }

    cout<<(dist[T][0]==-1?-1:dist[T][0]/3)<<endl;

    return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
const int N=3e4;
const int inf=INT_MAX/3;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
int dp[N],ans=inf;

int main()
{
	dp[0]=0;
	int m=read(),n=read();
	for (int i=1;i<=m+10000;i++) dp[i]=inf;
	for (int i=1;i<=n;i++)
	{
		int a=read(),b=read();
		for (int j=0;j<m;j++) dp[j+a]=min(dp[j+a],dp[j]+b);
	}
	for (int i=m;i<=m+10000;i++) ans=min(ans,dp[i]);
	print(ans);

	return 0;
}

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

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


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

using namespace std;

void printa(int A[], int len, string separator) {
	cout << A[0];
	for (int i = 1; i < len; i++)
		cout << separator << A[i];
	cout << endl;
}

int insertionSort(int A[], int len, int g) {
	int cnt = 0;
	for (int i = g; i < len; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
	return cnt;
}

void shellSort(int A[], int len) {
	int cnt = 0;
	vector<int> G;
	for (int h = 1; h <= len; h = 3 * h + 1)
		G.insert(G.begin(), h);
	int m = G.size();

	for (int i = 0; i < m; i++)
		cnt += insertionSort(A, len, G[i]);

	cout << m << endl;
	printa(G.data(), m, " ");
	cout << cnt << endl;
	printa(A, len, "\n");
}

int main() {
	int n, *a;
	cin >> n;
	a = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	shellSort(a, n);
	delete[] a;
	return 0;
}

Measured memory_bytes: 4896
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int M, D;
    cin >> M >> D;
    ll cnt = 0;
    for(int i = 1; i <= M; i++) {
        for(int j = 22; j <= D; j++) {
            if(j % 10 < 2) {
                continue;
            }
            if((j / 10) * (j % 10) == i) {
                cnt++;
                // cout << i << " " << j << endl;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	int n,c,k;
	cin>>n>>c>>k;
	vi arr(n);
	for(int &i:arr)cin>>i;
	sort(arr.begin(),arr.end());
	int cnt=0;
	REP(i,0,n-1) {
		int find = arr[i]+k;
		int num = 1;
		REP(j,i+1,n) {
			if(num==c||j==n||find<arr[j]) {
				cnt++;
				i=j-1;
				break;
			}
			num++;
		}
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	//prefill();
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	for(int i=1;i<=n;i++)putchar('x');
	return 0;
}

Measured memory_bytes: 256
import math

X = int(input())
N = int(math.sqrt(2 * X)) + 1

def gauss(n):
    ans = int(n * (n + 1)/ 2)
    return(ans)

A = [gauss(i) for i in range(N + 1)]

ans = 0
for i in range(1, N + 1):
    if X == A[i]:
        ans = i
        break
    elif X > A[i - 1] and X < A[i]:
        ans = i
        break

print(ans)

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

int main() {
    int a,b,c,k;
    cin >> a >> b >> c ;
    cin >> k;
    int id;
    bool check=true;
    for(int i=0;i<k;i++){
        if(b>a){
            id = i;
            break;
        }
        b *= 2;
    }
    if(b<=a){
        check = false;
    }
    for(int i=0;i<k-id;i++){
        if(c>b){
            id = i+1;
            break;
        }
        c *= 2;
    }
    if(c<=b){
        check = false;
    }
    if(check == false){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}



int32_t main()
{
    IOS;
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n, k;
        cin>>n>>k;
        int *h = new int[n];
        for(int i = 0; i<n; i++)cin>>h[i];

        int *dp = new int[n+1];
        for(int i = 0; i<=n; i++)dp[i] = INT_MAX;

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

        }

        cout<<dp[1]<<"\n";


        delete [] h;
        
    }
    
    return 0;
}



Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n, x; cin >> n >> x;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i];
    b[0] = abs(x - a[n - 1]);
    _rep(i, 1, n) b[i] = abs(a[i] - a[i - 1]);
    ll GCD = b[0];
    rep(i, n){
        GCD = gcd(GCD, b[i]);
    }
    cout << GCD << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var X = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = int.MaxValue;

        for (int P = 1; P <= 100; P++)
        {
            var e = 0;
            for (int i = 0; i < N; i++)
            {
                e += (X[i] - P) * (X[i] - P);
            }
            ans = Math.Min(ans, e);
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 28224
import sys
input_data = input()
input_numbers = input_data.split()

if __name__ == '__main__':
    a = int(input_numbers[0])
    b = int(input_numbers[1])

    if a < b :
        print("a < b")
    elif a > b :
        print("a > b")
    else :
        print("a == b")


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

int n, ans;
string s;
map<string,bool>ada;

int main() {
	cin >> n;
	while(n--){
		cin >> s;
		if(ada[s]!=1)ans++;
		ada[s]=1;
	}
	cout << ans << '\n';
}

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

using namespace std;

int main()
{
  // int n;
  // std::cin >> n;
  // std::vector<long long> l(n);
  // for(int i = 0; i < n; i++)
  // {
  //   std::cin >> l[i];
  // }
  // std::sort(l.begin(), l.end());
  
  int n; cin >> n;
  vector<long long> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];
  sort(l.begin(), l.end()); // L をソートしておく (二分探索に必要)

  // long long res = 0;
  
  // long long ans = 0;
  // for(int i = 0; i < n; ++i)
  // {
  //   for(int j = i+1; j < n; ++j)
  //   {
  //     // int k = std::distance(l.begin(),std::lower_bound(l.begin(), l.end(), l[i]+l[j]));
  //     int k = std::lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();

  //     ans += std::max(k-(j+1),0);
  //   }
  // }
  // std::cerr << ans << std::endl;
  long long res = 0;
    
    // a と b を固定
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            // c の動ける範囲の右端を求める
            int k = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();

            // c の動ける範囲は、[j+1, k)
            res += max(k - (j+1), 0);
        }
    }
    cout << res << endl;
}




Measured memory_bytes: 256
n = int(input())
t, a = [int(item) for item in input().split()]
hs = [int(item) for item in input().split()]

temp = 10**6
for i, h in enumerate(hs):
  if abs(a - (t - h*(0.006))) < temp:
    id = i+1
    temp = abs(a - (t - h*(0.006)))
  
print(id)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i <= b; ++i)
#define per(i,a,b) for(int i = a; i >= b; --i)
#define pb push_back
#define sz(x) (int)(x).size()
#define ll long long
#define deb(x) cout << '>' << #x << ": " << x << endl;
#define all(x) (x).begin(),(x).end()
typedef vector<int> vi;
ll i = 0,j = 0, k = 0;


void solve(){
      int n;cin >> n;
      int arr[n+1];
      rep(i,1,n)cin>>arr[i];
      int dp[n+1];
      dp[0] = dp[1] = 0;
      dp[2] = abs(arr[2] - arr[1]);
      for(i = 3; i <= n; ++i){
            dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]),dp[i-2] + abs(arr[i]-arr[i-2]));
      }
      cout << dp[n];
}



signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin>>t;
    while(t--)
        solve();
}





Measured memory_bytes: 1024
import java.util.*;
import java.math.*;

class Main
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for (int i = 0; i < N; i++) {
            BigInteger a = new BigInteger(sc.next());
            String ans = a.add(new BigInteger(sc.next())).toString();
            if (ans.length() > 80) {
                System.out.println("overflow");
            } else {
                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 12000
import bisect as bs
N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for b in B:
    i = bs.bisect_left(A,b)
    k = bs.bisect_right(C,b)
    ans += i*(N-k)
print(ans)

Measured memory_bytes: 23744
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
vector<P> ans;
int N;
int a[100];
void solve(bool plus) {
  if(plus) {
    FOR(i,0,N-1) {
      ans.push_back(P(i+1,i+2));
    }
  } else {
    for(int i = N - 1; i > 0; i--) {
      ans.push_back(P(i + 1, i));
    }
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  FOR(i,0,N) cin >> a[i];
  int MAX = -1e9, MIN = 1e9;
  int mxi = -1, mni = -1;
  bool minus = false, plus = false;
  FOR(i,0,N) {
    if(MAX < a[i]) {
      MAX = a[i];
      mxi = i;
    }
    if(MIN > a[i]) {
      MIN = a[i];
      mni = i;
    }
    if(a[i] >= 0) plus = true;
    if(a[i] < 0) minus = true;
  }

  if(plus && minus) {
    if(abs(MAX) >= abs(MIN)) {
      FOR(i,0,N) {
        ans.push_back(P(mxi+1,i+1));
        a[i] += MAX;
      }
      solve(1);
    } else {
      FOR(i,0,N) {
        ans.push_back(P(mni+1,i+1));
        a[i] += MIN;
      }
      solve(0);
    }
  } else if(plus) {
    solve(1);
  } else {
    solve(0);
  }
  cout << ans.size() << endl;
  FOR(i,0,ans.size()) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

// Solve the problem of ABC45 C
func main() {
	var numString string
	fmt.Scan(&numString)
	nums := toNums(numString)
	sum := 0
	bit := len(numString) - 1
	for mask := 0; mask < 1<<uint(bit); mask++ {
		plus := make([]bool, bit)
		for i := 0; i < bit; i++ {
			plus[i] = 1<<uint(i)&mask > 0
		}
		sum += calc(nums, plus)
	}
 	fmt.Println(sum)
}

func toNums(str string) []int {
	var nums []int
	for _, r := range str {
		n, _ := strconv.Atoi(string(r))
		nums = append(nums, n)
	}
	return nums
}

func calc(nums []int, plus []bool) int {
	sum := 0
	n := nums[0]
	for i, b := range plus {
		if b {
			sum += n
			n = nums[i+1]
		} else {
			n = n*10 + nums[i+1]
		}
	}
	return sum + n
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def matDot(A,B,MOD):
    N,M,L = len(A),len(A[0]),len(B[0])
    
    res = [[0]*L for i in range(N)]

    for i in range(N):
        for j in range(L):
            s = 0
            for k in range(M):
                s = (s + A[i][k]*B[k][j]) % MOD
            res[i][j] = s
    
    return res

def matPow(A,x,MOD):
    N = len(A)
    res = [[0]*N for i in range(N)]
    
    for i in range(N):
        res[i][i] = 1
    
    for i in range(x.bit_length()):
        if (x>>i) & 1:
            res = matDot(res,A,MOD)
        A = matDot(A,A,MOD)
    
    return res

n,k = map(int,input().split())
mod = 10**9+7

a = []
for i in range(n):
    a.append(tuple(map(int,input().split())))

b = matPow(a,k,mod)

ans = 0
for i in range(n):
    for j in range(n):
        ans = (ans+b[i][j])%mod

print(ans)

Measured memory_bytes: 42092
main = do
  a <- readLn
  b <- readLn
  c <- readLn
  d <- readLn
  e <- readLn
  let s = [a,b,c,d,e]
  print $ sum (map f s) - 10 + minimum (map g s)

f x
  | x `mod` 10 == 0 = x
  | otherwise = (x `div` 10 + 1) * 10
g y
  | y `mod` 10 == 0 = 10
  | otherwise = y `mod` 10

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <sstream>
#include <string>

using namespace std;

class Solver {
    typedef map<int, int> M;
    private:
        int next(int a) {
            vector<int> d;
            int max_a = 0;
            int min_a = 0;
            for (int i = 0; i < l; ++i) {
                d.push_back(a % 10);
                a /= 10;
            }
            sort(d.begin(), d.end());
            for (int i = 0; i < l; ++i) {
                max_a = 10 * max_a + d[l - i - 1];
                min_a = 10 * min_a + d[i];
            }
            return max_a - min_a;
        }
        string format(int j, int ai, int d) {
            stringstream ss;
            ss << j << " " << ai << " " << d;
            return ss.str();
        }
    public:
        int a0, l;
        string solve() {
            M m;
            int a = a0;
            while (true) {
                int i = m.size();
                if (m.find(a) != m.end()) {
                    return format(m[a], a, m.size() - m[a]);
                }
                m[a] = i;
                a = next(a);
            }
        }
};

int main() {
    Solver s;
    while (true) {
        cin >> s.a0 >> s.l;
        if (s.l == 0) {
            return 0;
        }
        cout << s.solve() << endl;
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int>a(n);
    vector<vector<int>>g(n, vector<int>(n,0));
    rep(i, n){
        a[i] = i+1;
    }
    rep(i, m){
        int x,y;
        cin >> x >> y;
        x--; y--;
        g[x][y] = 1;
        g[y][x] = 1;
    }
    int res = 0;
/*
    rep(i,n){
        rep(j,n){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
*/
    do{
        if(a[0] == 1){
            int cnt = 0;
            for(int i = 0; i < n-1; i++){
                int x,y;
                x = a[i];
                y = a[i+1];
                x--; y--;
//                cout << x << " " << y << endl;
                if(g[x][y] == 1){
                    cnt++;
                }
                if(cnt == n -1) res++;
            }
        }
    }while(next_permutation(a.begin(),a.end()));

    cout << res << endl;
}

Measured memory_bytes: 256
expressions = raw_input( ).split( " " )
stack = []
for op in expressions:
	if "+" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a + b )
	elif "-" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a - b	)
	elif "*" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a * b )
	else:
		stack.append( int( op ) )
print( stack.pop( ) )

Measured memory_bytes: 4216
#!/usr/bin/python3
from math import gcd
import sys
input = lambda: sys.stdin.readline().strip()

n = int(input())
indet = 0
d = {}
for i in range(n):
    a, b = [int(x) for x in input().split()]
    if b < 0:
        a *= -1
        b *= -1
    if a == 0 and b == 0:
        indet += 1
        continue
    elif a == 0:
        p = (0, 1)
    elif b == 0:
        p = (-1, 0)
    else:
        g = gcd(a, b)
        p = (a // g, b // g)
    d[p] = d.get(p, 0) + 1

sizes = []
ignore = set()
for p, size in d.items():
    if p not in ignore:
        a, b = -p[1], p[0]
        if b < 0:
            a *= -1
            b *= -1
        if (a, b) in d:
            ignore.add((a, b))
            sizes.append((size, d[(a, b)]))
        else:
            sizes.append((size, 0))
M = 10**9 + 7
ans = 1
for n1, n2 in sizes:
    ans *= (pow(2, n1, M) + pow(2, n2, M) - 1)
    ans %= M
print((indet + ans - 1) % M)

Measured memory_bytes: 131676
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll mx = 0;
    ll a = 0;
    rep(i,0,s.sz){
        if(s[i]=='I')a++;
        else a--;
        mx = max(mx,a);
    }
    cout << mx << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str1,first,last,mix;
    int n,h,a;
    while(true){
        cin>>str1;
        if(str1=="-") break;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>h;
            first=str1.substr(0,h);
            last=str1.substr(h,a-h);
            mix=last+first;
            str1=mix;
            
        }
        cout<<mix<<endl;
        
    }
    return 0;
}


Measured memory_bytes: 3216