akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;



public class Main{
	




	public static void main(String[] args) throws IOException {
		
		
		FastScanner sc=new FastScanner();
		
		int n = sc.nextInt();
		int x = sc.nextInt(),t = sc.nextInt();
		int val = n/x * t;
		if(n%x != 0)
			val+=t;
		System.out.println(val);
		
		
	}
	
	
	
	
 
	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long[] readArrayLong(int n) {
        	long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
        }
		long nextLong() {
			return Long.parseLong(next());
		}
		String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
	}
}


Measured memory_bytes: 32764
#include "bits/stdc++.h"
using namespace std;
 
const int N = 200005;
 
int n, arr[N];
int par[N], sz[N];
 
inline int findRoot(int x) {
    if (par[x] == x) {
        return x;
    }
    return par[x] = findRoot(par[x]);
}
 
inline void mergeTree(int x, int y) {
    x = findRoot(x);
    y = findRoot(y);
    par[x] = y;
    sz[y] += sz[x];
}
 
int main() {
    ios :: sync_with_stdio(false);
    cin >> n;
    vector < pair < int, int > > values;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
        values.push_back(make_pair(arr[i], i));
        par[i] = 0; sz[i] = 1;
    }
    sort(values.begin(), values.end());
    reverse(values.begin(), values.end());
    long long ans = 0;
    for (auto val : values) {
        int index = val.second;
        par[index] = index;
        int rightContribution = 1;
        int leftContribution = 1;
        if ((index + 1 <= n) && (par[index + 1] != 0)) {
            rightContribution += sz[findRoot(index + 1)];
            mergeTree(index, index + 1);
        }
        if ((index - 1 >= 1) && (par[index - 1] != 0)) {
            leftContribution += sz[findRoot(index - 1)];
            mergeTree(index, index - 1);
        }
        ans += ((leftContribution * 1LL * rightContribution) * val.first);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4336
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
for i in range(2 ** 3):
    op1 = "+" if i & (2 ** 0) else "-"
    op2 = "+" if i & (2 ** 1) else "-"
    op3 = "+" if i & (2 ** 2) else "-"
    formula = "{}{}{}{}{}{}{}".format(A, op1, B, op2, C, op3, D)
    ans = eval(formula)
    if ans == 7:
        print("{}=7".format(formula))
        break


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

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

    ll n;
    cin >> n;
    ll ans = n + 1;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0)
            ans = min(ans, i + n / i);
    }
    cout << ans - 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long b[200]={0};
    string s;
    cin>>s;
    for(long i=0;i<s.size();i++)
        b[s[i]]++;
    for(long i='a';i<='z';i++)
        if(b[i]==0)
        {
            cout<<char(i);
            return 0;
        }
    cout<<"None";
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int A, B;
    cin >> A >> B;
    if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
        cout << "Possible" << "\n";
    } else {
        cout << "Impossible" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  putStrLn $ case solve a b of
    LT -> "a < b"
    EQ -> "a == b"
    GT -> "a > b"

solve :: Int -> Int -> Ordering
solve = compare



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

double rec(double p[], int n, int i, int cnt, int icnt, double **mem)
{
  if(i==n&&icnt<cnt)
    return 0;
  if(i==n&&cnt<=icnt)
	return 1;
  if(mem[i][icnt]!=-1)
    return mem[i][icnt];
  double a=p[i]*rec(p,n,i+1,cnt,icnt+1,mem);
  double b=(1-p[i])*rec(p,n,i+1,cnt,icnt,mem);
  mem[i][icnt]=a+b;
  return a+b;
}

int main(){
  int n;
  cin>>n;
  double p[n];
  for(int i=0;i<n;i++)
    cin>>p[i];
  int cnt=n/2+1;
  double **mem=new double*[n+1];
  for(int i=0;i<=n;i++)
  {
    mem[i]=new double[n+1];
    for(int j=0;j<=n;j++)
      mem[i][j]=-1;
  }
  cout<<fixed<<setprecision(10)<<rec(p,n,0,cnt,0,mem);
            
}

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

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

  string  A; cin >> A;
  int N = A.size();
  vector<vector<int>> cnt(N, vector<int>(26, 0));

  cnt[0][A[0] - 'a'] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < 26; j++) {

      cnt[i][j] = cnt[i - 1][j];

      if (A[i] - 'a' == j) {
        cnt[i][j]++;
      }
    }
  }

  ll ans = 1;
  for (int i = 0; i < N; i++) {
    int j = A[i] - 'a';
    ans += (N - i - 1) - (cnt[N - 1][j] - cnt[i][j]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 27028
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  	int N, X;
  	cin >> N >> X;
  	int L[N+1];
  	for(int i=0;i<N;i++){
  		cin >> L[i];
  	}
  	L[N] = 100000;
  	int cnt = 0;
  	int loc = 0;
  	int i=0;

  	while(loc <= X){
  		cnt++;
  		loc += L[i];
  		i++;
  	}
  	cout << cnt <<endl;
    
  	return 0;
}



Measured memory_bytes: 256
import sys
import copy
from collections import deque

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

digtmp = [(0, 1), (1, 0), (0, -1), (-1, 0)]
area = [
    (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
    (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
    (0, -2), (0, -1), (0, 1), (0, 2),
    (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
    (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)
]

def warp(a:int, b:int, cnt:int):
    ans = []
    for i, j in area:
        x, y = a+i, b+j
        if 0 <= x < H and 0 <= y < W:
            if field[x][y] == '.' and check[x][y] == -1:
                check[x][y] = cnt
                ans.append((x, y))
    return ans


def main():
    global field, check, H, W
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())

    field = []
    check = [[-1] * W for _ in range(H)] 
    for h in range(H):
        tmp = list(input()[:-1])
        field.append(tmp)
    
    
    cnt = 0
    que = deque([(Ch-1, Cw-1)])
    for i in range(H*W):
        # BFS
        magic = []
        for _ in range(H*W):
            if len(que) == 0:
                break
            a, b = que.popleft()
            magic.append((a, b))
            for dx, dy in digtmp:
                x = a + dx
                y = b + dy
                if not (0 <= x < H and 0 <= y < W):
                    continue
                if check[x][y] != -1 or field[x][y] == '#':
                    continue
                check[x][y] = cnt
                que.append((x, y))

        # magic
        quetmp = []
        cnt += 1
        for _ in range(H*W):
            a, b = magic.pop()
            tmp = warp(a, b, cnt)
            quetmp += tmp 
            if len(magic) == 0:
                break
        que = deque(quetmp)
        
        if check[Dh-1][Dw-1] != -1:
            print(check[Dh-1][Dw-1])
            return
        if len(que) == 0:
            print(check[Dh-1][Dw-1])
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 128328
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, X[1 << 18], Y[1 << 18], T[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> T[i] >> X[i] >> Y[i];
	for (int i = 1; i <= N; i++) {
		int s = abs(X[i] - X[i - 1]) + abs(Y[i] - Y[i - 1]);
		if ((s + (T[i] - T[i - 1])) % 2 == 1 || (T[i] - T[i - 1]) < s) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 4744
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef map<string,int> si;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}


int atcoder() {
    string s;
    cin >> s;
        
    if(s=="A") cout << "T" << ENT;
    if(s=="T") cout << "A" << ENT;
    if(s=="G") cout << "C" << ENT;
    if(s=="C") cout << "G" << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,i,j,count=0,sw;

  scanf("%d",&N);
  int A[N];
  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
    }
    for(i=0;i<N-1;i++){
      for(j=N-1;j>i;j--){
            if(A[j]<A[j-1]){
              sw=A[j-1];
              A[j-1]=A[j];
              A[j]=sw;

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

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



void solve(){
	llint k,a,b;
	cin >> k;
	cin >> a >> b;
	string ans="NG";
	for(int i=a;i<=b;i++){
		if(i%k==0){
			ans="OK";
			break;
		}
	}

	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define rep(i,N) for (int i = 0; i < N; i++)

template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

long long H, W;
vector<string> grid;
const long long prime = 1000000007;
long long dp[1010][1010];

int main() {
    scanf("%Ld %Ld", &H, &W);
    grid.resize(H);
    rep(i,H) cin >> grid[i];
    dp[0][0] = 1;
    rep(i,H)rep(j,W){
        if (grid[i][j] == '#'){
            dp[i][j] = 0;
        }else{
            if(i != H-1 && grid[i+1][j] == '.') {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= prime;
            }
            if (j != W-1 && grid[i][j+1] == '.'){
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= prime;
            }
        }
    }

    printf("%Ld\n", dp[H-1][W-1]);
    //printf("%Ld\n", dp[H][W]);
    return 0;
}

Measured memory_bytes: 9216
import math
import sys

n = int(input())
if n == 0:
  print(0)
  sys.exit()
  
keta = 0
under = 0
s = ""
nn = 1

if n > 0:
    while True:
      if sum([2**i for i in range(0,nn,2)])+1<= n and n <= sum([2**i for i in range(0,nn+1,2)]):
          keta = nn+1
          under = sum([2**i for i in range(0,nn,2)])
          break
      else:
          nn+=1

    for i in range(1,keta):
        remainder = (n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "0" if i%2==1 else "1"
        else:
            s += "1" if i%2==1 else "0"
    else:
        s+="1"
    print(s[::-1])

else:
    while True:
        if n <= sum([(-2)**i for i in range(1,nn,2)]) and n >= sum([(-2)**i for i in range(1,nn+1,2)]):
            keta = nn+1
            under = sum([(-2)**i for i in range(1,nn,2)])
            break
        else:
            nn+=1

    for i in range(1,keta):
        remainder = abs(n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "1" if i%2==1 else "0"
        else:
            s += "0" if i%2==1 else "1"
    else:
        s+="1"
    print(s[::-1])
    




Measured memory_bytes: 3188
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize
    }
    let mut m = 1;
    while m <= n {
        if m == n {
            println!("No");
            return;
        }
        m *= 2;
    }
    println!("Yes");
    m = 2;
    while m < n {
        println!("{} {}", 1, m);
        println!("{} {}", 1, m + 1);
        println!("{} {}", m, m + n + 1);
        println!("{} {}", m + 1, m + n);
        m += 2;
    }

    println!("{} {}", n + 1, n + 3);

    if n % 2 == 0 {
        m = n;
        let mut e = 0;
        while m > 1 {
            m /= 2;
            e += 1;
        }
        println!("{} {}", n, 2usize.pow(e));
        println!("{} {}", n * 2, n + 1 - 2usize.pow(e));
    }
}


Measured memory_bytes: 6396
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
const int N=100;
const ll mod=1544487678797;
char s[N];
vector<pair<ll,ll> > lh[19],rh[19];
int main()
{
	int n,i;
	scanf("%i",&n);
	scanf("%s",s+1);
	int mask;
	for(mask=0;mask<(1<<n);mask++)
	{
		int red=0;
		ll h=0;
		for(i=0;i<n;i++)
		{
			if((mask>>i)&1)
			{
				red++;
				h*=26;h%=mod;
				h+=s[i+1]-'a';
				if(h>=mod) h-=mod;
			}
		}
		ll b=0;
		for(i=n-1;~i;i--)
		{
			if(!((mask>>i)&1))
			{
				b*=26;b%=mod;
				b+=s[i+1]-'a';
				if(b>=mod) b-=mod;
			}
		}
		//printf("%i %lld %lld\n",red,h,b);
		lh[red].pb(mp(h,b));
	}
	for(mask=0;mask<(1<<n);mask++)
	{
		int red=0;
		ll h=0;
		for(i=0;i<n;i++)
		{
			if((mask>>i)&1)
			{
				red++;
				h*=26;h%=mod;
				h+=s[i+1+n]-'a';
				if(h>=mod) h-=mod;
			}
		}
		ll b=0;
		for(i=n-1;~i;i--)
		{
			if(!((mask>>i)&1))
			{
				b*=26;b%=mod;
				b+=s[i+1+n]-'a';
				if(b>=mod) b-=mod;
			}
		}
		//printf("%i %lld %lld\n",red,b,h);
		rh[red].pb(mp(b,h));
	}
	for(i=0;i<=n;i++) sort(lh[i].begin(),lh[i].end());
	for(i=0;i<=n;i++) sort(rh[i].begin(),rh[i].end());
	//printf(":D\n");
	int sz,tz;
	ll sol=0;
	for(sz=0;sz<=n;sz++)
	{
		int j=0;
		tz=n-sz;
		for(i=0;i<lh[sz].size();i++)
		{
			ll cnt=1;
			while(i+1<lh[sz].size() && lh[sz][i+1]==lh[sz][i]) cnt++,i++;
			while(j<rh[tz].size() && rh[tz][j]<lh[sz][i]) j++;
			while(j<rh[tz].size() && rh[tz][j]==lh[sz][i]) sol+=cnt,j++;
		}
	}
	printf("%lld\n",sol);
	return 0;
}

Measured memory_bytes: 10448
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

struct SegmentTree {
	std::vector<i64> seg;
	int sz = 1;
	
	SegmentTree(int n) {
		while(sz < n) sz <<= 1;
		seg.assign(sz * 2 - 1, 0);
	}
	
	void add(int k) {
		k += sz - 1;
		seg[k] += 1;
		
		while(k) {
			k = (k - 1) / 2;
			
			seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
		}
	}
	
	i64 get(int a, int b, int k, int l, int r) {
		if(b<=l||r<=a) return 0;
		if(a<=l&&r<=b) return seg[k];
		
		return get(a, b, 2 * k + 1, l, (l + r) / 2) + get(a, b, 2 * k + 2, (l + r) / 2, r);
	}
	
	i64 get(int a, int b) {
		return get(a, b, 0, 0, sz);
	}
};

i64 n;
std::vector<int> a;

i64 count(int t) {
	std::vector<int> b = a, s(n + 1, 0);
	for(int i = 0; i < n; i++) b[i] = -2 * (b[i] > t) + 1;
	for(int i = 0; i < n; i++) s[i + 1] = s[i] + b[i];
	std::vector<int> vec = s; sort(begin(vec), end(vec));
	vec.erase(unique(begin(vec), end(vec)), end(vec));
	
	i64 ret = 0;
	SegmentTree seg(vec.size());
	for(int i = 0; i <= n; i++) {
		int k = lower_bound(begin(vec), end(vec), s[i]) - begin(vec);
		ret += seg.get(0, k); seg.add(k);
	}
	
	return ret;
}

int solve() {
	std::vector<int> vec = a; sort(begin(vec), end(vec));
	vec.erase(unique(begin(vec), end(vec)), end(vec));
	
	int ng = 0, ok = vec.size() - 1;
	while(abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		
		if(count(vec[mid]) >= n * (n + 1) / 4 + 1) ok = mid;
		else ng = mid;
	}

	return vec[ok];
}

int main(){
	cin >> n; a.resize(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 4196
N = int(input())
s = list(input())
check_SW = True
X1 = ["S","S"]
X2 = ["S","W"]
X3 = ["W","S"]
X4 = ["W","W"]

flg1 , flg2 , flg3 , flg4 = "","","",""
def check(X):
    for i in range(1,N-1):
        if (X[i] == "S" and s[i]=="o") or (X[i] == "W" and s[i] == "x"):
            X.append(X[i-1])
        else:
            if X[i-1] == "S":
                X.append("W")
            else:
                X.append("S")
    for i in range(N):
        if (s[i] == "o" and X[i] == "S") or (s[i] == "x" and X[i] == "W") :
            if X[(i-1)%N] != X[(i+1)%N]:
                return False , X
                break
        else:
            if X[(i-1)%N] == X[(i+1)%N]:
                return False , X
                break
    return True , X

flg1 , X1 = check(X1)
flg2 , X2 = check(X2)
flg3 , X3 = check(X3)
flg4 , X4 = check(X4)

if flg1:
    print("".join(X1))
elif flg2:
    print("".join(X2))   
elif flg3:
    print("".join(X3))    
elif flg4:
    print("".join(X4))     
else:
    print(-1)

Measured memory_bytes: 7332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

ll N,a[10000],b[10000],x=0,t;

int main(){
  cin>>N; CINA(a,N);CINA(b,N);
  REP(i,N){
    t = b[i]-a[i];
    if(t>=0){ x+=t/2;}
    else{ x+=t;}
  }
  cout<<(x>=0 ?Liny:Linn);
}


Measured memory_bytes: 384
#!/usr/bin/env ruby
require 'set'

def main
    s = gets.chomp
    t = gets.chomp
    puts s == t[0..-2] ? "Yes" : "No"
end

main

# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
# until s.empty? do

Measured memory_bytes: 14508
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve() {
    int n;
    cin >> n;
    VS s(n);
    REP(i,0,n) cin >> s[i];
    int bal = 0;
    REP(i,0,n) for (char c: s[i]) bal += (c == '(' ? 1 : -1);
    if (bal != 0) {
        cout << "No" << endl;
        return;
    }
    VI needs(n, 1000000+1), b(n);
    REP(i,0,n) {
        int bal = 0;
        for (char c: s[i]) {
            bal += (c == '(' ? 1 : -1);
            chmin(needs[i], bal);
        }
        b[i] = bal;
    }

    priority_queue<PII,VP,less<PII>> l, r;
    REP(i,0,n) {
        if (b[i] >= 0) l.emplace(needs[i], b[i]);
        else r.emplace(needs[i] - b[i], -b[i]);
    }

    int h = 0;
    while (!l.empty()) {
        auto p = l.top();
        l.pop();
        if (h + p.first < 0) {
            cout << "No" << endl;
            return;
        }
        h += p.second;
    }
    h = 0;
    while (!r.empty()) {
        auto p = r.top();
        r.pop();
        if (h + p.first < 0) {
            cout << "No" << endl;
            return;
        }
        h += p.second;
    }
    cout << "Yes" << endl;
}

signed main() {
    solve();
    
    return 0;
}


Measured memory_bytes: 50288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
ll p[maxn],c[maxn];
bool vis[maxn];
std::vector<ll> V;
ll ans,n,k;
void check() {
	ll S=0;
	for(auto x:V) S+=x;
	vector<ll> tem;
	for(int i=0;i<V.size();i++) tem.push_back(V[i]);
	for(int i=0;i<V.size();i++) tem.push_back(V[i]);
	for(int i=0;i<V.size();i++) tem.push_back(V[i]);
	ll sum=0,len=50;
	if(S>0) {
		if(k>=V.size()) {
			sum+=S*(k/V.size()-1);
			len=k-(k/V.size()-1)*V.size();
		}
		else {
			sum=0;
			len=k;
		}
	}else {
		sum=0;
		len=min(k,(ll)V.size());
	}
	deque<pair<ll,ll>>dq;dq.push_back({-1,0});
	ll now=0,mx=-1e18;
	for(int i=0;i<tem.size();i++) {
		while(!dq.empty()&&i-dq.front().first>len) dq.pop_front();
		now+=tem[i];mx=max(mx,now-dq.front().second);
		while(!dq.empty()&&now<dq.back().second) dq.pop_back();
		dq.push_back({i,now});
	}
	ans=max(ans,sum+mx);
}
void dfs(int now) {
	if(vis[now]) {
		check();
		V.clear();
		return;
	}
	V.push_back(c[now]);
	vis[now]=1;
	dfs(p[now]);
}
int main() {
    cin>>n>>k;
    ans=-1e18;
    for(int i=1;i<=n;i++) cin>>p[i];
    for(int i=1;i<=n;i++) cin>>c[i],ans=max(ans,c[i]);
    for(int i=1;i<=n;i++) if(!vis[i]) dfs(i);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod2=998244353;
ll mod=1e9+7;
vector<int> seg;
vector<int> dp;
void update(int v,int tl,int tr,int pos,int val)
{
    if(tl==tr)
    seg[v]=val;
    else
    {
        int mid=(tl+tr)/2;
        if(pos<=mid)
        update(2*v,tl,mid,pos,val);
        else
        {
            update(2*v+1,mid+1,tr,pos,val);
        }
        seg[v]=max(seg[2*v],seg[2*v+1]);
        
    }
    
}
int get(int v,int tl,int tr,int l,int r)
{
    if(tl>r||tr<l)
    return 0;
    if(tl>=l&&tr<=r)
    return seg[v];
    int mid=(tl+tr)/2;
    return max(get(2*v,tl,mid,l,r),get(2*v+1,mid+1,tr,l,r));
}
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int p=3e5;
    seg.resize(4*p,0);
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        int val=get(1,1,p,max(0,a[i]-k),min(p,a[i]+k));
        update(1,1,p,a[i],val+1);
        ans=max(ans,val+1);
    }
    cout<<ans<<endl;


    
    
}

Measured memory_bytes: 9068
using System;
using System.Collections.Generic;

class A
{
	public static void Main ()
	{

		string[] s = Console.ReadLine ().Split (' ');
		int r = int.Parse (s [0]);
		int c = int.Parse (s [1]);

		int[,] spred = new int[r + 1, c + 1];
		for (int i=0; i<r; i++) {
			string[] s2 = Console.ReadLine ().Split (' ');
			for (int x=0; x<c; x++) {
				spred [i, x] = int.Parse (s2 [x]);
				spred [i, c] += int.Parse (s2 [x]);
				spred [r, x] += int.Parse (s2 [x]);
				spred [r, c] += int.Parse (s2 [x]);
			}
		}

		for (int i=0; i<=r; i++) {
			for (int x=0; x<c; x++) {
				Console.Write (spred [i, x] + " ");
			}
			Console.WriteLine (spred [i, c]);
		}

	}
}

Measured memory_bytes: 9272
#include<stdio.h>
int main(void)
{
int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
if(a == b){
	printf("a == b\n");
}
else{
	if(a > b){
		printf("a > b\n");
	}
	else{
		printf("a < b\n");
	}
}
return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
string s[200005];
bool cmp(string a,string b)
{
	return a<b; 
} 
int main()
{
	int n,i,ans;
	cin>>n;
	for(i=1;i<=n;i++)
	{
	    cin>>s[i];
	}
	sort(s+1,s+1+n,cmp);
	i=1;
	ans=1;
    while(i<n)
    {
    	if(s[i]==s[i+1]&&i<n)i++;
    	else
		{
		 ans++;
    	 i++;	
		}
    }
    cout<<ans;
}  

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

int main(){
  string s; cin >>s;
  int n = s.size();
  string ans = "";
  rep(i,n){
    if(s[i]=='0') ans += '0';
    else if(s[i]=='1') ans += '1';
    else if(s[i]=='B' && ans!="") {
      int x = ans.size();
      ans.erase(x-1,1);
    }
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3636
def main():
    h, w, n = map(int, input().split())
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    s, t = input(), input()

    u, d, l, r = 0, h - 1, 0, w - 1

    for ss, tt in reversed(tuple(zip(s, t))):
        if tt == 'U': d = min(d + 1, h - 1)
        if tt == 'D': u = max(u - 1, 0)
        if tt == 'L': r = min(r + 1, w - 1)
        if tt == 'R': l = max(l - 1, 0)

        if ss == 'U': u += 1
        if ss == 'D': d -= 1
        if ss == 'L': l += 1
        if ss == 'R': r -= 1

        if l > r or u > d:
            print('NO')
            return

    if l <= x <= r and u <= y <= d:
        print('YES')
        return
    else:
        print('NO')
        return


if __name__ == '__main__':
    main()

Measured memory_bytes: 18224
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef vector< vector< pair<int, int> > > graph;

class Node{
public:
	int apos, bpos, visit, cost;
	Node(int apos, int bpos, int visit, int cost) : apos(apos), bpos(bpos), visit(visit), cost(cost) {}
	bool operator < (const Node &nd) const { return cost > nd.cost; }
};

int main(){
	int n, m;
	static int dp[50][50][1024];
	int d[50], e[50];
	int num[1001], idx[50];
	while(cin >> n >> m, n){
		memset(num, 0, sizeof(num));
		d[0  ] = 0; e[0  ] = 0;
		idx[0] = num[0]++;
		for(int i=1;i<n-1;i++){
			cin >> d[i] >> e[i];
			idx[i] = num[e[i]]++;
		}
		d[n-1] = 0; e[n-1] = 1000;
		idx[n-1] = num[1000]++;
		graph ga(n), gb(n);
		for(int i=0;i<m;i++){
			int a, b, c; cin >> a >> b >> c;
			if(e[a-1]<=e[b-1]) ga[a-1].push_back(make_pair(b-1, c));
			if(e[a-1]>=e[b-1]) gb[b-1].push_back(make_pair(a-1, c));
		}

		memset(dp, -1, sizeof(dp));
		priority_queue<Node> qu; qu.push(Node(0, 0, 1, 0));
		dp[0][0][1] = 0;
		int res = -1;
		while(!qu.empty()){
			Node nd = qu.top(); qu.pop();
			int apos = nd.apos, bpos = nd.bpos, visit = nd.visit, cost = nd.cost;
			if(dp[apos][bpos][visit] < cost) continue;
			if(apos == n-1 && bpos == n-1){
				res = cost;
				break;
			}

			if(e[apos] >= e[bpos]){
				for(int i=0;i<gb[bpos].size();i++){
					int next = gb[bpos][i].first;
					int add  = gb[bpos][i].second;
					if(!(e[next] == e[apos] && (visit&(1<<idx[next])))) add += d[next]; 

					int nvisit = visit;
					if(e[next] == e[apos] && !(visit&(1<<idx[next]))) nvisit |= 1<<idx[next];
					if(e[next] > e[apos]) nvisit = 1<<idx[next];

					if(dp[apos][next][nvisit] == -1 || dp[apos][next][nvisit] > dp[apos][bpos][visit] + add){
						dp[apos][next][nvisit] = dp[apos][bpos][visit] + add;
						qu.push(Node(apos, next, nvisit, dp[apos][next][nvisit]));
					}
				}
			}
			if(e[apos] <= e[bpos]){
				for(int i=0;i<ga[apos].size();i++){
					int next = ga[apos][i].first;
					int add  = ga[apos][i].second;
					if(!(e[next] == e[bpos] && (visit&(1<<idx[next])))) add += d[next]; 

					int nvisit = visit;
					if(e[next] == e[bpos] && !(visit&(1<<idx[next]))) nvisit |= 1<<idx[next];
					if(e[next] > e[bpos]) nvisit = 1<<idx[next];

					if(dp[next][bpos][nvisit] == -1 || dp[next][bpos][nvisit] > dp[apos][bpos][visit] + add){
						dp[next][bpos][nvisit] = dp[apos][bpos][visit] + add;
						qu.push(Node(next, bpos, nvisit, dp[next][bpos][nvisit]));
					}
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 11000
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());

        if ((A < C && C < B) || (B < C && C < A)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

int main() {
    string s; cin >> s;
    int a_cnt=0, b_cnt=0, c_cnt=0;
    for (auto c : s) {
        if (c == 'a') a_cnt++;
        if (c == 'b') b_cnt++;
        if (c == 'c') c_cnt++;
    }
    int maxv = max(max(a_cnt,b_cnt), c_cnt);
    int minv = min(min(a_cnt,b_cnt), c_cnt);
    if (maxv-minv >1 )cout << "NO" << endl;
    else cout << "YES" << endl;

}


Measured memory_bytes: 3776
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	_, m := readInt(), readInt()
	ac := make(map[int]bool)
	wa := make(map[int]int)

	w := 0
	for i := 0; i < m; i++ {
		p, res := readInt(), readString()
		if res == "AC" {
			_, ok1 := ac[p]
			_, ok2 := wa[p]
			if !ok1 && ok2 {
				w += wa[p]
			}
			ac[p] = true
			continue
		}
		wa[p]++
	}

	fmt.Println(len(ac), w)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 6912
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int abcd;
	cin >> abcd;
	int a, b, c, d;
	d = (abcd % 10);
	c = ((abcd / 10) % 10);
	b = ((abcd / 100) % 10);
	a = ((abcd / 1000) % 10);
	if (a + b + c + d == 7) {
		cout << a << "+" << b << "+" << c << "+" << d << "=7";
		return 0;
	}
	else if (a + b + c - d == 7) {
		cout << a << "+" << b << "+" << c << "-" << d << "=7";
		return 0;
	}
	else if (a + b - c + d == 7) {
		cout << a << "+" << b << "-" << c << "+" << d << "=7";
		return 0;
	}
	else if (a + b - c - d == 7) {
		cout << a << "+" << b << "-" << c << "-" << d << "=7";
		return 0;
	}
	else if (a - b + c + d == 7) {
		cout << a << "-" << b << "+" << c << "+" << d << "=7";
		return 0;
	}
	else if (a - b + c - d == 7) {
		cout << a << "-" << b << "+" << c << "-" << d << "=7";
		return 0;
	}
	else if (a - b - c + d == 7) {
		cout << a << "-" << b << "-" << c << "+" << d << "=7";
		return 0;
	}
	else if (a - b - c - d == 7) {
		cout << a << "-" << b << "-" << c << "-" << d << "=7";
		return 0;
	}
}

Measured memory_bytes: 256
N = int(input())
a_ls = [int(i) for i in input().split()]
b_ls = [int(i) for i in input().split()]

cnt = 0
for ind in range(N):
    n_kill = min(a_ls[ind], b_ls[ind])
    cnt += n_kill
    if n_kill < b_ls[ind]:
        if a_ls[ind + 1] <= b_ls[ind] - n_kill:
            cnt += a_ls[ind + 1]
            a_ls[ind + 1] = 0
        else:
            a_ls[ind + 1] -= b_ls[ind] - n_kill
            cnt += b_ls[ind] - n_kill

print(cnt)

Measured memory_bytes: 19156
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll k,x,y; cin>>k>>x>>y;
    ll xm=1,ym=1,xym=0;
    if(x<0){
        xm=-1; x=-x;
    }
    if(y<0){
        ym=-1; y=-y;
    }
    if(y<x){
        swap(x,y); xym=1;
    }
    ll dis=x+y,ans,xcur=0,ycur=0;
    vector<pair<ll,ll>> path;
    if(k%2){
        if(dis<k && dis%2){
            ans=3;
            path.assign(ans,mk(0,k));
            path[0]=mk(k-(dis+k)/2,(dis+k)/2);
            path[1]=mk(-k+(dis+k)/2,(dis+k)/2);
            path[2]=mk(0,-k);
        }
        else if(dis<k){
            ans=2;
            path.assign(ans,mk(0,k));
            path[0]=mk((ans*k-dis)/2,k-(ans*k-dis)/2);
            path[1]=mk(-(ans*k-dis)/2,k-(ans*k-dis)/2);
        }
        else{
            ans=(dis+k-1)/k;
            if(dis%2!=ans%2) ans++;
            path.assign(ans,mk(0,k));
            if(ans>1){
                path[0]=mk((ans*k-dis)/2,k-(ans*k-dis)/2);
                path[1]=mk(-(ans*k-dis)/2,k-(ans*k-dis)/2);
            }
        }
    }
    else{
        if(dis%2){
            cout<<-1<<endl;
            return 0;
        }
        if(dis<k){
            ans=2;
            path.assign(ans,mk(0,k));
            path[0]=mk((ans*k-dis)/2,k-(ans*k-dis)/2);
            path[1]=mk(-(ans*k-dis)/2,k-(ans*k-dis)/2);
        }
        else{
            ans=(dis+k-1)/k;
            path.assign(ans,mk(0,k));
            if(ans>1){
                path[0]=mk((ans*k-dis)/2,k-(ans*k-dis)/2);
                path[1]=mk(-(ans*k-dis)/2,k-(ans*k-dis)/2);
            }
        }
    }
    cout<<ans<<endl;
    ll cnt=x;
    //rep(i,ans) cout<<path[i].first<<" "<<path[i].second<<endl;
    rep(i,ans){
        if(path[i].first>=0 && path[i].second>=0){
            ll d=min(cnt,path[i].second);
            path[i].first+=d;
            path[i].second-=d;
            cnt-=d;
        }
        xcur+=path[i].first;
        ycur+=path[i].second;
        if(xym) cout<<xm*ycur<<" "<<ym*xcur<<endl;
        else cout<<xm*xcur<<" "<<ym*ycur<<endl;
    }
}

Measured memory_bytes: 6284
N = gets.to_i
ds = gets.split.map(&:to_i)
ans = 0
(0...(N - 1)).each do |i|
  d = ds[i]
  ((i + 1)...N).each do |j|
    d2 = ds[j]
    ans += d * d2
  end
end
puts ans


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define MAX 16

using namespace std;
double d[MAX];
double km[MAX],kazu[1<<MAX],num[MAX],kazu2[1<<MAX];
double dp[1<<MAX][MAX];
int n;
vector<int> prev[(1<<MAX)][MAX];  //同じく経路復元用　最短経路の直前の頂点を示す
//vector<int> path[(1<<n)][MAX];  //経路復元用
void solve();

int main(){
  cin >> n;
  for(int i=0;i<n;i++)
    {
      cin >> num[i] >> d[i] >> kazu2[i];
      kazu2[i]*=20;
    }

  for(int i=1;i<(1<<n);i++)
    {
      int sum=0,count=0;
      for(int j=1;j<(1<<n);j=(j<<1),count++){
	if((i&j)!=0){
	  sum += kazu2[count];
	}
      }
      kazu[i]=sum;
    }

  solve();


}

void solve()
{

  rep(i,(1<<n))rep(j,n)dp[i][j]=INF;

  rep(i,n)
    {
    dp[1<<i][i]=0.0;
    prev[1<<i][i].push_back(i);
    }
  double cost;

  for(int S=1;S<(1<<n);S++)
    {
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      if(!(S & (1<<j)))
		{
		  cost = ((70.0+kazu[S])/2000.0)*abs(d[i] - d[j]);
		  //cout << "cost = " << cost << endl;
		  if(dp[S|(1<<j)][j] > dp[S][i] + cost)
		    {
		      dp[S|(1<<j)][j]=dp[S][i]+cost;
		      prev[S|(1<<j)][j]=prev[S][i];
		      prev[S|(1<<j)][j].push_back(j);
		    }
		}
	    }
	}
    }
    
  double mini = INF;
  vector<int> path;

  for(int i=0;i<n;i++){
    if(mini > dp[(1<<n)-1][i]){
      mini = dp[(1<<n)-1][i];
      path = prev[(1<<n)-1][i];
    }
  }

  for(int i=0;i<path.size();i++){
    cout << num[path[i]];
    if(i != path.size()-1)cout << " ";
  }
  cout << endl;



}

Measured memory_bytes: 0
uses math ;
var n,t1,t2,i,ans,k:longint ;
       a:array[-1000000..1000000] of longint ;
begin
   readln(n) ;
	 for i:=1 to n do 
	 begin 
	   read(k) ;
		 inc(a[k]) ;
		 inc(a[k-1]) ;
		 inc(a[k+1]) ;
		 t2:=max(t2,k+1) ;
		 t1:=min(t1,k-1) ;
	 end;
	 for i:=t1 to t2 do 
	 if a[i]>ans then ans:=a[i] ;
	 writeln(ans) ;
end.

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

int N;

int main(void){
    cin >> N;
    lli res = 0;
    int n = 10000000;
    vector<lli> table(n+1, 0);
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j+=i){
            table[j]++;
        }
    }
    for(int i = 1; i <= N; i++) res+=i*table[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 81376
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	vector<pair<ll,int>>vec(4);
	rep(i, 0, 4) {
		ll a;cin >> a;
		vec[i] = { a,i };
	}
	ll N; cin >> N;
	N *= 4;

	ll ans = 0;
	while (N > 0) {
		int j = 0;
		ll cnt = (ll)1e18;
		rep(i, 0, 4) {
			ll x = N / pow(2, i);
			if (x == 0)continue;
			if (chmin(cnt, x * vec[i].first)) {
				j = i;
			}
		}
		ll a = N / (int)pow(2, j);
		N -= pow(2, j) * a;
		ans += cnt;
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    int max = 1;
    int maxcnt = 0;
    for(int i = 1; i <= N; ++i) {
        int cnt = -1;
        int m = i;
        while(m > 0) {
            cnt++;
            m /= 2;
        }
        if(maxcnt < cnt) {
            maxcnt = cnt;
            max = i;
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int mod = 1e9+7;

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

    ll dif = abs(B-A);

    bool check = false;
        
    for(int i=0; i<N; i++){
        ll smallC = C*i;
        ll bigC = C*(N-1-i);
        ll smallD = D*i;
        ll bigD = D*(N-1-i);
        if(smallC - bigD <= dif && dif <= smallD - bigC){
            check = true;
        }
    }

    if(check) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;

}

Measured memory_bytes: 256
N, M = map(int, raw_input().split())

edge = []
for i in xrange(M):
  edge.append(map(lambda x: int(x)-1, raw_input().split(' ')))

ans = 0
for ex in xrange(M):
  n = []
  for i in xrange(N):
    n.append({})
  for i in xrange(M):
    if i == ex: continue
    a, b = edge[i]
    n[a][b] = n[b][a] = 1

  cl = set()
  op = set([0])
  while len(op) > 0:
    a = op.pop()
    cl.add(a)
    for to in n[a]:
      if to not in cl:
        op.add(to)

  if len(cl) < N:
    ans += 1

print ans

Measured memory_bytes: 2696
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BIMissYou solver = new BIMissYou();
        solver.solve(1, in, out);
        out.close();
    }

    static class BIMissYou {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            StringBuilder buff = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                buff.append("x");
            }
            out.println(buff);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            byte b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

    }
}



Measured memory_bytes: 21460