akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define INF 1010001000
#define MAX_V 10001
#define MAX_E 100000
#define min(a, b) a<b?a:b

typedef struct edge {
    int from, to, cost;
}edge;

int par[MAX_V], rank[MAX_V];

void init(int n);
int find(int x);
void unite(int x, int y);
int same(int x, int y);
int cmp(const void *a, const void *b);
int kruskal(void);

edge input[MAX_E];
int V, E;


int main(void)
{
    int i, j, s, t, d;
    scanf("%d %d", &V, &E);
    for (i = 0; i < E; i++) {
        scanf("%d %d %d", &input[i].from, &input[i].to, &input[i].cost);
    }
    printf("%d\n", kruskal());
    return 0;
}


int kruskal(void)
{
    edge e;
    int i, res = 0;
    init(V);
    qsort(input, E, sizeof(edge), cmp);
    for (i = 0; i < E; i++) {
        e = input[i];
        if (same(e.from, e.to)) {
            unite(e.from, e.to);
            res += e.cost;
        }
    }
    return res;
}

int cmp(const void *a, const void *b)
{
    edge temp1 = *(edge *) a;
    edge temp2 = *(edge *) b;
    return temp1.cost - temp2.cost;
}

void init(int n)
{
    int i;
    for (i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int find(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) {
        return ;
    }
    if (rank[x] < rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
}

int same(int x, int y)
{
    //同じなら0, 違うならそれ以外
    return find(x) - find(y);
}

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 200005


int main(){
sp;
    int limit,n;
    cin>>n>>limit;
    ll w[n+1],a[n+1];
    for(int i=1; i<=n; ++i) cin>>w[i]>>a[i];
    ll dp[n+1][limit+1];
    memset(dp,0,sizeof dp);
    for(int i=1;i<n+1; ++i){
        for(int j=1; j<limit+1; ++j){
            if(w[i]<=j)
        dp[i][j]=max(a[i]+dp[i-1][j-w[i]],dp[i-1][j]);
        else
            dp[i][j]=dp[i-1][j];
        }}
 cout<<dp[n][limit];
return 0;}


Measured memory_bytes: 79232
#include<stdio.h>
main(){
  int a[4],b[4],i,hit,blow,j;
  while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
    hit=0;
    blow=0;
    scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
    for(i=0;i<4;i++){
      if(a[i]==b[i])
	hit++;
      else{
	for(j=0;j<4;j++){
	  if(a[i]==b[j])
	    blow++;
	}
      }
    }
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

Measured memory_bytes: 0
import math

N = int(input())
S = [list(map(int, input().split())) for i in range(N)]

def dist(x,y):
  return math.sqrt((x[0]-y[0])**2 + (x[1]-y[1])**2)

ans = 0
for i in range(N):
  for j in range(N):
    if j==i:
      continue
    ans += dist(S[i],S[j])
ans = ans / N

print(ans)

Measured memory_bytes: 38384
memo = {}
def f(x):
    if 0<=x<=5:
        return x
    if x in memo:
        return memo[x]
    k = 0
    while 9**k<=x:
        k += 1
    m = 0
    while 6**m<=x:
        m += 1
    memo[x] = min(f(x-9**(k-1))+1,f(x-6**(m-1))+1)
    return memo[x]
print(f(int(input())))    

Measured memory_bytes: 38384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		
		int[][] fish = new int[N][6];
		
		TreeSet<Integer> x_tree = new TreeSet<Integer>();
		TreeSet<Integer> y_tree = new TreeSet<Integer>();
		TreeSet<Integer> d_tree = new TreeSet<Integer>();
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j < 6; j++){
				fish[i][j] = sc.nextInt();
				
				switch(j % 3){
				case 0:
					x_tree.add(fish[i][j]);
					break;
				case 1:
					y_tree.add(fish[i][j]);
					break;
				case 2:
					d_tree.add(fish[i][j]);
					break;
				}
			}
		}
		
		ArrayList<Integer> x_list = new ArrayList<Integer>(x_tree);
		ArrayList<Integer> y_list = new ArrayList<Integer>(y_tree);
		ArrayList<Integer> d_list = new ArrayList<Integer>(d_tree);
		
		final int x_size = x_list.size();
		final int y_size = y_list.size();
		final int d_size = d_list.size();
		
		int[] x_dist = new int[x_size - 1];
		int[] y_dist = new int[y_size - 1];
		int[] d_dist = new int[d_size - 1];
		for(int x = 0; x < x_size - 1; x++){
			x_dist[x] = x_list.get(x + 1) - x_list.get(x);
		}
		for(int y = 0; y < y_size - 1; y++){
			y_dist[y] = y_list.get(y + 1) - y_list.get(y);
		}
		for(int d = 0; d < d_size - 1; d++){
			d_dist[d] = d_list.get(d + 1) - d_list.get(d);
		}
		
		int[][][] area = new int[d_size - 1][y_size - 1][x_size - 1];
		long sum = 0;
		
		for(int i = 0; i < N; i++){
			int x_start = Collections.binarySearch(x_list, fish[i][0]);
			int y_start = Collections.binarySearch(y_list, fish[i][1]);
			int d_start = Collections.binarySearch(d_list, fish[i][2]);
			int x_end   = Collections.binarySearch(x_list, fish[i][3]);
			int y_end   = Collections.binarySearch(y_list, fish[i][4]);
			int d_end   = Collections.binarySearch(d_list, fish[i][5]);
			
			if(x_start < 0){
				x_start = -(x_start + 1);
			}
			if(y_start < 0){
				y_start = -(y_start + 1);
			}
			if(d_start < 0){
				d_start = -(d_start + 1);
			}
			
			if(x_end < 0){
				x_end = -(x_end + 2);
			}else{
				x_end--;
			}
			if(y_end < 0){
				y_end = -(y_end + 2);
			}else{
				y_end--;
			}
			if(d_end < 0){
				d_end = -(d_end + 2);
			}else{
				d_end--;
			}
			
			for(int d = d_start; d <= d_end; d++){
				for(int y = y_start; y <= y_end; y++){
					for(int x = x_start; x <= x_end; x++){
						if(area[d][y][x] >= K){
							continue;
						}else{
							area[d][y][x]++;
							
							if(area[d][y][x] >= K){
								long x_d = x_dist[x];
								long y_d = y_dist[y];
								long d_d = d_dist[d];
								sum += (x_d * y_d * d_d);
							}
						}
					}
				}
			}
		}
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 25888
#include<iostream>
#include<algorithm>

using namespace std;

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

    long long x[N], y[N], z[N];
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> z[i];
    }
    long long ppp[N];
    long long ppm[N];
    long long pmp[N];
    long long pmm[N];
    long long mpp[N];
    long long mpm[N];
    long long mmp[N];
    long long mmm[N];
    for(int i = 0; i < N; i++){
        ppp[i] = x[i] + y[i] + z[i];
        ppm[i] = x[i] + y[i] - z[i];
        pmp[i] = x[i] - y[i] + z[i];
        pmm[i] = x[i] - y[i] - z[i];
        mpp[i] = -x[i] + y[i] + z[i];
        mpm[i] = -x[i] + y[i] - z[i];
        mmp[i] = -x[i] - y[i] + z[i];
        mmm[i] = -x[i] - y[i] - z[i];
    }
    sort(ppp, ppp+N, greater<long>());
    sort(ppm, ppm+N, greater<long>());
    sort(pmp, pmp+N, greater<long>());
    sort(pmm, pmm+N, greater<long>());
    sort(mpp, mpp+N, greater<long>());
    sort(mpm, mpm+N, greater<long>());
    sort(mmp, mmp+N, greater<long>());
    sort(mmm, mmm+N, greater<long>());

    long long ans[8] = {};

    for(int i = 0; i < M; i++){
        ans[0] += ppp[i];
        ans[1] += ppm[i];
        ans[2] += pmp[i];
        ans[3] += pmm[i];
        ans[4] += mpp[i];
        ans[5] += mpm[i];
        ans[6] += mmp[i];
        ans[7] += mmm[i];
    }
    long long m = ans[0];
    for (int i = 1; i < 8; i++){
        m = max(m, ans[i]);
    }

    cout << m;
}
    

Measured memory_bytes: 384
using System;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            string S = Console.ReadLine();
            int len = S.Length;
            int sum1=0;
            int sum2=0;
            for(var i=0;i<len;i++){
                if(i%2==0&&S[i]=='1')
                    sum1++;
                if(i%2==1&&S[i]=='0')
                    sum1++;
            }

            for(var i=0;i<len;i++){
                if(i%2==0&&S[i]=='0')
                    sum2++;
                if(i%2==1&&S[i]=='1')
                    sum2++;
            }
            Console.WriteLine(Math.Min(sum1,sum2));
        }
    }
}

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

int main(){
    long n;
    cin >> n;
    long a;
    cin >> a;
    long b;
    cin >> b;
    long c = b - a;
    if(!(c%2))cout << c/2 << endl;
    else{
        long d;
        if(a <= n - b)d = a + b;
        else  d = 2 * n - a - b + 1;
        cout << d/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
    #define MAX 100000
    #define NIL -1

    struct Node{int p, l, r;};
    struct Node T[MAX];
    int n, H, D[MAX];

    int getDepth(int u){
    int d = 0;
    for(d = 0; T[u].p != NIL ;d++) u = T[u].p;
    return d;
    }

    void print(int u){
    int i, c;
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].p);
    printf("depth = %d, ", D[u]);

    if ( T[u].p == NIL ) printf("root, ");
    else if ( T[u].l == NIL ) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if (i) printf(", ");
        printf("%d", c);
    }
    printf("]\n");
    }

    int main(){
    int i, j, d, v, c, l;
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

    for ( i = 0; i < n; i++ ){
        scanf("%d %d", &v, &d);
        for ( j = 0; j < d; j++ ){
        scanf("%d", &c);
        if ( j == 0 ) T[v].l = c;
        else T[l].r = c;
        l = c;
        T[c].p = v;
        }
    }
    
    H = 0;
    for ( i = 0; i < n; i++ ){
        D[i] = getDepth(i);
        if ( D[i] > H ) H = D[i];
    }

    for ( i = 0; i < n; i++ ) print(i);
    return 0;
    }


Measured memory_bytes: 3304
#include<stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(r<=x&&r<=(W-x)&&r<=y&&r<=(H-y))
	{
       printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;

}



Measured memory_bytes: 2000
#サイコロの目からk個ずつ順にループで切り出して和をリストするとTLE
#累積和のリストから、k個の和のリスト → 期待値のリストでTLE解消

from itertools import accumulate

n, k = map(int,input().split())
l = list(map(int,input().split()))

p = [0] + list(accumulate(l))

q = [] #累積和'p'からから求めたk個ずつの和
r = [] #出目の期待値
for i in range(n-k+1):
    q.append(p[i+k] - p[i])
    r.append((q[i] + k) / 2)

print(max(r))


Measured memory_bytes: 89096
#include <bits/stdc++.h>
using namespace std;
const double con = 0.006;
int main()
{
	float t;
	int a,n;
	cin>>n>>t>>a;
	float best = 1e9;
	float place = 0;
	for(int i =0;i<n;i++)
	{
		float h;
		cin>>h;
		float avr = t - h * con;
		//cout<<i<<" "<<avr<<endl;
		if(best > abs(float(a) - avr))
		{
			best = abs(float(a) - avr);
			place = i + 1;
		}
	}
	cout<<place<<endl;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> A(N);
  for (auto &it : A)
    cin >> it;
  map<ll, int> mp;
  for (int i = 0; i < N; i++)
    mp[i + A[i]]++;
  ll ans = 0;
  for (int j = 0; j < N; j++)
  {
    ans += mp[j - A[j]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27468
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<complex>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb(i) push_back(i)
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int d[512][512];
int main(){
	int n,m;
	while(cin >> n && n){
		m = 0;
		fill_n(d[0],512*512,INF);
		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			d[a][b] = d[b][a] = c;
			m = max(m,max(a+1,b+1));
		}
		rep(i,m)d[i][i] = 0;
		rep(k,m)rep(i,m)rep(j,m){
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		}
		int city = -1, val = INF;
		rep(i,m){
			int tmp = 0;
			rep(j,m){
				tmp += d[i][j];
			}
			if(tmp < val){
				val = tmp;
				city = i;
			}
		}
		cout << city << " " << val << endl;
	}
	return 0;
}

Measured memory_bytes: 2188
#include<stdio.h>

int bubblesort(int A[],int n)
{
    int count=0;
    int flag=1;
    for(int i=0;flag;i++)
    {
        flag=0;
        for(int j=0;j<n-i-1;j++)
        {
          if(A[j]>A[j+1])
          {
              int tmp=A[j];
              A[j]=A[j+1];
              A[j+1]=tmp;
              count++;
              flag=1;
          }
        }
    }
    return count;
}

int main()
{
    int n;
    scanf("%d",&n);
    int A[n];
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    int count = bubblesort(A,n);
    for(int i=0;i<n;i++)
    {
        if(i)printf(" ");
        printf("%d",A[i]);

    }
    printf("\n%d\n",count);
    return 0;
}



Measured memory_bytes: 2104
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=998244353
n,k = gets.chomp.split.map(&:to_i)
ls = []
rs = []
k.times do
  ll, rr = gets.chomp.split.map(&:to_i)
  ls.push ll
  rs.push rr
end

dp = Array.new(n+1, 0)
dp[1] = 1
kukan_sum = Array.new(k, 0)

2.upto(n) do |i|
  count = 0
  k.times do |j|
    l = i - rs[j]
    r = i - ls[j]
    if r >= 1
      kukan_sum[j] += dp[r]
    end
    if l >= 2
      kukan_sum[j] -= dp[l-1]
    end
    kukan_sum[j] = (kukan_sum[j] + MOD) % MOD
    count += kukan_sum[j]
  end
  dp[i] = count % MOD
end

# p dp

puts dp.last


Measured memory_bytes: 16168
N = int(input())
A = list(map(int,input().split()))
csum = [0]
temp = 0
for a in A:
    temp += a
    csum.append(temp)
# csum.sort()
# print(csum)
from collections import Counter
freq = Counter(csum)
ans = 0
for v in freq.values():
    ans += (v*(v-1))//2
print(ans)

Measured memory_bytes: 41492
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define _GLIBCXX_DEBUG
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  string s;cin >> s;
  if(s[0] == s[1]&&s[1] == s[2]) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void swap(int[] m, int x, int y){
		int temp = m[x-1];
		m[x-1] = m[y-1];
		m[y-1] = temp;
	}
		
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		int w = stdIn.nextInt();
		int[] m = new int[w];
		for(int i = 0; i < w; i++){
			m[i] = i+1;
		}
		int n = stdIn.nextInt();
		String[] str = new String[n];
		for(int i = 0; i < n; i++){
			str[i] = stdIn.next();
		}
		String[][] s = new String[n][2];
		int[][] line = new int[n][2];
		for(int i = 0; i < n; i++){
			s[i] = str[i].split(",");
			line[i][0] = Integer.parseInt(s[i][0]);
			line[i][1] = Integer.parseInt(s[i][1]);
		}
		for(int i = 0; i < n; i++){
			swap(m,line[i][0],line[i][1]);
		}
		
		for(int i = 0; i < w; i++){
			System.out.println(m[i]);
		}
	}
}

Measured memory_bytes: 12000
Q=int(input())
ans=0
from heapq import heappush,heappop
left=[]
right=[]
L=-1*float('inf')
R=float('inf')
for i in range(Q):
    q=input()
    if q=="2":
        print(" ".join([str(L),str(ans)]))
    else:
        s,a,b=map(int,q.split())
        ans+=b
        if L<=a<=R:
            heappush(left,-1*a)
            heappush(right,a)
            L=a
            R=a
        elif a<L:
            ans+=L-a
            x=heappop(left)
            heappush(right,-1*x)
            heappush(left,-1*a)
            heappush(left,-1*a)
        elif R<a:
            ans+=a-R
            x=heappop(right)
            heappush(left,-1*x)
            heappush(right,a)
            heappush(right,a)
        R=right[0]
        L=-1*left[0]

Measured memory_bytes: 19068
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():

    w, h, n = [int(x) for x in input().split()]
    l, r, u, d = 0, w, h, 0
    for _ in range(n):
        x, y, a = [int(x) for x in input().split()]
        if a == 1:
            l = max(l, x)
        elif a == 2:
            r = min(r, x)
        elif a == 3:
            d = max(d, y)
        else:
            u = min(u, y)
    print(max(0, (r - l)) * max(0, (u - d)))

    
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""


Measured memory_bytes: 9464
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int A[] =new int[N+1];
        
        int num1=0;
        int num2=0;
        int m;
        
        for(int i=1;i<=M;i++){
            
            m=sc.nextInt();
            A[m]=1;
            
        }
        for(int i=X;i>=0;i--){
            
            num1+=A[i];
            
        }
        for(int i=X;i<=N;i++){
            
            num2+=A[i];
            
        }
        int min_num = Math.min(num1, num2);
        
        System.out.println(min_num);
        
    }
}


Measured memory_bytes: 36024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin>> n >> m>> c;
    vector<int> b(m);
    for(int i=0;i<m;i++)cin >> b.at(i);
    int h=0;
    int sum;
    for(int i=0;i<n;i++){
        sum=c;
        for(int j=0;j<m;j++){
            int a;
            cin >> a ;
            sum+=a*b.at(j);
        }
        //cout << sum << endl;
        if(sum>0)h++;
    }
    cout << h << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]

a = h[0]
for i in range(1, n-1):
    a = max(h[i], a)
    b = h[i+1]
    if a-b >= 2:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 14252
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int n;
    scanf("%d", &n);
    int a[n];

    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            printf("%d", a[n-1-i]);
        } else {
            printf(" %d", a[n-1-i]);
        }
    }

    printf("\n");
    
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define MAXN   1015
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n ;
    cin >> n ;
    map < ll , map< ll , ll > > mp ;
    for ( int i = 1 ; i <= n ; i++) {
        int x = i%10 , y = i  ;
        while (y >= 10) {
            y /= 10 ;
        }
        mp[y][x]++ ;
    }
    ll res = 0 ;
    for ( int i = 0 ; i <= 9 ; i++) {
        for ( int j = 0 ; j <= 9 ; j++) {
            res += (mp[i][j] * mp[j][i]) ;
        }
    }
    cout << res ;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int V,E;
vvi g;
vi tsort(){
    vi indeg(V, 0);
    stack<int> S;
    rep(i,V) for(auto v : g[i]) indeg[v]++;
    rep(i,V) if(indeg[i] == 0) S.push(i);

    vi res;
    while(S.size()>0){
        int v = S.top(); S.pop();
        res.emplace_back(v);
        for(auto u : g[v]){
            indeg[u]--;
            if(indeg[u] == 0) S.push(u);
        }
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> V >> E;
    g = vvi(V);
    rep(i,E){
        int s,t; cin >> s >> t;
        g[s].push_back(t);
    }
    vi ans = tsort();
    rep(i,V){
        cout << ans[i] << endl;
    }
    return 0;
}


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

using namespace std;

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

pair<int, int> a[100];
pair<int, int> b[100];

bool fa[100];
int N;

int main()
{
	int N;
	cin >> N;
	rep(i, N) {
		int t, t2;
		cin >> t >> t2;
		a[i] = MP(t, t2);
	}
	rep(i, N) {
		int t, t2;
		cin >> t >> t2;
		b[i] = MP(t, t2);
	}
	sort(a, a+N);
	sort(b, b+N);
	int res = 0;
	rep(i, N) {
		int x = b[i].first;
		int y = b[i].second;
		int ma = -1;
		int wj = -1;
		rep(j, N) {
			if (a[j].first > x) break;
			if (y <= a[j].second) continue;
			if (ma < a[j].second && !fa[j]) {
				ma = a[j].second;
				wj = j;
			}
		}
		if (wj != -1) {
			res++;
			fa[wj] = true;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
H,W,K = map(int, input().split())

mod = 10**9+7
dp = [[0]*W for _ in range(H+1)]

dp[0][0] = 1
L = [1, 2, 3, 5, 8, 13, 21]
for i in range(H):
    for j in range(W):
        if j > 0:
            dp[i+1][j] += dp[i][j-1]*L[max(0, j-2)]*L[max(0, W-2-j)]
        if j < W-1:
            dp[i+1][j] += dp[i][j+1]*L[max(0, j-1)]*L[max(0, W-3-j)]
        dp[i+1][j] += dp[i][j]*L[max(0, j-1)]*L[max(0, W-2-j)]
        dp[i+1][j] %= mod
        
print(dp[H][K-1])

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class a, int N, class T>
void fillArray(a(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string a, b, c;
bool mab[100005], mac[100005], mbc[100005];
void solve() {
    cin >> a >> b >> c;
    fillArray(mab, true);
    fillArray(mac, true);
    fillArray(mbc, true);
    rep(i, sz(a)) rep(j, sz(b)) if (a[i] != '?' && b[j] != '?' && a[i] != b[j]) mab[i - j + 50000] = false;
    rep(i, sz(a)) rep(j, sz(c)) if (a[i] != '?' && c[j] != '?' && a[i] != c[j]) mac[i - j + 50000] = false;
    rep(i, sz(b)) rep(j, sz(c)) if (b[i] != '?' && c[j] != '?' && b[i] != c[j]) mbc[i - j + 50000] = false;
    int ans = iinf;
    loops(i, -4000, 4000) loops(j, -4000, 4000)
        if (mab[i + 50000] && mac[j + 50000] && mbc[j - i + 50000])
            mins(ans, max({ i + sz(b),j + sz(c),sz(a) }) - min({ i,j,0 }));
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";

signed main()
{
	//freopen("input.txt", "r", stdin);
	string s; cin>>s;
	string str[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	for(int i=0; i<7; i++)
	{
		if(str[i] == s)
		{
			cout<<7-i<<"\n";
			break;
		}
	}
	
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int n;
int x[100000], l[100000];
P p[100000];

int main() {
	int i;
	
	cin >> n;
	rep(i, n) {
		cin >> x[i] >> l[i];
		P hoge = P(x[i] + l[i], x[i] - l[i]);
		p[i] = hoge;
	}
	sort(p, p + n);
	
	int last = -1e+9;
	int cnt = 0;
	rep(i, n) {
		if (last > p[i].second) {
			continue;
		}
		else {
			last = p[i].first;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int a[100001];
int n; 
int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
	}
	int ans=0;
	for(int i=1;i*i<=a[0];i++){
		if(a[0]%i)continue;
		int ii=a[0]/i;
		int x=0;
		forn(j,0,n){
			if(a[j]%i)
			x++;
			if(x==2)
			break;
		}
		if(x!=2)
		ans=max(ans,i);
		x=0;
		forn(j,0,n){
			if(a[j]%ii)
			x++;
			if(x==2)
			break;
		}
		if(x<2)ans=max(ans,ii);
	}
	for(int i=1;i*i<=a[1];i++){
		if(a[1]%i)continue;
		int ii=a[1]/i;
		int x=0;
		forn(j,0,n){
			if(a[j]%i)
			x++;
			if(x==2)
			break;
		}
		if(x!=2)
		ans=max(ans,i);
		x=0;
		forn(j,0,n){
			if(a[j]%ii)
			x++;
			if(x==2)
			break;
		}
		if(x<2)ans=max(ans,ii);
	}
	cout<<ans; 
	re 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int M = sc.nextInt();
    	int[] a = new int[A];
    	int[] b = new int[B];
    	int aMin = 100001;
    	int bMin = 100001;
    	for(int i = 0; i < A; i++){
    	    a[i] = sc.nextInt();
    	    aMin = Math.min(aMin, a[i]);
    	}
    	for(int i = 0; i < B; i++){
    	    b[i] = sc.nextInt();
    	    bMin = Math.min(bMin, b[i]);
    	}
    	int ans = aMin + bMin;
    	for(int i = 0; i < M; i++){
			int t1 = sc.nextInt()-1;
			int t2 = sc.nextInt()-1;
			int t3 = sc.nextInt();
			int sum = a[t1] + b[t2] - t3;
			ans = Math.min(sum, ans);
    	}
    	sc.close();
    	System.out.println(ans);
    }
}

Measured memory_bytes: 151268
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
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; }
inline ll pow2(const int n) { return 1ll << n; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
// 1. 問題よくよめえええええええええええええええええええええええええ
// 2. intオーバーフロー << * + あたり
// 3. 落ち着け

int N, T, A;
vi H;

int main() {
    cin >> N >> T >> A;
    H.resize(N);
    rep(i, N) cin >> H[i];

    int ans;
    double diff = DBL_MAX;
    rep(i, N) {
        double t = T - 0.006 * H[i];
        if (abs(t - A) < diff) {
            diff = abs(t - A);
            ans = i + 1;
        }
    }
    write(ans);
}

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

int main() {
  int n1; cin >> n1;
  int ans = n1;
  while (true) {
    char op; cin >> op;
    if (op == '+') {
      int n; cin >> n;
      ans += n;
    } else if (op == '-') {
      int n; cin >> n;
      ans -= n;
    } else if (op == '*') {
      int n; cin >> n;
      ans *= n;
    } else if (op == '/') {
      int n; cin >> n;
      ans /= n;
    } else break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
 
bool f[10003];
 
bool f2[10003];
 
 
int main(){
 
for(int i=0;i<10002;i++)
for(int j=2;j*j<=i;j++)
{if(i%j!=0)f[i]=true;
else{ f[i]=false;break;}
}
f[3]=true;f[5]=true;
 
for(int i=0;i<10002;i++) 
if(f[i]==true&&f[i+2]==true)f2[i]=true;
f2[5]=true;
int n;
while(1){
scanf("%d",&n);if(n==0)break;
int p=0,q=0;
for(int i=n-2;i>=5;i--)
if(f2[i]==true){q=i+2;p=i;break;}
if(n<=6){p=3;q=5;}
printf("%d %d\n",p,q);
}
return 0;
}

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

#define int long long
#define inf 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

int n;
int d[114514];

int solve(int b) {
  if(b + 2 < n) {
    mfor(i, b, n - 1) {
      if((d[b] - d[b + 1]) * (d[i] - d[i + 1]) < 0) {
        return solve(i + 1) + 1;
      }
    }
    return 1;
  }
  else {
    return 1;
  }
}

signed main() {
  cin >> n;
  rep(i, n) {
    cin >> d[i];
  }
  n = unique(d, d + n) - d;
  cout << solve(0) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------
const ll MAX_V = 200010;

class dijkstra {
public:

    struct edge {
        ll to;
        ll cost;
    };

    vector<edge> E[MAX_V];
    ll d[MAX_V];

    void calc(ll s) {
        priority_queue <pll, vector<pll>, greater<pll> > que;
        rep(i, MAX_V) d[i] = LINF;
        que.emplace(0LL, s);
        d[s] = 0LL;
        while (!que.empty()) {
            pll p = que.top();
            que.pop();
            ll v = p.second;
            if (d[v] < p.first) continue;

            for (auto&& e : E[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.emplace(d[e.to], e.to);
                }
            }
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    dijkstra ds;
    int n;
    cin >> n;

    rep(i, n - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        ds.E[a].push_back({b, c});
        ds.E[b].push_back({a, c});
    }

    int q, k;
    cin >> q >> k;
    ds.calc(k);

    rep(i, q) {
        int x, y;
        cin >> x >> y;
        cout << ds.d[x] + ds.d[y] << endl;
    }


    return 0;
}


Measured memory_bytes: 14320
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N;
   cin >> N;
   int H[N];
   int cnt = 1;
   int max = 0;
   for (int i = 0; i < N; i++) {
      cin >> H[i];
      if (i == 0) max = H[i];
      if (i != 0 && H[i] >= max) {
         cnt++;
         max = H[i];
      }
   }
   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 256
s=list(input())
s_b = s[::-1]

count = 0
ans = [0] * len(s)
for i in range(len(s)):
    if s[i] != s_b[i]:
        count += 1
        ans[i] = 1


for i in range(len(s)//2):
    if ans[i] == 1:
        s_b[i] = s[i]

#print(s_b)
print(ans.count(1)//2)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int a,b;char c='!';
    while(1){
    scanf("%d %c %d",&a,&c,&b);
    if(c=='+'){printf("%d\n",a+b);}
    if(c=='-'){printf("%d\n",a-b);}
    if(c=='*'){printf("%d\n",a*b);}
    if(c=='/'){printf("%d\n",a/b);}
    if(c=='?')break;
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
using namespace std;
int main()
{
	long i,n,ans=0;
	cin >> n;
	long a[n+1];
	for(i=1;i<=n;i++){
		cin >> a[i];
		if(a[i]==a[i-1]){
			ans++;
			a[i]=101;
		}
	} 
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

int main() {
    int n, sum = 0;
    string s;
    cin >> n >> s;

    for(int i = 0; i < n; i++) {
        if(s.at(i) == 'R') {
            sum++;
        }
    }

    if(sum > (n / 2)) puts("Yes");
    else puts("No");

    return 0;
}

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

int n, m, q;
std::vector<int> *g;
int *rem[11], *v, *d, *c;

int main() {
	scanf("%d%d", &n, &m);
	g = new std::vector<int>[n];
	for (int i = 0; i < 11; ++i) {
		rem[i] = new int[n];
		for (int j = 0; j < n; ++j) {
			rem[i][j] = 0;
		}
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[--u].push_back(--v);
		g[v].push_back(u);
	}
	scanf("%d", &q);
	v = new int[q];
	d = new int[q];
	c = new int[q];
	for (int i = 0; i < q; ++i) {
		scanf("%d%d%d", v + i, d + i, c + i);
		rem[d[i]][--v[i]] = i + 1;
	}
	for (int i = 10; i; --i) {
		for (int u = 0; u < n; ++u) {
			for (int v: g[u]) {
				rem[i - 1][v] = std::max(rem[i - 1][v], rem[i][u]);
			}
		}
	}
	for (int u = 0; u < n; ++u) {
		int mx = 0;
		for (int d = 0; d < 11; ++d) {
			mx = std::max(mx, rem[d][u]);
		}
		printf("%d\n", mx ? c[mx - 1] : 0);
	}
	return 0;
}

Measured memory_bytes: 12024
n=int(input())
s=input()
def e(c):
    if c=="S":
        return "W"
    else:
        return "S"

def f(s1,sn,s2):
    ans=[""]*n
    ans[0]=s1
    ans[1]=s2
    for i in range(1,n-1):
        if s[i]=="o":
            if ans[i]=="S":
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=e(ans[i-1])
        else:
            if ans[i]=="W":
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=e(ans[i-1])
    if ans[-1]!=sn:
        return False
    elif s[-1]=="o":
        if ans[-1]=="S":
            if ans[-2]==ans[0]:
                return ans
        else:
            if ans[0]==e(ans[-2]):
                return ans
    else:
        if ans[-1]=="W":
            if ans[-2]==ans[0]:
                return ans
        else:
            if ans[0]==e(ans[-2]):
                return ans
    return False

if s[0]=="o":
    if f("S","S","S"):
        print(*f("S","S","S"),sep="")
    elif f("W","S","W"):
        print(*f("W","S","W"),sep="")
    elif f("W","W","S"):
        print(*f("W","W","S"),sep="")
    elif f("S","W","W"):
        print(*f("S","W","W"),sep="")
    else:
        print(-1)
else:
    if f("W","W","W"):
        print(*f("W","W","W"),sep="")
    elif f("W","S","S"):
        print(*f("W","S","S"),sep="")
    elif f("S","S","W"):
        print(*f("S","S","W"),sep="")
    elif f("S","W","S"):
        print(*f("S","W","S"),sep="")
    else:
        print(-1)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int fn(string s)
{
  int sum = 0;
  each (c, s) sum += c - '0';
  return sum;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    int mx = fn(s);
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '0') continue;
      string t = s;
      t[i] = t[i] - 1;
      fill(t.begin() + i + 1, t.end(), '9');
      mx = max(mx, fn(t));
    }
    cout << mx << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define N 100000
#define Q 1000
 
void enq1(int);
int deq1(void);
void enq2(int);
int deq2(void);
 
int head=0,tail=0,p;
int S1[N],S2[N];
 
int main(){
 
  int n,q,i,T=0,a,b,c=0;
  char name[N][10];
  int time[N];
 
  scanf("%d %d",&n,&q);
 
  for(i=0 ; i<n ; i++){
    scanf("%s %d",name[i],&time[i]);
    enq1(time[i]);
    enq2(i);
  }
 
 
  while(1){
    a=deq1();
    b=deq2();
 
    if(head==N) head=0;
    if(tail==N) tail=0;
 
    if(a-q<=0){
      T+=a;
      printf("%s %d\n",name[b],T);
      c++;
      if(c==n) break;
    }
    else{
      T+=q;
      a-=q;
      enq1(a);
      enq2(b);
    }
  }
 
  return 0;
}
 
void enq1(int n){
  S1[tail]=n;
  tail++;
}
 
int deq1(){
  head++;
  return S1[head-1];
}
 
void enq2(int n){
  S2[tail]=n;
  tail++;
}
 
int deq2(){
  head++;
  return S2[head-1];
}


Measured memory_bytes: 3264
import sys

INF = 1000000007

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

n, a, b = na()
x = list(na())

ans = 0

for i in range(len(x) - 1):
    ans = ans + min((x[i+1] - x[i]) * a, b)

print(ans)

Measured memory_bytes: 14168
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
    int n, x[100] = {}, y[100] = {};

    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];
    
    double d1 = 0, d2 = 0, d3 = 0, di = 0;
    for (int i = 0; i < n; i++) {
        double a = fabs(x[i] - y[i]);
        d1 += a;
        d2 += pow(a, 2.0);
        d3 += pow(a, 3.0);
        di = max(di, a);
    }
    d2 = pow(d2, 1.0/2.0);
    d3 = pow(d3, 1.0/3.0);
    
    printf("%.6f\n", d1);
    printf("%.6f\n", d2);
    printf("%.6f\n", d3);
    printf("%.6f\n", di);

    return 0;
}


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

struct G {

    public int edge, d;
    public int[] a;

    public G(int n) {
        edge = n;
        a = new int[n];
        d = -1;
    }
}

class C11{
    public static void Main() {

        int n = int.Parse(Console.ReadLine());
        G[] g = new G[n + 1];

        for(int i = 0; i < n; i++) {
            string[] str = Console.ReadLine().Split(' ');
            int stringToInt1 = int.Parse(str[0]), stringToInt2 = int.Parse(str[1]);
            g[stringToInt1] = new G(stringToInt2);

            for(int j = 0; j < stringToInt2; j++) {
                g[stringToInt1].a[j] = int.Parse(str[j + 2]);
            }
        }

        g[1].d = 0;
        var queue = new Queue<int>();
        queue.Enqueue(1);

        while(queue.Count > 0) {
            int id = queue.Dequeue();

            for(int i = 0; i < g[id].edge; i++) {
                if(g[g[id].a[i]].d == -1) {
                    g[g[id].a[i]].d = g[id].d + 1;
                    queue.Enqueue(g[id].a[i]);
                }
            }
        }

        for(int i = 1; i <= n; i++) {
            Console.WriteLine(i + " " + g[i].d);
        }

    }
}



Measured memory_bytes: 18388
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[31];
  for(int i=1;i<31;i++)
    a[i]=i;
  vector<int> flag;
  for(int i=0;i<28;i++){
    int n;
    cin>>n;
    flag.push_back(n);
  }
  for(int i=1;i<=30;i++){
    int flag2=0;
    for(int j=0;j<28;j++){
      if(a[i]==flag[j]){
	flag2=1;
	break;
      }
    }
    if(flag2==0)
      cout<<a[i]<<endl;
  }
  return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N;
    cin >> N;
    VI V(N);
    VI A(N/2 + 1, 0);
    REP(i, N) {
        cin >> V[i];
        A[V[i]/2]++;
    }
    int ans = 0;
    if (N % 2 == 0) {
        REP(i, N/2) {
            if (A[i] != 2) {
                cout << "0\n";
                return 0;
            }
        }

    } else {
        if (A[0] != 1) {
            cout << ans << '\n';
            return 0;
        }
        FOR(i, 1, N/2 - 1) {
            if (A[i] != 2) {
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    int k = N / 2;
    ans = 1;
    REP(i, k) {
        ans = (ans * 2) % MOD;
    }
    cout << ans << endl;


}

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

int main(){
	int n;
	int a[21];
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	
	int count=0;
	
	for(int i=2;i<=n-1;i++)
	{
		if(a[i]>a[i-1] && a[i]<a[i+1] || a[i]<a[i-1] && a[i]>a[i+1])
			count++;
	}
	
	cout<<count;
	
	return 0;
}

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

int main()
{
    int n,k,q,t;
    cin >> n >> k >> q;
    vector<int> player(n);

    for(int i = 0; i < q; ++i)
    {
        cin >> t;
        player[t-1] += 1;
    }

    for(int i = 0; i < n; ++i)
    {
        if(k - q + player[i] > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000007;
using ll = long long;
int main(){
    int a,b;
    cin>>a>>b;
    if (b%a==0){
        cout<<a+b<<endl;
    }
    else{
        cout<<b-a<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int main(){
  //std::ifstream in("test.txt");
  //  std::cin.rdbuf(in.rdbuf());
  int n;
  string inp;
  int set[5]={5,12,17,24,31};
  while(1){
    cin >> n;
    if(n==0)return 0;

    //int list[n];
    int shori[n];
    
    int size;
    int ans=0;
    //  int num=0;
    for(int i=0;i<n;i++){
      cin >> inp;
      if(ans==-1)continue;
      size=inp.size();
      shori[i]=0;
      //cout << list[i] << endl;
      for(int j=0;j<=i;j++){
	if(shori[j]==-1)continue;
       
        for(int l=0;l<5;l++){
	  if(shori[j]<set[l]){
	    if(size<=set[l]-shori[j]){
	      shori[j]+=size;
	      break;
	    }else{
	      shori[j]=-1;
	      break;
	    }
	  }
	}
	if(shori[j]==set[4]){
	  cout << j+1 << endl;
	  ans=-1;
	  break;
	}
      }
      
   
    }
 
  }
      
}

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

int main() {
    int N,size;
  	string s;
   	
  	cin >> N;
  	cin >> s;
  
  	size = s.length();
    /*cout << size << endl;*/
  
  	if(size <= N){
      cout << s << endl;
    }else{
      cout << s.substr(0, N) + "..." << endl;
    }
   
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <cstdlib> 
using namespace std;
 
int main() {
  string str;
  cin >> str;
  int ap,zp;
  ap = -1;
  zp = -1;
 
  for(int i = 0; i < str.size(); i++){
   if(str.at(i) == 'A'){
       ap = i;
       break;
    }
  }
    
  for(int i = 0; i < str.size(); i++){
   if(str.at(i) == 'Z'){
       zp = i;
    }
  }
   cout << zp - ap + 1 << endl;  
}

Measured memory_bytes: 640
(N, M), As = readlines.map{|l| l.split.map(&:to_i)}

puts As.inject([0]){|r, a| r << r.last + a}.group_by{|x| x % M}.values.map(&:size).select{|n| n > 1}.map{|n| n*(n - 1)/2}.inject(:+) || 0

Measured memory_bytes: 17156