akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define F first
#define S second
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}

/*
(char)'1' - (int)48 = (int)1;
　1111181
*/
////////////////////////////////////////////////////

struct MyStruct
{
	int  x,y;
};


int main()
{
	int n = in();
	int m = in();
	int a = in();
	while (n != 0 || m != 0 || a != 0)
	{
		int z[120];
		rep(i, 110)z[i] = i;
		vector<MyStruct> k[1100];
		MyStruct s;
		int h;
		rep(i,m)
		{
			cin >> h >> s.x >> s.y;
			k[h].push_back(s);
		}
		for (int i = 1; i <= 1000; i++)
		{
			for (int l = 0; l < k[i].size(); l++)
			{
				swap(z[k[i][l].x], z[k[i][l].y]);
			}
		}
		cout << z[a] << endl;
		cin >> n >> m >> a;
	}
}

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

int main(void){
  int N,M,C;
  cin>>N;
  cin>>M;
  cin>>C;
  vector<int> B(M);
  vector< vector<int> > A;
  int ans = 0;
  A.resize(N);		// ()内の数字が要素数になる
  for( int i=0; i<N; i++ ){
    A[i].resize(M);
  }
  
  for(int i=0;i<M;i++){
    cin>>B[i];
  }
  for(int i = 0; i<N; i++){
    for(int j = 0; j<M; j++){
      cin>>A[i][j];
    }
  }
  
  for(int i = 0; i<N; i++){
    int val = C;
    for(int j = 0; j<M; j++){
      val += B[j]*A[i][j];
    }
    if(val>0){
      ans++;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  string s;
  set<string> st;
  for(int i=0;i<n;i++){
    cin >> s;
    st.insert(s);
  }
  cout << st.size()<<endl;
}


Measured memory_bytes: 19140
import sys
N=int(input())
A=[]
pai=int(1)
hantei=int(0)
A=list(map(int,input().split()))
for i in range(N):
    if A[i]==0:
        print("0")
        sys.exit()
for i in range(N):
    pai=pai*A[i]
    if pai>10**18:
        print("-1")
        hantei=int(1)
        break
if hantei==0:
    print(pai)


Measured memory_bytes: 21696
import heapq

N,M = map(int,input().split())

baito = [[] for i in range(M+1)]
for i in range(N):
    A,B = map(int,input().split())
    if A <= M:
        baito[A].append(B)

que = []
ans = 0
for i in range(1, M+1):
    if len(baito[i]) != 0:
        for val in baito[i]:
            heapq.heappush(que, val*-1)
    if len(que) != 0:
        ans += heapq.heappop(que)*-1

print(ans)

Measured memory_bytes: 72864
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// FAIL
void fail(){ print(-1); std::exit(0); }
//void fail(){ print("No"); std::exit(0); }

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  //ll N, M;
  //std::cin >> N >> M;
  //ll A, B, C, D;
  //std::cin >> A >> B >> C >> D;

  ll N;
  std::cin >> N;
  std::map< std::string, ll > mcnt;

  for (ll i = 0; i < N; i++) {
    std::string s;
    std::cin >> s;
    mcnt[s]++;
  }

  ll max_num = 0LL;
  for (auto& elem : mcnt) {
    max_num = std::max(max_num, elem.second);
  }

  std::vector< std::string > vs;
  for (auto& elem : mcnt) {
    if (elem.second == max_num) {
      vs.push_back(elem.first);
    }
  }

  std::sort(vs.begin(), vs.end());
  for (auto s : vs) print(s);

  return 0;
}


Measured memory_bytes: 25584
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int A = sc.nextInt();
        int ans = 0;
        if(H%A==0) {
        	ans = H/A;
        } else {
        	ans = H/A+1;
        }
        
	    System.out.println(ans);
		
    }
}

Measured memory_bytes: 21712
#include "iostream"
#include "vector"

using namespace std;

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

	vector<int> k(M);
	vector< vector<int> > s(M);
	for(int i = 0; i < M; i++){
		cin >> k[i];
		for(int j = 0; j < k[i]; j++){
			int a;
			cin >> a;
			s[i].push_back(a);
		}
	}

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

	long long ans = 0;
	for(int bit = 0; bit < (1<<N); bit++){
		bool f = true;
		for(int i = 0; i < M; i++){
			int count = 0;
			for(int j = 0; j < k[i]; j++){
				if(bit & (1<<(s[i][j]-1))){
					count++;
				}
			}

			if(count % 2 != p[i]){
				f = false;
				break;
			}
		}
		if(f){
			ans++;
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
c = list(map(int, input().split()))
x, y, z = c[0]-c[1], c[1]-c[2], c[2]-c[0]
flag = True
for i in range(2):
  c = list(map(int, input().split()))
  s, t, u = c[0]-c[1], c[1]-c[2], c[2]-c[0]
  if (x!=s) or (y!=t) or (z!=u):
    flag = False
    break
    
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9072
import sys
import numpy
def shift_only(data, num):
    count = 0
    while True:
        if detect_even(data, num):
            count += 1
            data = data / 2
        else:
            break
    return count

# input ... array
def detect_even(data, num):
    if (data % 2 == 0).sum() == num:
        return True
    else:
        return False

if __name__ == "__main__":
    input = sys.stdin.readline
    size = int(input())
    data = numpy.array(list(map(int, input().split())))
    print(shift_only(data, size))


Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>>;
using GraphEdge = vector<vector<int>>;
long long modinv(long long a, long long m=MOD) {long long b = m, u = 1, v = 0;while (b) {    long long t = a / b;    a -= t * b; swap(a, b);    u -= t * v; swap(u, v);}u %= m; if (u < 0) u += m;return u;}
//MODの割り算の際にa/＝b;をa *= modinv(b,MOD);とする。
int gcd(int a, int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int main(){
    int K;cin >> K;
    int odd = 0;
    int even= 0;
    Rep(i,K){
        if(i%2==0)odd++;
        else even++;
    }
    cout << odd * even << endl;
    return 0;
}

Measured memory_bytes: 3580
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
while(true){
   var L=Arr.shift();
   if(L==0)break;
   var arr=[0,0,0,0,0,0,0,0,0,0];
   for(var i=0;i<L;i++){
      arr[Arr.shift()]++;
   }
   for(var i=0;i<10;i++){
      if(arr[i]==0)console.log("-");
      else console.log(Array(arr[i]+1).join("*"));
   }
}

Measured memory_bytes: 10292
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define p(x) cout<< x << " ";
#define pe(x) cout<< x << endl ;
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define el endl
#define M 998244353 
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 1e5 + 5;

int32_t main() 
{ 
    int n;
    cin>>n;
    int a[n][3],dp[n][3];
    memset(dp,0,sizeof(dp));
    FOR(i,0,n)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    FOR(i,1,n)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    
    
    
    
} 

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
//int k = 0;
vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }

    //int p = min(int(out.size()+k), int(d));
    //cout << p << endl;
    //if(out.size() >= d) return score;
    //cout << k << endl;
    //cout << out.size() << " " << d << endl;
    //int p = min(int(out.size()+k), d);
    //int k = 13;
    //int p = min(int(out.size()+k), d);
    ll q = LLONG_MIN;
    for(int k = 0; k < 26; k++) {
        int p = out.size()+k;
        ll tmp = 0;
        for(int i = out.size(); i < p; i++) {
            for(int j = 0; j < 26; j++) {
                //score -= c[j]*((i)-last[j]);
                tmp -= c[j]*((i+1)-last[j]);
            }
        }
        if(tmp < q) {
            q = tmp;
        }
    }
    return score-q;
}

/*
vector<int> proc(int k) {
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
    //cout << "k: " << k << endl;
    //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    return out;
}
*/

int main() {
    init();
    
    vector<int> out;
    ll ans = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            //for(int k = 0; k < 26; k++) {
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            //}
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 3728
#include<stdio.h>
#include<string.h>
   
int LCS(char *X, char *Y){
  int i,j,m,n,c[1001][1001];
  m = strlen(X);
  n = strlen(Y);
     
  for(i=0; i<m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<n; j++){
    c[0][j] = 0;
  }
   
  for(i=1;i<m+1;i++){
    for(j=1;j<n+1;j++){
      if (X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else if (c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  return c[i-1][j-1];
}
   
int main(){
  int i, q;
  char X[1001], Y[1001];
     
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%s", X);
    scanf("%s", Y);
    printf("%d\n", LCS(X, Y));
   
  }
  return 0;
}

Measured memory_bytes: 6652
#include<bits/stdc++.h>
#define ll long long
#define INF 1e18
#define N 2010
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
struct Info{int nu,ne,qu,fi;}a[N*20];
int s,t,n,z1,z2,z3,z4,x,y,z,num=1,b[N],li[1000010],la[N],mi[N];
ll di[N],ansn;
bool vi[N];
void jb(int x,int y,int z,int p){
	a[++num].nu=y;a[num].ne=b[x];b[x]=num;a[num].qu=z;a[num].fi=p;
	a[++num].nu=x;a[num].ne=b[y];b[y]=num;a[num].qu=0;a[num].fi=-p;
}
bool dij(){
	for (int i=1;i<=t;i++)di[i]=INF,vi[i]=1,mi[i]=0;di[s]=0;vi[s]=0;mi[s]=100;
	int l=1,r=1;li[l]=s;
	while (l<=r){
		for (int y=b[li[l]];y;y=a[y].ne){
			if (a[y].qu!=0){
				if (di[li[l]]+a[y].fi<di[a[y].nu]){
					di[a[y].nu]=di[li[l]]+a[y].fi;la[a[y].nu]=y;mi[a[y].nu]=min(mi[li[l]],a[y].qu);
					if (vi[a[y].nu]){vi[a[y].nu]=0;li[++r]=a[y].nu;}
				}
			}
		}
		vi[li[l]]=1;l++;
	}
	if (di[t]==INF) return 0;
	ansn=ansn-di[t]*mi[t];
	for (int i=t;i!=s;){
		i=la[i];
		a[i].qu-=mi[t];a[i^1].qu+=mi[t];
		i=a[i^1].nu;
	}
	return 1;
}
int main(){
	read(n);
	s=n+n+5,t=n+n+6,z1=n+n+1,z2=n+n+2,z3=n+n+3,z4=n+n+4;
	for (int i=1;i<=n;i++){
		read(x);read(y);read(z);
		jb(s,i,z,0);
		jb(i,z1,z,x+y);jb(i,z2,z,x-y);jb(i,z3,z,-x-y);jb(i,z4,z,-x+y);
	}
	for (int i=1;i<=n;i++){
		read(x);read(y);read(z);
		jb(i+n,t,z,0);
		jb(z3,i+n,z,x+y);jb(z4,i+n,z,x-y);jb(z1,i+n,z,-x-y);jb(z2,i+n,z,-x+y);
	}
	while (dij());
	cout<<ansn<<endl;
	return 0;
}

Measured memory_bytes: 2560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

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

class AWhiteCells {
 public:
  void solve(std::istream &in, std::ostream &out) {
      int ans = 0;
      int H, W, h, w;
      in >> H >> W >> h >> w;

      ans = H * W;

      for (int i = 0; i < H; ++i)
          for (int j = 0; j < W; ++j) {
              if (i < h || j < w)
                  ans--;
          }
      out << ans << '\n';
  }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    AWhiteCells solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

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

struct record {
    struct record *prev;
    struct record *next;
    int key;
} ;

record *head = (record *)malloc(sizeof(record));

void init()
{
    head->prev = head;
    head->next = head;
    head->key  = -1;
}

void insert(int x)
{
    record *p = (record *)malloc(sizeof(record));
    p->next = head->next;
    head->next = p;
    p->prev = head;
    p->next->prev = p;
    p->key = x;
     
}

void _delete(int x)
{
    record *p = head->next;
    while (p->key != x){
        if (p->key == -1){
            break;
        }else {
        p = p->next;
        }
    }
    if(p->key != -1) { 
        p->next->prev = p->prev;
        p->prev->next = p->next;
        free(p);
    }
}

void deleteFirst()
{
    if (head->next->key == -1){
        printf("リストは空です");
        exit(0);
    }
    record *p = head->next;
    head->next = p->next;
    head->next->prev = head;
    free(p);
}

void deleteLast()
{
    if (head->prev->key == -1){
        printf("リストは空です");
        exit(0);
    }
    record *p = head->prev;
    head->prev = p->prev;
    head->prev->next = head;
    free(p);
}

void list_out()
{
    if (head->next->key == -1){
        printf("出力できません");
        exit(0);
    }
    record *p = head->next;
    printf("%d", p->key);
    p = p->next;
    while(p->key != -1){
        printf(" %d", p->key);
        p = p->next;
    }
    printf("\n");
}

int main()
{
    init();
    int n, x;
    char order[20];
    scanf("%d", &n);

    for (int i = 0; i < n; i++){
        scanf("%s", order);
        
        if (order[0] == 'i') {
            scanf("%d", &x);
            insert(x);
        } else if (order[6] == '\0'){
            scanf("%d", &x);
            _delete(x);
        } else if(order[6] == 'F'){
            deleteFirst();
        } else {
            deleteLast();
        }
    }
    list_out();
    return 0;
}


Measured memory_bytes: 34016
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, M;
int seg = 1<<17;
vector<vector<pair<int, ll>>> e(6*seg);

void dfs(vector<int> &v, int L, int R, int k=0, int l=0, int r=-1){
    if(r == -1) r = seg;
    if(R <= l || r <= L) return;
    if(L <= l && r <= R){
        v.pb(k);
        return;
    }
    dfs(v, L, R, k*2+1, l, (l+r)/2);
    dfs(v, L, R, k*2+2, (l+r)/2, r);
}

long long dijkstra(vector<vector<pair<int, long long>>> e, int s, int t){
    vector<long long> cost(e.size(), 1e18L);
    priority_queue<pair<long long, int>> pq;
    cost[s] = 0;
    pq.push({ 0,s });
    while(!pq.empty()){
        int n = pq.top().second;
        if(-pq.top().first != cost[n]){
            pq.pop();
            continue;
        }
        pq.pop();
        for(int i=0; i<e[n].size(); i++){
            if(cost[e[n][i].first] > cost[n] + e[n][i].second){
                cost[e[n][i].first] = cost[n] + e[n][i].second;
                pq.push({ -cost[e[n][i].first], e[n][i].first });
            }
        }
    }
    return cost[t];
}

signed main(){
    cin >> N >> M;
    rep(i, seg-1){
        e[2*seg + i].pb({ 2*seg + 2*i+1, 0 });
        e[2*seg + i].pb({ 2*seg + 2*i+2, 0 });
    }
    rep(i, seg){
        e[2*seg + seg-1+i].pb({ i,0 });
    }
    rep(i, seg){
        int k = seg-1+i;
        while(k != 0){
            e[i].pb({4*seg + k, 0});
            k = (k-1) / 2;
        }
        e[i].pb({ 4*seg,0 });
    }

    rep(i, M){
        int L, R; ll C;
        cin >> L >> R >> C;
        L--;
        vector<int> v;
        dfs(v, L, R);
        rep(j, v.size()){
            rep(k, v.size()){
                e[4*seg + v[j]].pb({ 2*seg + v[k], C });
            }
        }
    }

    /*rep(i, e.size()){
        rep(j, e[i].size()){
            cout << i << " " << e[i][j].first << endl;
        }
    }*/

    ll ans = dijkstra(e, 0, N-1);
    if(ans >= 1e18L) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 908184
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

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

  for(int i=0;i<n;i++){
    string str1, str2;
    string ans;
    cin >> str1 >> str2;

    int str_i=0, str_x=0, str_c=0, str_m=0;
    char c1[9],c2[9];
    strcpy(c1, str1.c_str());
    strcpy(c2, str2.c_str());

    for(int j=str1.size()-1;j>=0;j--){
      if(c1[j]=='m'||c1[j]=='c'||c1[j]=='x'||c1[j]=='i') {
        if(j>0){
          if(c1[j-1]>='2'&&c1[j-1]<='9'){
            if(c1[j]=='i') str_i+=(int)(c1[j-1]-'0');
            if(c1[j]=='c') str_c+=(int)(c1[j-1]-'0');
            if(c1[j]=='x') str_x+=(int)(c1[j-1]-'0');
            if(c1[j]=='m') str_m+=(int)(c1[j-1]-'0');
          }else{
            if(c1[j]=='i') str_i++;
            if(c1[j]=='c') str_c++;
            if(c1[j]=='x') str_x++;
            if(c1[j]=='m') str_m++;
          }
        }else{
          if(c1[j]=='i') str_i++;
          if(c1[j]=='c') str_c++;
          if(c1[j]=='x') str_x++;
          if(c1[j]=='m') str_m++;
        }
      }
    }

    for(int j=str2.size()-1;j>=0;j--){
      if(c2[j]=='m'||c2[j]=='c'||c2[j]=='x'||c2[j]=='i') {
        if(j>0){
          if(c2[j-1]>='2'&&c2[j-1]<='9'){
            if(c2[j]=='i') str_i+=(int)(c2[j-1]-'0');
            if(c2[j]=='c') str_c+=(int)(c2[j-1]-'0');
            if(c2[j]=='x') str_x+=(int)(c2[j-1]-'0');
            if(c2[j]=='m') str_m+=(int)(c2[j-1]-'0');
          }else{
            if(c2[j]=='i') str_i++;
            if(c2[j]=='c') str_c++;
            if(c2[j]=='x') str_x++;
            if(c2[j]=='m') str_m++;
          }

        }else{
          if(c2[j]=='i') str_i++;
          if(c2[j]=='c') str_c++;
          if(c2[j]=='x') str_x++;
          if(c2[j]=='m') str_m++;
        }
      }
    }

    if(str_i>=10){
      str_i-=10;
      str_x++;
    }
    if(str_x>=10){
      str_x-=10;
      str_c++;
    }
    if(str_c>=10){
      str_c-=10;
      str_m++;
    }

    if(str_m==1) ans = ans + 'm';
    else if(str_m!=0) ans=ans+to_string(str_m)+'m';
    if(str_c==1) ans = ans + 'c';
    else if(str_c!=0) ans=ans+to_string(str_c)+'c';
    if(str_x==1) ans = ans + 'x';
    else if(str_x!=0) ans=ans+to_string(str_x)+'x';
    if(str_i==1) ans = ans + 'i';
    else if(str_i!=0) ans=ans+to_string(str_i)+'i';

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1248
S = input()
List = list(S)
odd = []
even = []

for i in range(len(List)):
  if i % 2 == 0:
    odd.append(List[i])
  else:
    even.append(List[i])

if set(odd).issubset({'R','U','D'}) and set(even).issubset( {'L','U','D'}):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int n;

int f(int64_t m, int a, int b, int c) {
    int ret=0;
    if (m > n) return 0;
    if (a > 0 && b > 0 && c > 0) ret++;
    ret += f(m*10+3, a+1, b, c);
    ret += f(m*10+5, a, b+1, c);
    ret += f(m*10+7, a, b, c+1);
    return ret;
}

int main() {
    cin >> n;
    ct(f(0, 0, 0, 0));
}

Measured memory_bytes: 256
n = int(input())
a = [0]+[int(i) for i in input().split()]+[0]
ans = sum(abs(a[i+1] - a[i]) for i in range(n+1))
for i in range(1, n+1):
  print(ans - abs(a[i+1] - a[i]) - abs(a[i] - a[i-1]) + abs(a[i+1] - a[i-1]))

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int count=0;
    for(int i=0; s[i]!='\0'; i++){
        if(s[i]=='+')count++;
        else count--;
    }
    cout<<count<<endl;

    return 0;
}


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

using namespace std;

using dijkstra_cost = long long;

template<class T>
struct Graph {
	struct Vertex {
		T cost;
		Vertex(T v1) : cost(v1) {}
		Vertex() {}
	};
	struct Edge {
		int to;
		T cost;
		Edge(int t, T c) : to(t), cost(c) {}
		Edge() {}
	};
	int sz;
	vector<Vertex> v;
	vector<vector<Edge>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = Vertex(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Dijkstra : public Graph<T> {
	Dijkstra(int n) : Graph<T>(n) {}
	void Dijkstra_solve(int s, dijkstra_cost INF_COST) {
		auto& v = this->v;
		auto& e = this->e;
		for (auto& vv : v) vv.cost = INF_COST;
		using Q_T = pair<dijkstra_cost, int>;
		priority_queue<Q_T, vector<Q_T>, greater<>> q;
		q.emplace(0, s);
		while (!q.empty()) {
			auto a = q.top();
			q.pop();
			if (a.first >= v[a.second].cost) continue;
			v[a.second].cost = a.first;
			for (auto& p : e[a.second]) {
				if (p.cost == INF_COST) continue;
				if (a.first + p.cost < v[p.to].cost) q.emplace(a.first + p.cost, p.to);
			}
		}
	}
};

void SoundHound2018_D() {
	int N, M, s, t;
	cin >> N >> M >> s >> t;
	s--;t--;
	Dijkstra<long long> G(N), G2(N);
	for (int i = 0; i < M; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--;b--;
		G.add_edge(a, b, c);
		G.add_edge(b, a, c);
		G2.add_edge(a, b, d);
		G2.add_edge(b, a, d);
	}
	G.Dijkstra_solve(s, LLONG_MAX);
	G2.Dijkstra_solve(t, LLONG_MAX);
	vector<long long> ans(N);
	for (int i = 0; i < N; i++) {
		ans[i] = G.v[i].cost + G2.v[i].cost;
	}
	for (int i = N - 1; i > 0; i--) {
		ans[i-1] = min(ans[i], ans[i-1]);
	}
	for (int i = 0; i < N; i++) {
		cout << (long long) 1e15 - ans[i] << endl;
	}
}

int main() {
	SoundHound2018_D();
}

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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector<int> up(n), parent(n, -1);
  function<void(int)> dfs = [&](int x) {
    if (x) {
      up[x] = max(up[parent[x]], parent[x]);
    }
    for (auto y : adj[x]) {
      if (y != parent[x]) {
        parent[y] = x;
        dfs(y);
      }
    }
  };
  dfs(0);
  vector<int> p(n), size(n);
  for (int i = 0; i < n; ++i) {
    p[i] = i;
    if (i) {
      size[i] = 1;
    }
  }
  auto find = [&](int x) {
    while (x != p[x]) {
      x = p[x] = p[p[x]];
    }
    return x;
  };
  vector<vector<int>> sub(n);
  for (int i = 1; i < n; ++i) {
    sub[up[i]].push_back(i);
  }
  vector<int> value(n), answer(n);
  for (int i = 0; i < n; ++i) {
    for (auto x : sub[i]) {
      if (x < i) {
        answer[x] = size[find(x)];
      } else {
        answer[x] = 1;
        for (auto y : adj[x]) {
          if (y < i) {
            if (y != parent[x]) {
              value[y] = size[find(y)];
            }
            answer[x] += size[find(y)];
          }
        }
      }
    }
    for (auto j : adj[i]) {
      if (j < i) {
        int x = find(i), y = find(j);
        size[x] += size[y];
        p[y] = x;
      }
    }
  }
  vector<int> pos(n);
  vector<int> st;
  function<void(int)> solve = [&](int x) {
    pos[x] = st.size();
    st.push_back(x);
    if (x) {
      answer[x] += answer[up[x]] - (x == up[x] ? 0 : value[st[pos[up[x]] + 1]]);
    }
    for (auto y : adj[x]) {
      if (y != parent[x]) {
        solve(y);
      }
    }
    st.pop_back();
  };
  solve(0);
  for (int i = 1; i < n; ++i) {
    printf("%d%c", answer[i], i == n - 1 ? '\n' : ' ');
  }
  return 0;
}


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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> LR(N);
    for(int i=0; i<N; i++) {
        int l, r;
        cin >> l >> r;
        LR[i] = {l, r+1};
    }
    sort(LR.begin(), LR.end());

    Segtree<int> Lmax(N, [](int a, int b){ return max(a, b); }, -1e9);
    Segtree<int> Rmin(N, [](int a, int b){ return min(a, b); }, 1e9+1);
    for(int i=0; i<N; i++){
        Lmax.update(i, LR[i].first);
        Rmin.update(i, LR[i].second);
    }

    int ans = 0;

    // 1区間孤立
    for(int i=0; i<N; i++){
        int res1 = LR[i].second - LR[i].first;
        int r2 = min(Rmin.between(0, i-1), Rmin.between(i+1, N-1));
        int l2 = max(Lmax.between(0, i-1), Lmax.between(i+1, N-1));
        int res2 = max(0, r2-l2);
        ans = max(ans, res1 + res2);
    }

    // 左端ソートしてある境目で二分
    for(int i=1; i<N; i++){
        int res1 = Rmin.between(0, i-1) - Lmax.between(0, i-1);
        int res2 = Rmin.between(i, N-1) - Lmax.between(i, N-1);
        int res = max(0, res1) + max(0, res2);
        ans = max(ans, res);
    }

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


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

int main() {
  ll A, B, C, K; cin>>A>>B>>C>>K;
  if(A>=K) cout<<K<<endl;
  else if(A+B>=K) cout<<A<<endl;
  else cout<<2*A+B-K<<endl;
}

Measured memory_bytes: 3636
n, m = gets.split.map(&:to_i)

stores = n.times.map{|i| 
    gets.split.map(&:to_i)
}.sort_by{|it| it[0]}

spent = 0
to_buy = m
stores.each{|price, count|
    if count >= to_buy
        spent += to_buy * price
        break
    else
        spent += count * price
        to_buy -= count
    end
}

puts spent


Measured memory_bytes: 12664
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.split("\n");
var nq=arr[0].split(" ").map(Number);
var s = arr[1];
var a=[0,0];
var cnt=0;
for(var i=1;i<s.length;i++){
   if(s[i]=="C" && s[i-1]=="A")cnt++;
   a.push(cnt);
}
var ans=[];
while(ans.length < nq[1]) {
   var lr=arr[ans.length+2].split(" ");
   ans.push(a[parseInt(lr[1])]-a[parseInt(lr[0])]);
}
console.log(ans.join("\n"));

Measured memory_bytes: 34744
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

ll mypow(ll x, ll n) {
    ll ret = 1;
    for(int i=0; i<n; ++i) {
        ret *= x;
    }
    return ret;
}

ll gcd(ll x, ll y) {
    if(y == 0) return x;
    else return gcd(y, x%y);
}

class rational {
public:
    rational() 
        : num_(0), dom_(0) // 0/0 represents 0
    {}

    void print() {
        if(dom_ == 0 || dom_ == 1) {
            cout << num_ << endl;
        } else {
            cout << num_ << '/' << dom_ << endl;
        }
    }
    void add(ll num, ll dom) {
        if(dom_ == 0) {
            num_ = num;
            dom_ = dom;
        } else {
            num_ = num_ * dom + num * dom_;
            dom_ *= dom;
        }
        ll g = gcd(abs(num_), dom_);
        num_ /= g;
        dom_ /= g;
    }
    
private:
    ll num_, dom_;
};

int main() {
    string str;
    while(cin >> str, str != "#") {
        int i=0;
        rational ret;
        int n=0;
        reverse(str.begin(), str.end());
        while(i < str.size()) {
            if(str[i] == 't') { // tsew
                ret.add(90, mypow(2, n));
                i += 4;
            } else if(str[i] == 'h') { // htron
                if(n != 0) {
                    ret.add(-90, mypow(2, n));
                }
                i += 5;
            }
            n += 1;
        }
        ret.print();
    }
}


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

int main(){
    string s;
    cin >> s;
    int stack = 0;
    int p = 0;
    rep (i,(int)s.length()) {
        if (s[i] == 'S') stack++;
        else if (stack > 0) stack--,p++;
    }
    cout << (int)s.length() - p*2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, W;
int dp[200000];
int w[200000], v[200000];
signed main() {
	cin >> n >> W;
	for (int i = 1; i <= W; i++) {
		dp[i] = -1;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
		for (int j = W - w[i]; j >= 0; j--) {
			if (dp[j] >= 0) {
				dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
				ans = max(ans, dp[j + w[i]]);
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a==b || a-b==1 || b-a==1)cout<<a+b;
    else if(a>b)cout<<a+a-1;
    else cout<<b+b-1;
}

Measured memory_bytes: 256
n,*t=map(int,open(0).read().split())
*z,=sorted(zip(*[iter(t)]*2))
s=set()
for i in range(n-1):
    if i in s:
        continue
    x,l=z[i]
    j=i+1
    while 1:
        y,r=z[j]
        if x+l>y-r:
            if y+r<x+l:
                s|={i}
                break
            else:
                s|={j}
        else:
            break
        j+=1
        if j==n:break
print(n-len(s))

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

using namespace std;

int main() {
  int n;
  long long a = 2, b = 1;
  scanf("%d", &n);
  while (--n) {
    long long t = a + b;
    a = b;
    b = t;
  }
  cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;

        if (n % ((d * 2) + 1) == 0) {
            ans = n / ((d * 2) + 1);
        } else {
            ans = n / ((d * 2) + 1) + 1;
        }
        

        System.out.println(ans);

        sc.close();
    }    
}


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

using namespace std;
#define ll unsigned long long
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}

int main() {
	int n;
	cin >> n;
	ll a;
	ll ans = 1;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ll g = gcd(a, ans);
		ans = (a / g)*ans;
	}
	cout << ans << endl;
	

	//system("pause");
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> dist(n+1, vector<int>(n+1, 1000));
    for (int i=0; i<n+1; ++i) {
        dist[i][i] = 0;
    }
    int r, k;
    for (int i=0; i<n; ++i) {
        cin >> r >> k;
        int t;
        for (int j=0; j<k; ++j) {
            cin >> t;
            dist[r][t] = 1;
        }
    }
    for (int k=0; k<n+1; ++k) {
        for (int i=0; i<n+1; ++i) {
            for (int j=0; j<n+1; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int p;
    cin >> p;
    int s, d, v;
    for (int i=0; i<p; ++i) {
        cin >> s >> d >> v;
        if (dist[s][d] == 1000 || v < dist[s][d]+1) {
            cout << "NA" << endl;
        } else {
            cout << dist[s][d]+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1256
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))

    # しゃくとり法の練習
    res = 0
    right = 0
    sumA = 0# leftからrightまでの算術和（=論理和）

    for left in range(N):
        while right < N and (sumA+A[right]) == sumA^A[right]:
            sumA += A[right]
            right += 1

        res += right - left
        if left == right:
            right += 1
        else:
            sumA -= A[left]

    print(res)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#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 REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define IN(x) cin >> x
#define DE(x) cerr << (x) << " "
#define BR cerr << "\n"
#define OUT(x) cout << (x) << endl
#define FIX cout << fixed << setprecision(10)

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;

int main(void){
  ll D;
  IN(N);
  IN(D);
  REP(i, N) {
    ll X, Y;
    IN(X);
    IN(Y);
    if (X*X + Y*Y <= D*D) {
      ret++;
    }
  }

  OUT(ret);

}


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

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());

    int alice, bob;
    alice = 0;
    bob = 0;
    rep (i, a.size()) {
        if (i%2==0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
    
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int arr[]=new int[a];
		for(int i=0;i<a;i++)
			arr[i]=sc.nextInt();
		int l=0,r=a-1;
		int s=arr[l]-arr[r];
		while(l<r-1){
			if(s<=0){
			l++;
            s=s+arr[l];			
			}
				else{
					r--;
					s=s-arr[r];
				}
		}
		System.out.println(Math.abs(s));
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cstdio>
#include <complex>
using namespace std;

double cross(complex<double> a, complex<double> b) {
  return (a * conj(b)).imag();
}

int main() {
  int n, j = 1;
  while (cin >> n, n) {
    vector<complex<double> > v(n);
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      v[i] = complex<double>(a, b);
    }
    double sum = cross(v[0], v[n-1]);
    for (int i = 1; i < n; i++) {
      sum += cross(v[i], v[i-1]);
    }
    sum = abs(sum) / 2;
    printf("%d %.1f\n", j, sum);
    j++;
  }
}

Measured memory_bytes: 1224
using System;
class test
{
	static void Main()
	{
		int[] ms = new int[10];
		for ( int i=0; i<10; i++ )
		{
			ms[i] = int.Parse(Console.ReadLine());
		}
		Array.Sort(ms);
		Console.WriteLine(ms[9]);
		Console.WriteLine(ms[8]);
		Console.WriteLine(ms[7]);
	}
}

Measured memory_bytes: 5728
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */

int main()
{

	int		R,G,B,N;
	int		t,tt;
	int		r,g,b;
	int		ans = 0;

	scanf("%d %d %d %d", &R, &G, &B, &N);

	for (r=0; r*R<=N; r++) {
		t = r*R;
		for (g=0; t+g*G<=N; g++) {
			tt = t + g*G;
			if ((N-tt)%B == 0) {
				ans++;
			}
		}
	}
	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 128
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      static final long MOD = 1000000007L;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         int A = Integer.parseInt(st.nextToken());
         int B = Integer.parseInt(st.nextToken());
         long[] fac = new long[200001];
         long[] invfac = new long[200001];
         fac[0] = invfac[0] = 1L;
         for(int i=1; i <= 200000; i++)
         {
            fac[i] = (fac[i-1]*i)%MOD;
            invfac[i] = power(fac[i], MOD-2, MOD);
         }
         /*
         long[] fac = new long[200001];
         long[] invfac = new long[200001];
         fac[0] = invfac[0] = 1L;
         for(int i=1; i <= 200000; i++)
            fac[i] = (fac[i-1]*i)%MOD;
         invfac[200000] = power(fac[200000], MOD-2, MOD);
         for(int i=199999; i >= 1; i--)
            invfac[i] = (fac[i+1]*(i+1))%MOD;
         */
         long res = (fac[N+M-2]*invfac[N-1])%MOD;
         res = (res*invfac[M-1])%MOD;
         for(int c=0; c < B; c++)
         {
            long temp = (fac[A-1+M-c-1]*invfac[A-1])%MOD;
            temp = (temp*invfac[M-c-1])%MOD;
            long above = (fac[N-A-1+c]*invfac[c])%MOD;
            above = (above*invfac[N-A-1])%MOD;
            res -= (temp*above)%MOD;
            if(res < 0)
               res += MOD;
         }
         System.out.println(res);
      }
      public static long power(long x, long y, long p) 
      { 
         //0^0 = 1
         long res = 1L;      
         x = x%p;  
         while(y > 0) 
         { 
            if((y&1)==1) 
               res = (res*x)%p;
            y >>= 1;
            x = (x*x)%p;  
         } 
         return res; 
      } 
   }

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

int main() {
    int n, q;
    string s;
    vector<int> ac(100005);
    cin >> n >> q >> s;
    vector<int> l(q);
    vector<int> r(q);

    for(int i = 1; i <= q; i++) {
        cin >> l[i] >> r[i];
    }

    int ac_c = 0;
    for(int i = 1; i <= n; i++) {
        ac[i] = ac_c;
        if(i == n) {
            break;
        }
        if(s[i-1] == 'A') {
            if(s[i] == 'C') {
                //cout << "UP" << endl;
                ac[i] = ac_c++; 
            }
        }
        //cout << i << " " << ac[i] << endl;
    }

    for(int i = 1; i <= q; i++) {
        cout << ac[r[i]] - ac[l[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(void)
{
  int x,y;
  while(1){
    scanf("%d%d\n",&x,&y);
    if(x==0 && y==0){break;}
    else if(x>y){printf("%d %d\n",y,x);}
    else {printf("%d %d\n",x,y);}
  }
  return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int H, W, D, Q;
vector<int> L, R;
vector<pair<int, int>> A;
vector<vector<int>> g;
int main(){
  cin >> H >> W >> D;
  A.resize(H*W), g.resize(D, vector<int>(H*W/D+1, 0));
  REP(i, H){
    REP(j, W){
      int a;
      cin >> a;
      A[a-1] = {i, j};
    }
  }
  cin >> Q;
  L.resize(Q), R.resize(Q);
  REP(i, Q){
    cin >> L[i] >> R[i];
    L[i]--, R[i]--;
  }
  // cout << "hello" << endl;
  REP(i, D){
    int cost = 0;
    g[i][0] = 0;
    for(int j = 1; i+j*D < H*W; j++){
      //cout << "i:" << i << " j:" << j << endl;
      // if(i< 0 || i >= D){
      //   cout << "iover:" << i << endl;
      // }
      // if(j <0 || j >= H*W/D+1){
      //   cout << "jover:" << j << endl;
      // }
      int pre = (j-1)*D+i, nx = j*D+i;
      // if(nx >= H*W || nx < 0){
      //   cout << "nx:" << nx << endl;
      // }
      // if(pre >= H*W || pre < 0){
      //   cout << "pre:" << pre << endl;
      // }
      // cerr << "cost:" << endl;
      cost += abs(A[pre].first - A[nx].first) + abs(A[pre].second - A[nx].second);
      // cerr << "g[i][j]" << endl;
      g[i][j] = cost;
    }
  }
  REP(i, Q){
    cout << g[L[i]%D][R[i]/D] - g[L[i]%D][L[i]/D] << endl;
  }
  return 0;
}


Measured memory_bytes: 6912
def d_menagerie():
    N = int(input())
    S = input()

    s = S + S[:2]  # 円環状に並んでいることを考慮
    for ans in ('SS', 'SW', 'WS', 'WW'):  # Sheep, Wolf について1番と2番の種類を仮定する
        for i in range(1, N + 1):
            if (ans[-1] == 'S' and s[i] == 'o') or (ans[-1] == 'W' and s[i] == 'x'):
                # この場合，今注目している動物の両隣は同じ種類．
                # よって，今注目している動物の右隣を左隣と同じにする．
                ans += ans[-2]
            else:
                # 両隣は違う種類．右隣を左隣と逆にする．
                ans += ('S' if ans[-2] == 'W' else 'W')
        if ans[:2] == ans[N:]:
            # sの最初の2文字(仮定)と最後の2文字が一致した文字列のみ受理する．
            return ans[:N]
    return '-1'  # どの割り当て方も矛盾した

print(d_menagerie())

Measured memory_bytes: 3444