akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define lld long long

using namespace std;

priority_queue<lld, vector <lld>, greater <lld> > heap_min;
priority_queue<lld, vector <lld>, less    <lld> > heap_max;
int q;
int l_min, l_max;
lld t_min, t_max;
lld a_sum, b_sum;
lld s_min, s_max;
lld result, xmin;

void setvaA(lld x)
{
    heap_max.push(x);
    s_max += x;
}

void setvaI(lld x)
{
    heap_min.push(x);
    s_min += x;
}

void popvaA(lld x)
{
    heap_max.pop();
    s_max -= x;
}

void popvaI(lld x)
{
    heap_min.pop();
    s_min -= x;
}

void prepare()
{
    l_min = heap_min.size();
    l_max = heap_max.size();
}

void update(lld x, lld y)
{
    b_sum += y;
    prepare();
    if      (l_min == 0 && l_max == 0) setvaA(x);
    else if (l_min == 0 && l_max != 0) setvaI(x);
    else
    {
        t_min = heap_min.top();
        t_max = heap_max.top();
        if      (x >  t_max)               setvaI(x);
        else if (x <  t_min)               setvaA(x);
        else if (x == t_min && x == t_max) setvaA(x);
    }
}

void impartial()
{
    t_min = heap_min.top();
    t_max = heap_max.top();
    if (t_max > t_min)
    {
        popvaA(t_max);
        popvaI(t_min);
        setvaA(t_min);
        setvaI(t_max);
    }
}

void equitable()
{
    while (heap_max.size() > heap_min.size())
    {
        t_max = heap_max.top();
        popvaA(t_max);
        setvaI(t_max);
    }
    while (heap_max.size() < heap_min.size())
    {
        t_min = heap_min.top();
        popvaI(t_min);
        setvaA(t_min);
    }
}

void ketqua()
{
    if (heap_max.size() >= 1)
    {
        lld temp = heap_max.top();
        if (l_min == l_max)
            temp = b_sum + (s_min - s_max);
        else if (l_max = l_min + 1)
            temp = b_sum + (s_min - s_max + temp);

        result = temp;
        xmin   = heap_max.top();
    }
}

void solve()
{
    cin >> q;
    for (int i = 1; i <= q; i++)
    {
        int query;
        cin >> query;
        if (query == 1)
        {
            lld a, b;
            cin >> a >> b;
            update(a, b);
            prepare();
            if (l_min + l_max == 2)     impartial();
            else if (l_min + l_max > 2) equitable();
        }
        else
        {
            prepare();
            ketqua();
            cout << xmin << ' ' << result << '\n';
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("127F.inp", "r", stdin);
    //freopen("127F.out", "w", stdout);
        solve();
    return 0;
}


Measured memory_bytes: 3828
# encoding: utf-8                                                            

while (n = gets.to_i) > 0 do
  idx = []
  m = []  
  n.times { m.push gets.split.map(&:to_i); idx.push [0] * n}
  m.length.times { |i|
    idx[i][m[i].enum_for(:each_with_index).min[1]] += 1;
    idx[m.transpose[i].enum_for(:each_with_index).max[1]][i] += 2
  }
  k = 0
  n.times { |i| n.times { |j| k = m[i][j] if idx[i][j] == 3}}
  p k

end

Measured memory_bytes: 6120
def main():
    h, w = list(map(int, input().split()))
    canvas = []
    for i in range(h):
        canvas.append(list(input()))
    can_draw = True
    for i in range(h):
        for j in range(w):
            if canvas[i][j] == '.':
                continue
            s = []
            # 上下
            if i != 0:
                s.append(canvas[i - 1][j])
            if i != h - 1:
                s.append(canvas[i + 1][j])
            # 左右
            if j != 0:
                s.append(canvas[i][j - 1])
            if j != w - 1:
                s.append(canvas[i][j + 1])
            if s.count('#') == 0:
                can_draw = False
    print('Yes') if can_draw else print('No')



if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
const int maxn = 1e5 + 5;
using namespace std;
int a[maxn], n;
bool cmp(const int &x, const int &y){
	return x > y;
}
int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; i++){
		if (i + 1 > a[i + 1]){
			int ans = 0, j = i;
			while (a[j + 1] == i) ++j;
			ans = ((a[i] - i) & 1) | ((j - i) & 1); 
			if (ans) puts("First");
			else puts("Second");
			return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    sc.nextLine();
    String[] c = new String[h];

    for (int i = 0; i < h; ++i) {
      c[i] = sc.next();
    }

    for (int i = 0; i < h; ++i) {
      System.out.print(c[i] + "\n" + c[i] + "\n");
    }
  }
}


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

int main() {
    long long x, y;
    cin >> x >> y;
    int count = 1;
    for(int i = 0; ; i++){
        x = x * 2;
        if(x <= y){
            count++;
        } else {
            break;
        }
    }
    cout << count << endl;
}

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

int main(){
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    } 
    else{
        cout << 0 << endl;
    }
    return 0; 
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=2e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
int n,m,ans,f[N],sz[N];
int find(int x){
	return f[x]==x?x:(f[x]=find(f[x]));
}
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	n=read(),m=read();
	for(int i=1;i<=n;i++) f[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++){
		int x=find(read()),y=find(read());
		if(x!=y){
			f[x]=y;
			sz[y]+=sz[x];
		}
	}
	for(int i=1;i<=n;i++) ans=max(ans,sz[i]);
	cout<<ans<<endl; 
	return 0;
}


Measured memory_bytes: 5192
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

C_S = Counter(S)
C_T = Counter(T)
C_S.subtract(C_T)
print(max(0, C_S.most_common(1)[0][1]))


Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 18 20:38:47 2018
ABC106C
@author: maezawa
"""

s = input()
k = int(input())

if s[0]=='1':
    ans = 1
    cnt = 0
    for c in s:
        if c == '1':
            cnt += 1
        else:
            ans = c
            break
    if k <= cnt:
        print('1')
    else:
        print(ans)
else:
    print(s[0])

Measured memory_bytes: 3060
n=int(input())
k=int((n*2)**0.5)
if (k*(k+1))//2==n:
  print('Yes')
  print(k+1)
else:
  print('No')
  exit()
s=[[] for _ in range(k+1)]
t=1
for i in range(1,k+1):
  for j in range(i):
    s[i].append(t)
    s[j].append(t)
    t+=1
for i in s:
  print(len(i),*i)


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

using namespace std;

int main() {
  int N;
  cin >> N;
  int answer = 0;
  for (int i = 1; i <= N; i++) {
    int A;
    cin >> A;
    if (i % 2 == 1 && A % 2 == 1) answer++;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
#CODE FESTIVAL 2016 qual B C
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

w,h = LI()
p = [I() for _ in range(w)]
q = [I() for _ in range(h)]
hq = []
for i in p:
    heappush(hq,(i,0))
for i in q:
    heappush(hq,(i,1))
ans = 0
w += 1
h += 1
while hq:
    v,flg = heappop(hq)
    if flg:
        ans += v*w
        h -= 1
    else:
        ans += v*h
        w -= 1
print(ans)

Measured memory_bytes: 72412
import collections

n = int(input())
s = [input() for i in range(n)]

c_1 = collections.Counter(s[0])
for i in range(1,len(s)):
  tmp = {}
  c_2 = collections.Counter(s[i])
  for k in c_1:
    tmp[k] = min(c_1[k],c_2[k])
  c_1 = tmp
result = ""
for i in c_1:
  for j in range(c_1[i]):
    result += i
print("".join(sorted(result)))

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

int main(){
  
  string a,b;
  int c = 0;
  cin >> a >> b;

  for(int i=0;i<3;i++){
  if( a.at(i) == b.at(i) ){
    
    c++;
    
   }
  }
  
   cout << c << endl;
 
}
  


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int a,b,k;cin>>a>>b>>k;
    int cnt=0;

    for (int i=min(a,b);i>0;i--) {
        if(a%i==0&&b%i==0){
            cnt++;
        }
        if(cnt==k){
            cout<<i<<endl;
            break;
        }

    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long ll;

template <class T>
using ordered_set=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> v(n,0);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&v[i]);
        v[i]-=k;
    }
    ll res=0;
    ll sum=0;
    map<ll,int> m;
    ordered_set<pair<ll,int>> s;
    for(int i=0;i<n;i++)
    {
        s.insert({sum,++m[sum]});
        sum+=v[i];
        res+=s.order_of_key({sum,m[sum]+1});
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 25984
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>

struct T
    {
        bool b = false;
        int w = 0;
    }t;

int main() {
    

    int n, m;
    int p;
    int correct = 0, penalty = 0, temp = 0;
    std::string s;
    std::cin >> n >> m;
    std::vector<T> a (n+1);
    for(int i = 0; i < m; i++) {
        std::cin >> p >> s;
        if(a[p].b == false) {
            if(s == "AC") {
                correct++;
                a[p].b = true;
            }
            else {
                a[p].w++;
            }
        }
    }

    for(int i = 1; i < a.size(); i++) {
        if(a[i].b) {
            penalty += a[i].w;
        }
    }
    std::cout << correct << " " << penalty;
    // output: #correct #penalties

    return 0;
}

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


int main(){
  int N,D;
  cin>>N>>D;
  
  vector<vector<int>>X(N,vector<int>(D));

  int ans=0;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
cin>>X[i][j];
    }
  }
  
  for(int i=0;i<N;i++){
    for(int k=i+1;k<N;k++){
      int sum=0;
      
for(int j=0;j<D;j++){
  sum+=pow((X[i][j]-X[k][j]),2);
  
} 
      
      for(int m=0;m<=130;m++){
      if(sum==pow(m,2)){
ans++;
        break;
     
      }
    }
      
    }
  
  }
  
  cout<<ans<<endl;
}
          
        
      
  
    
    
    
    
    
  

    
    
    
    
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
 
using namespace std;
#define ll long long
 
int main()
{
	// Value
	ll N;
	ll x;
	string result = "No";
	vector<ll> resultn;
 
	// Input
	cin>>N>>x;
	ll size = 2*N-1;
 
	// Cal
	vector<ll> nums;
	for(ll i=0;i<size;++i){
		resultn.push_back(-1);
		nums.push_back(i+1);
	}
	[&](){
		//reject
		if(x==1 || x==size) return;

		result = "Yes";
		if(x!=2){
			//insert centor num (make beam)
			ll centor = size/2;
			resultn[centor] = x;
			resultn[centor+1] = x+1;
			resultn[centor-1] = x-1;
			if(N==2) return;
			resultn[centor+2] = x-2;

			//umeru
			ll nums_seek = 0;
			for(ll i=0;i<size;++i){
				//skip centor
				if(i==centor-1){
					if(N==3) return;
					i+=4;
				}

				//skip x
				if(nums_seek+1 == x-2){
					nums_seek+=4;
				}

				//cout<<nums_seek+1<<endl;
				
				resultn[i] = nums[nums_seek];
				nums_seek++;
			}
		}else{
			//insert centor num (make beam)
			ll centor = size/2;
			resultn[centor] = x;
			resultn[centor-1] = x-1;
			resultn[centor+1] = x+1;
			if(N==2) return;
			resultn[centor-2] = x+2;

			//umeru
			ll nums_seek = 0;
			for(ll i=0;i<size;++i){
				//skip centor
				if(i==centor-2){
					i+=4;
				}

				//skip x
				if(nums_seek+1 == x-1){
					nums_seek+=4;
				}

				//cout<<nums_seek+1<<endl;
				
				resultn[i] = nums[nums_seek];
				nums_seek++;
			}
		}
	}();
 
	// Output
	cout << result << endl;
	if(result == "Yes"){
		for(ll i=0;i<size;++i){
			cout << resultn[i] << endl;
		}
	}
 
	// Fin
	return 0;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int result[110000][3],A[110000],B[110000],C[110000];
  for(int i=0; i<3; i++)
    result[0][i]=0;
  A[0]=B[0]=C[0]=0;
  for(int i=1; i<=n; i++)
    cin >> A[i] >> B[i] >> C[i];
  int s=0,b=1,h=2;
  for(int i=1; i<=n; i++){
  	result[i][s]=A[i]+max(result[i-1][b],result[i-1][h]);
    result[i][b]=B[i]+max(result[i-1][s],result[i-1][h]);
    result[i][h]=C[i]+max(result[i-1][s],result[i-1][b]);
  }
  cout << max(max(result[n][s],result[n][b]),result[n][h]);
}	

Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 30000;
typedef long long ll;
int main()
{
  int n,i,j,k,cc,bb=0,res=0;
  int p[3]={3,5,7};
  ll m=10;
  ll c[4][N_MAX],b[4][N_MAX];
  bool f;
  cin >> n;
  if(n<357){
    cout << "0" << endl;
    return 0;
  }
  b[0][bb]=3; b[1][bb]=1; b[2][bb]=0; b[3][bb]=0; bb++;
  b[0][bb]=5; b[1][bb]=0; b[2][bb]=1; b[3][bb]=0; bb++;
  b[0][bb]=7; b[1][bb]=0; b[2][bb]=0; b[3][bb]=1; bb++;
  while(true){
    f=0;
    cc=0;
    for(j=0;j<3;j++){
      for(i=0;i<bb;i++){
        for(k=0;k<4;k++)
          c[k][cc]=b[k][i];
        c[0][cc]+=m*p[j];
        if(c[0][cc]>n){
          f=1;
          break;
        }
        c[j+1][cc]++;
        if(c[1][cc]>0&&c[2][cc]>0&&c[3][cc]>0)
          res++;
        cc++;
      }
      if(f==1)
        break;
    }
    if(f==1)
      break;
    for(k=0;k<4;k++)
      copy(c[k],c[k]+cc,b[k]);
    bb=cc;
    m*=10;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4268
(defun func(x)
  (or (not (car x)) (and (car x) (cdr x) (char= (car x) (cadr x)) (func (cddr x)))))

(let ((x (concatenate 'list (sort (read-line) #'char<))))
  (princ (if (func x)
		   "Yes"
		   "No")))


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

const int MAXN = 1e5 + 5;

int N, M;
unordered_set <int> adj[MAXN];
int deg[MAXN];
bool bio[MAXN];
int dad[MAXN];

void no() {
	puts("No");
	exit(0);
}

void yes() {
	puts("Yes");
	exit(0);
}

void go(int x) {
	bio[x] = true;
	for (auto it : adj[x])
		if (!bio[it])
			go(it);
}

void check(vector <int> c) {
	memset(bio, false, sizeof bio);
	for (int i = 0; i < c.size(); i++) {
		int nxt = c[(i + 1) % c.size()];
		adj[c[i]].erase(nxt);
		adj[nxt].erase(c[i]);
	}
	
	for (int i = 1; i <= N; i++)
		if (adj[i].size() > 2)
			yes();
	
	int cnt = 0;
	for (int i = 1; i <= N; i++)
		if (!bio[i] && !adj[i].empty()) {
			go(i);
			cnt++;
		}
	
	if (cnt > 1)
		yes();
	else	
		no();
}

void dfs(int x, int p) {
	bio[x] = true;
	dad[x] = p;
	for (auto it : adj[x])
		if (!bio[it])
			dfs(it, x);
		else if (it != p) {
			vector <int> cyc;
			while (1) {
				cyc.push_back(x);
				if (x == it)
					break;
				x = dad[x];
			}
			check(cyc);
		}
}

int main() {
	scanf("%d%d", &N, &M);
	while (M--) {
		int a, b;
		scanf("%d%d", &a, &b);
		adj[a].insert(b);
		adj[b].insert(a);
	}
	
	if (N == 1)
		no();
	
	for (int i = 1; i <= N; i++) {
		deg[i] = adj[i].size();
		if (deg[i] % 2)
			no();
	}
	
	sort(deg + 1, deg + N + 1, greater <int> ());

	if (deg[1] == 2)
		no();
	if (deg[1] > 4)
		yes();
	if (deg[3] > 2)
		yes();
			
	dfs(1, 0);
	
	return 0;
}

Measured memory_bytes: 27392
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val h = LongArray(n){long()}
    var isOk = true
    var flag = false
    for (i in 0 until n-1) {
        if (h[i] > h[i + 1]) {
            if (h[i] - 1 != h[i + 1] || flag) {
                isOk = false
                break
            }
            flag = true
        }
        if (h[i] < h[i + 1]) flag = false
    }
    println(if (isOk) "Yes" else "No")
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 31524
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;
string hds;
int hdi;
int hdfs(){
	vector<int> vt;
	//	cout<<i<<" : "<<hdi<<endl;
	int ret=0;
	if(isdigit(hds[hdi])){
		int a=0;
		while(isdigit(hds[hdi]))	a=10*a+(hds[hdi++]-'0');
		vt.push_back(a/2+1);
	}
	else	{
		while(hds[hdi]=='['){
			hdi++;
			vt.push_back(hdfs());
			hdi++;
		}
	}
	sort(vt.begin(),vt.end());
	return ret=accumulate(vt.begin(),vt.begin()+vt.size()/2+1,0);
}

int main(){
	int n;
	cin>>n;
	REP(i,0,n)	{
		hdi=0;
		cin>>hds;
		p(hdfs());
	}
	return 0;
}

Measured memory_bytes: 3252
/**
*    author:  yuya1234
*    created: 10.07.2020 13:12:10
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

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

  int x[m];
  REP(i,m)cin>>x[i];

  sort(x,x+m);

  int xx[m-1];
  REP(i,m-1)xx[i]=x[i+1]-x[i];

  sort(xx,xx+m-1,greater<int>());

  ll ans=0;
  if(n<m)
  {
    FOR(i,n-1,m-2)
    {
      ans+=xx[i];
    }
  }
  
  cout<<ans<<endl;

  return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	for(int i = 0; i < a.length(); i++) {
		cout << a[i] << b[i];
	}
	
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
 int n;cin>>n;
 vector<int>arr(n);
 for(int i=0;i<n;i++)
 cin>>arr[i];
 
 int maxi=arr[0];
 int ans=0;
 for(int i=1;i<n;i++)
 {
     if(arr[i]<=maxi)
     ans+=maxi-arr[i];
     maxi=max(maxi,arr[i]);
 }
  cout<<ans<<endl;
}
int32_t main()
{
    rapido;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    solve();
}


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

int gcd(int a, int b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    else return gcd(b, a%b);
}

int main(){
    int N, K;  cin >> N >> K;
    vector<int> A(N);
    int M = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        M = max(M, A[i]);
    }
    int g = A[0];
    for(int i=1; i<N; i++) g = gcd(g, A[i]);

    if(K%g==0 && K<=M){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


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

using namespace std; 

int main () {
		string s; cin >> s;
		if (s == "Sunny") { cout << "Cloudy"; };
		if (s == "Cloudy") { cout << "Rainy"; };
		if (s == "Rainy") { cout << "Sunny"; };
}

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

int main() {
    int xs, ys, xt, yt, N;
    cin >> xs >> ys >> xt >> yt >> N;
    vector<ll> x(N + 2), y(N + 2), r(N + 2, 0);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> r[i];
    }
    x[N] = xs;
    y[N] = ys;
    x[N + 1] = xt;
    y[N + 1] = yt;

    vector<vector<double>> graph(N + 2, vector<double>(N + 2, 0));
    for (int i = 0; i < N + 2; i++) {
        for (int j = 0; j < N + 2; j++) {
            ll dx = x[i] - x[j];
            ll dy = y[i] - y[j];
            double dd = dx * dx + dy * dy;
            if (dd <= (r[i] + r[j]) * (r[i] + r[j])) {
                graph[i][j] = 0;
                graph[j][i] = 0;
            } else {
                graph[i][j] = sqrt(dd) - r[i] - r[j];
                graph[j][i] = graph[i][j];
            }
        }
    }

    vector<double> dist(N + 2, 1e10);
    dist[N] = 0;
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> que;
    que.push({0, N});
    while (!que.empty()) {
        double d = que.top().first;
        int u = que.top().second;
        que.pop();
        if (d > dist[u]) {
            continue;
        }
        for (int v = 0; v < N + 2; v++) {
            if (v == u) {
                continue;
            }
            if (dist[v] > dist[u] + graph[u][v]) {
                dist[v] = dist[u] + graph[u][v];
                que.push({dist[v], v});
            }
        }
    }

    cout << setprecision(10) << dist[N + 1] << endl;
}


Measured memory_bytes: 13940
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

pair<int, int> p1[200001], p2[200001];

int main() {
    int n;
    cin >> n;
    vector<int> a;
    long long ans = 0;
    int l = 0, r = 0;
    int ll = 0, rr = n - 2;
    for (int i = 0; i < n; i++) {
        cin >> l;
        a.push_back(l);
    }
    sort(a.begin(), a.end());
    l = a[n - 1];
    r = a[n - 1];
    while (rr - ll >= 0) {
        int mx = 0;
        mx = max(mx, abs(l - a[ll]));
        mx = max(mx, abs(l - a[rr]));
        mx = max(mx, abs(r - a[ll]));
        mx = max(mx, abs(r - a[rr]));
        if (mx == abs(l - a[ll])) {
            l = a[ll];
            ll++;
        } else if (mx == abs(l - a[rr])) {
            l = a[rr];
            rr--;
        } else if (mx == abs(r - a[ll])) {
            r = a[ll];
            ll++;
        } else if (mx == abs(r - a[rr])) {
            r = a[rr];
            rr--;
        }
        ans += mx;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1524
n, W = list(map(int, input().split()))
data = []
for _ in range(n):
    w, v = list(map(int, input().split()))
    data.append((w, v))

dp = [[0] * (W+1) for i in range(n+1)]

for i in range(1, n+1):
    w, v = data[i-1]
    for j in range(W+1):                
        if j - w >= 0:
            dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[-1][W])


Measured memory_bytes: 119916
fn main() {
    let v: Vec<char> = {
        let s = read::<String>();
        s.chars().into_iter().collect()
    };
    let x = ((v[0] as u8) - b'0') * 10 + (v[1] as u8) - b'0';
    let y = ((v[2] as u8) - b'0') * 10 + (v[3] as u8) - b'0';
    let yymm = 1 <= y && y <= 12;
    let mmyy = 1 <= x && x <= 12;
    let ret = if yymm && mmyy {
        "AMBIGUOUS"
    } else if yymm && !mmyy {
        "YYMM"
    } else if !yymm && mmyy {
        "MMYY"
    } else {
        "NA"
    };
    println!("{}", ret);
}

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,k;
        cin>>n>>k;
        ld res=0;
        rep(i,n){
            ll x=i+1;
            ll count=0;
            while(x<=k-1){
                count++;
                x*=2;
            }
            ld y=1;
            rep(j,count){
                y/=2.0;
            }
            res+=y;
        }
        ld ans=res/n;
        cout<<fixed<<setprecision(12)<<ans<<endl;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

typedef pair<int,int> P;

enum Type{
	Query,
	Event,
};

struct Info{
	Info(int arg_time,int arg_value_1,int arg_value_2,Type arg_type,int arg_query_id){
		time = arg_time;
		value_1 = arg_value_1;
		value_2 = arg_value_2;
		type = arg_type;
		query_id = arg_query_id;
	}
	bool operator<(const struct Info &arg) const{
		if(time != arg.time){
			return time > arg.time;
		}else{
			return query_id > arg.query_id;
		}
	}

	int time,value_1,value_2,query_id;
	Type type;
};

bool ans[100000];

int main(){

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	priority_queue<Info> Q;

	int day,from,to;
	for(int loop = 0; loop < M; loop++){
		scanf("%d %d %d",&day,&from,&to);
		Q.push(Info(day+1,from,to,Event,-1));
	}

	for(int i = 0; i < num_query; i++){
		scanf("%d %d %d",&day,&from,&to);
		Q.push(Info(day,from,to,Query,i));
	}

	set<P> SET; //区間(left-right)
	set<P>::iterator it_1,it_2,work;
	for(int i = 1; i <= N; i++)SET.insert(make_pair(i,i));
	SET.insert(make_pair(BIG_NUM,BIG_NUM));

	int new_left,new_right;
	P tmp;

	while(!Q.empty()){

		if(Q.top().type == Event){

			//printf("time:%d 工事\n",Q.top().time);

			it_1 = SET.lower_bound(make_pair(Q.top().value_1,-1));
			it_2 = SET.lower_bound(make_pair(Q.top().value_2,-1));

			tmp = *it_1;
			if(tmp.first == Q.top().value_1){ //value_1はこのグループ
				new_left = tmp.first;
			}else{ //value_1は1つ前のグループ
				it_1--;
				tmp = *it_1;
				new_left = tmp.first;
			}

			tmp = *it_2;
			if(tmp.first == Q.top().value_2){//value_2は1つ前のグループ
				new_right = tmp.second;
			}else{
				it_2--;
				tmp = *it_2;
				new_right = tmp.second;
			}

			it_2++;
			SET.erase(it_1,it_2);

			//printf("new_left:%d new_right:%d\n",new_left,new_right);
			SET.insert(make_pair(new_left,new_right));

			}else{

			if(Q.top().value_2 <= Q.top().value_1){
				ans[Q.top().query_id] = true;
				Q.pop();
				continue;
			}

			it_1 = SET.lower_bound(make_pair(Q.top().value_1,-1));
			it_2 = SET.lower_bound(make_pair(Q.top().value_2,-1));

			tmp = *it_1;
			//printf("tmp:left:%d right:%d\n",tmp.first,tmp.second);
			if(tmp.first == Q.top().value_1){ //value_1はこのグループ
				//Do nothing
			}else{ //value_1は1つ前のグループ
				it_1--;
			}

			tmp = *it_2;
			//printf("tmp:left:%d right:%d\n",tmp.first,tmp.second);
			if(tmp.first == Q.top().value_2){//value_2はこのグループ
				//Do nothing
			}else{
				it_2--;
			}

			if(it_1 == it_2){
				ans[Q.top().query_id] = true;
			}else{
				ans[Q.top().query_id] = false;
			}
		}

		Q.pop();
	}

	for(int i = 0; i < num_query; i++){
		if(ans[i]){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}

	return 0;
}



Measured memory_bytes: 11444
def main():
    b, w = map(int, input().split())
    image = [list(input()) for _ in range(b)]
    image.insert(0, ["#"]*w)
    image.append(["#"]*w)
    for im in image:
        im.insert(0, "#")
        im.append("#")

    for im in image:
        print(*im, sep="")


if __name__ == "__main__":
    main()


Measured memory_bytes: 4596
import scala.io.StdIn.{readLine,readInt}
 
object Main {
 
  def main(args: Array[String]) = {
    val n = readInt
    val rooms = Array.ofDim[Int](4,3,10)
 
    1 to n foreach { _ =>
      val v = readLine.split(" ").map(_.toInt)
      rooms(v(0)-1)(v(1)-1)(v(2)-1) += v(3)
    }
 
    for(b <- 0 to 3) {
      for(f <- 0 to 2) {
        for(r <- 0 to 9) {
          print(" "+rooms(b)(f)(r))
        }
        println()
      }
      if(b!=3) {
        println("####################")
      }
    }
  }
}


Measured memory_bytes: 43988
// B - Trained?
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, e, f, h, k, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n;
  vlli d(n), z;
  set<lli> g;
  rep(i, 0, n)
  {
    cin >> d[i];
    // z.pb(d[i] - 1);
    d[i]--;
  }
  // rep(i, 0, n)
  // {
  //   if (d[i] != 2)
  //   {
  //     ans++;
  //   }
  // }
  // if (ans == n)
  // {
  //   cout << -1 << endl;
  //   return 0;
  // }

  // a = d[0];
  // if (a == 2)
  // {
  //   cout << count << endl;
  //   return 0;
  // }

  // while (!g.count(a) && count < n)
  // {

  //   g.insert(a);
  //   a = d[a - 1];
  //   count++;
  //   if (a == 2)
  //   {
  //     cout << count + 1 << endl;
  //     return 0;
  //   }
  // }
  rep(i, 0, n)
  {
    if (ans == 1)
    {
      cout << count << endl;
      return 0;
    }
    if (count >= n)
    {
      cout << -1 << endl;
      return 0;
    }
    count++;
    ans = d[ans];
  }
  cout << -1 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll n,k;
	cin>>n>>k;
		n=n%k;
		cout<<min(abs(n),abs(n-k));
 cout<<"\n"; 
 } 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
const LL MOD = (LL)1e9+7;
const LL INF = (LL)1e9+7;
const LL INFLL = (LL)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int n, m, s, t;
	cin >> n >> m >> s >> t;

	vector<vector<vector<PLL>>> road(2, vector<vector<PLL>>(n+1));
	vector<vector<LL>> fast(2, vector<LL>(n+1, INFLL));

	REP(i, m){
		LL a, b;
		cin >> a >> b;
		REP(i, 2){
			LL c;
			cin >> c;
			road[i][a].push_back(PII(b, c));
			road[i][b].push_back(PII(a, c));
		}
	}

	auto func = [&](int start, int id){
		auto &nroad = road[id];
		auto &nfast = fast[id];
		nfast[start] = 0;
		priority_queue<PLL, vector<PLL>, greater<PLL>> que;
		que.push(PLL(0, start));
		while(que.size()){
			PLL top = que.top();
			que.pop();
			if(nfast[top.second]!=top.first)continue;
			foreach(i, nroad[top.second]){
				LL nt = i.second + top.first;
				LL np = i.first;
				if(chmin(nfast[np], nt))que.push(PLL(nt, np));
			}
		}
	};

	func(s, 0);
	func(t, 1);

	multiset<LL> fasts;

	REPA(i, n+1){
		fasts.insert(fast[0][i] + fast[1][i]);
	}

	REPA(i, n+1){
		cout << (LL)1e15 - *fasts.begin() << endl;
		fasts.erase(fasts.find(fast[0][i] + fast[1][i]));
	}

	return 0;

}


Measured memory_bytes: 23092
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A, B, Q = LI()
    s = []
    t = []
    x = []
    for _ in range(A):
        s.append(I())
    for _ in range(B):
        t.append(I())
    for _ in range(Q):
        x.append(I())

    # ダミー境界を加える
    s = [-inf] + s + [inf]
    t = [-inf] + t + [inf]

    for pos in x:
        l_s = bisect.bisect_left(s, pos)
        l_t = bisect.bisect_left(t, pos)

        left_shrine = s[l_s-1]
        right_shrine = s[l_s]
        left_temple = t[l_t-1]
        right_temple = t[l_t]

        d1 = pos - min(left_shrine, left_temple)
        d2 = max(right_shrine, right_temple) - pos
        d3 = 2 * (pos - left_shrine) + (right_temple - pos)
        d4 = 2 * (right_temple - pos) + (pos - left_shrine)
        d5 = 2 * (pos - left_temple) + (right_shrine - pos)
        d6 = 2 * (right_shrine - pos) + (pos - left_temple)

        ans = min([
            d1, d2, d3, d4, d5, d6
        ])
        print(ans)

    '''
    ダミー境界を加えない場合
    for pos in x:
        l_s = bisect.bisect_left(s, pos)
        l_t = bisect.bisect_left(t, pos)

        if l_s == 0:
            left_shrine = None
        else:
            left_shrine = s[l_s-1]
        if l_s == A:
            right_shrine = None
        else:
            right_shrine = s[l_s]

        if l_t == 0:
            left_temple = None
        else:
            left_temple = t[l_t-1]
        if l_t == B:
            right_temple = None
        else:
            right_temple = t[l_t]

        d1, d2, d3, d4, d5, d6 = inf, inf, inf, inf, inf, inf
        if left_shrine and left_temple:
            d1 = pos - min(left_shrine, left_temple)
        if right_shrine and right_temple:
            d2 = max(right_shrine, right_temple) - pos
        if left_shrine and right_temple:
            d3 = 2 * (pos - left_shrine) + (right_temple - pos)
            d4 = 2 * (right_temple - pos) + (pos - left_shrine)
        if left_temple and right_shrine:
            d5 = 2 * (pos - left_temple) + (right_shrine - pos)
            d6 = 2 * (right_shrine - pos) + (pos - left_temple)

        ans = min([
            d1, d2, d3, d4, d5, d6
        ])
        print(ans)
        '''
main()



Measured memory_bytes: 19240
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
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 (a>b) { a=b; return 1; } return 0; }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n;
string s;
vector<string> tmp={"SS","SW","WS","WW"};
cin>>s;
for(int i=0;i<4;i++){
   vector<char> a(n,'!');
   a[0]=tmp[i][0],a[1]=tmp[i][1];
   bool ok=true;
   for(int j=1;j<=n;j++){
        if(s[j%n]=='o'&&a[j%n]=='S'){
            if(a[(j+1)%n]=='!')a[(j+1)%n]=a[j-1];
            else {
                if(a[(j+1)%n]!=a[j-1])ok=false;
            }
        }
        if(s[j%n]=='x'&&a[j%n]=='W'){
            if(a[(j+1)%n]=='!')a[(j+1)%n]=a[j-1];
            else {
                if(a[(j+1)%n]!=a[j-1])ok=false;
            }
        }
        if(s[j%n]=='x'&&a[j%n]=='S'){
            if(a[(j+1)%n]=='!'){
                if(a[j-1]=='S')a[(j+1)%n]='W';
                else a[(j+1)%n]='S';
            }
            else {
                if(a[(j+1)%n]==a[j-1])ok=false;
            }
        }
        if(s[j%n]=='o'&&a[j%n]=='W'){
            if(a[(j+1)%n]=='!'){
                if(a[j-1]=='S')a[(j+1)%n]='W';
                else a[(j+1)%n]='S';
            }
            else {
                if(a[(j+1)%n]==a[j-1])ok=false;
            }
        }
      }
    if(ok){
        for(int j=0;j<n;j++)cout<<a[j];
        cout<<endl;
        return 0;
    }  
   }
   cout<<-1<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double Pai= Math.PI;
        double r = sc.nextDouble();
        double P = r*r*Pai;
        double E = 2*Pai*r;
        System.out.printf("%6f %6f",P,E);
    }
}

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

int main()
{
    ll H, W;
    cin >> H >> W;

    ll ans;
    if (H == 1 || W == 1)
    {
        ans = 1;
    }
    else
    {
        ans = ((W + 1) / 2) * ((H + 1) / 2) + (W / 2) * (H / 2);
    }

    cout << ans << endl;

    return 0;
}

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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

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

	vector<bool> visited(n, false);
	vector<int> route;
	route.push_back(0);
	int cycle = INF;
	rep(i, n) {
		int position = route.back();
		if (visited[position]) {
			cycle = position;
			route.pop_back();
			break;
		}
		else if (!visited[position]) {
			visited[position] = true;
			route.push_back(a[position]);
		}
	}
	if (cycle == INF) cycle = route.back();
	int bloop = 0, loop = 0;
	for (auto x : route) {
		if (x == cycle) break;
		bloop++;
	}
	loop = route.size() - bloop;
	int ans = 0;
	if (k < bloop) ans = route[k] + 1;
	else {
		k -= bloop;
		k %= loop;
		k += bloop;
		ans = route[k] + 1;
	}

	/*
	for (auto x : route) cout << x << " ";
	cout << endl;
	cout << "bool: " << endl;
	for (auto x : visited) cout << x << " ";
	cout << endl;
	cout << "cycle point: " << cycle << endl;
	cout << bloop << " " << loop << endl;
	*/
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 5044
#include<bits/stdc++.h>
//#define int long long
#define LL long long
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef pair<int,int>pii;typedef vector<int>VI;typedef vector<pii>VP;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
const int N=105;
int n,m,f[N][N];bool g[N][N];char s[N][N];
signed main(){
	memset(f,63,sizeof(f));
	rd(n),rd(m);
	rep(i,1,n)scanf("%s",s[i]+1);
	f[0][1]=f[1][0]=0;
	rep(i,1,n){
		rep(j,1,m){
			if(i==1&&j==1){
				f[i][j]=s[i][j]=='#';
				continue;
			}
			memset(g,0,sizeof(g));
			g[i][j]=1;
			per(ii,i,1)per(jj,j,1){
				g[ii][jj]|=g[ii+1][jj]&(s[ii][jj]==s[i][j]);
				g[ii][jj]|=g[ii][jj+1]&(s[ii][jj]==s[i][j]);
				if(g[ii][jj]){
					f[i][j]=min(f[i][j],f[ii-1][jj]+(s[i][j]=='#'));
					f[i][j]=min(f[i][j],f[ii][jj-1]+(s[i][j]=='#'));
				}
			}
		}
	}
	pt(f[n][m],'\n');
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;

int main() {
  char C;
  cin >> C;
  C++;
  cout << C << endl;
  return 0;
}


Measured memory_bytes: 256
def f(n,k):
  return (n+1)*(n+k+1)*(n-k+2)//2+k*(k-1)*(2*k-1)//6-(n+1)*(n+2)*(2*n+3)//6+n-k+2

n,k=map(int,input().split())
print(f(n,k)%1000000007)

Measured memory_bytes: 61736
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
//
const int MX = 1e5 + 1337;
int dp[MX]; // 1 - win, 0 - lose
int32_t main()
{
    // A =  { a_1 , a_ 2, ... a _ n}
    //
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    forn(i,n)
    cin >> a[i];
    for(int i = 0 ; i <= k; i++){
        for(int j = 0; j < n; j++){
            if( i >= a[j] && dp[i - a[j]] == 0) // мы можем сходить в проиг состояние
            {
                dp[i] = 1;
            }
        }
    }
    if(dp[k]==1)
        cout << "First\n";
    else
        cout << "Second\n";
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
arr = list(map(int, input().split()))


a = 0
b = 0

isAlice = True

while n > 0:
    
    if isAlice:
        a += max(arr)
        isAlice = False
    else:
        b += max(arr)
        isAlice = True
    
    arr.remove(max(arr))
    n -= 1
    
print(a - b)
    

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

int main() {
  int n;
  cin >> n;
  int a[3] = {0};

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x % 4 == 0) a[2]++;
    else if (x % 2 == 0) a[1]++;
    else a[0]++;
  }

  if (a[1] == n) {
    puts("Yes");
    return 0;
  }

  if (a[1]) a[0]++;
  cout << (a[2] + 1 >= a[0] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
 
#define MOD 998244353LL

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  
  vector <pair<long long, long long>> d(K);
  for (int i = 0; i < K; ++i) {
    cin >> d[i].first >> d[i].second;
  }
  
  vector <long long> dp(N, 0);
  vector <long long> dp_sum(N, 0);
  dp[0] = 1;
  dp_sum[0] = 1;
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < K; ++j) {
      if (i - d[j].second <= 0 && i - d[j].first >= 0) {
        dp[i] += dp_sum[i - d[j].first];
      } else if (i - d[j].second > 0) {
        dp[i] += (dp_sum[i - d[j].first] - dp_sum[i - d[j].second - 1]);
      }
      dp[i] %= MOD;
    }
    dp_sum[i] = dp_sum[i - 1] + dp[i];
  }
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 6408