akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
using namespace std;
int main() {
  char a[7];
  scanf("%s",a);
  if (a[0] == 'S') {
    printf("Cloudy");
  } else if (a[0] == 'C') {
    printf("Rainy");
  } else {
    printf("Sunny");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int i;
	for(i=0;i<=8;i++)
	{
		if(pow(2,i)>n)
		{
			break;
		}
	}
	i--;
	cout << pow(2,i) << endl;
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 888
def main():
    import sys
    input = sys.stdin.readline

    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))

    ################
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意)，根の場合は"-(要素数）"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        members(x):要素xが属するグループに属する要素をリストで返す
        roots:全ての根の要素を返す
        group_count():グループの数を返す
        all_group_members():{根要素：[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            arr=[]
            for r in range(self.roots()):
                arr.append(set(self.members(r)))
            return arr

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
################
    mod=10**9+7
    N,K,L=MI()
    uf1 = UnionFind(N)
    uf2 = UnionFind(N)
    ans=[0]*N

    for i in range(K):
        p,q=MI()
        p-=1
        q-=1
        uf1.union(p,q)
        
    for i in range(L):
        p,q=MI()
        p-=1
        q-=1
        uf2.union(p,q)
        
    from collections import defaultdict
    dd = defaultdict(int)
    
    for i in range(N):
        a=uf1.find(i)
        b=uf2.find(i)
        dd[(a,b)]+=1
        
    for i in range(N):
        a=uf1.find(i)
        b=uf2.find(i)
        ans[i]=dd[(a,b)]
        
    print(' '.join(map(str, ans)))
    
    
    
        
        
    


main()


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int r = c - a;
	int u = d - b;
	Rep(i, r) cout << 'R';
	Rep(i, u) cout << 'U';
	Rep(i, r) cout << 'L';
	Rep(i, u) cout << 'D';
	cout << 'D';
	Rep(i, r + 1) cout << 'R';
	Rep(i, u + 1) cout << 'U';
	cout << 'L';
	cout << 'U';
	Rep(i, r + 1) cout << 'L';
	Rep(i, u + 1) cout << 'D';
	cout << 'R';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
signed main(){
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
  return 0;
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,X; cin >> N >> X;
	vector<int> S(N);
	repp(i,0,N) cin >> S[i];
	sort(S.begin(),S.end());
	vector<LL> dp(X+1,0);
	repp(i,0,X+1) dp[i] = i%S[0];
	const LL mod = 1e9+7;
	repp(i,1,N){
		vector<LL> nx(X+1);
		repp(k,0,X+1) nx[k] = (dp[k]*i+dp[k%S[i]])%mod;
		swap(dp,nx);
	}
	cout << dp[X] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
typedef long long ll;

using namespace std;

int main()
{
	ll mod = 1e9 + 7;
	int N, M;
	cin >> N >> M;
	vector<ll> p(N + 1, -1);
	rep(i, M)
	{
		int tmp;
		cin >> tmp;
		p[tmp] = 0;
	}
	rep(i, N + 1)
	{
		if (i == 0)
		{
			p[i] = 1;
		}
		else if (i == 1)
		{
			if(p[i] < 0) p[i] = 1;
		}
		else 
		{
			if (p[i] < 0) p[i] = p[i - 1] + p[i - 2];
			if (p[i] > mod) p[i] %= mod;
		}
	}
	ll ans = p[N] % mod;
	co(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,a[N][N];
int color[N],d[N],f[N],tt;
void dfs(void);
void visit(int);

int main(){
    int i,j,k,l,m;
    
    scanf("%d",&n);
    for(i=1; i<=n; i++){
        for(j=1; j<=n; j++) a[N][N] = 0;
    }
    
    for(i=1; i<=n; i++){
        scanf("%d%d", &k,&l);
        for(j=0; j<l; j++){
            scanf("%d",&m);
            a[k][m] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

void dfs(){
    int u;
    for(u=1; u<=n; u++){
        color[u] = WHITE;
    }
    tt = 0;
    
    for(u=1; u<=n; u++){
        if(color[u] == WHITE) visit(u);
    }
    for(u=1; u<=n; u++){
        printf("%d %d %d\n",u,d[u],f[u]);
    }
}

void visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v=1; v<=n; v++){
        if(a[u][v] == 0) continue;
        if(color[v] == WHITE){
            visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

Measured memory_bytes: 636
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

#define Pi 3.1415926535897932384626


int main()
{
	ll n, ans = 1,before;
	string s;
	bool flag = true;

	cin >> n;

	vecll a(n);

	forll(i, 0, n)
		cin >> a[i];

	sort(a.begin(), a.end());

	forll(i, 0, n)
	{
		before = ans;

		ans *= a[i];

		if (ans > 1000000000000000000 || ans < before)
		{
			if (a[i] == 0)
				ans = 0;
			else
				ans = -1;

			break;
		}
	}

	cout << ans << "\n";
}


Measured memory_bytes: 4052
<?php
function check($n, $x) {
  if ($n > ($x - 3)) $n = $x - 3;

  $ret = 0;
  for ($i = $n; $i > 2; $i--) {
    if (($i * 3 - 3) < $x) break;

    for ($j = $i-1; $j > 1; $j--) {
      if (($i + $j * 2 - 1) < $x) break;

      for ($k = $j-1; $k > 0; $k--) {
        $sum = $i + $j + $k;
        if ($sum == $x) {
          $ret++;
        } elseif ($sum < $x) {
          break;
        }
      }
    }
  }
  return $ret;
}

$input = trim(fgets(STDIN));
List($n, $x) = explode(" ", $input);

while ($n != 0 or $x != 0) {
  $ans = check($n, $x);
  echo $ans . PHP_EOL;

  $input = trim(fgets(STDIN));
  List($n, $x) = explode(" ", $input);
}

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

#define TC int n;scanf("%d",&n);while(n--)
#define lld long long int

int main()
{
    int x=0,y=0;
    vector<int>v;
    TC
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    y=(v.size()/2);
    cout<<v[y]-v[y-1];
    return 0;
}


Measured memory_bytes: 892
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <int,bool> cnt;
    int a,b,c; cin>>a>>b>>c; 
    int i=a;
    while (true){
        if (i%b==c) break;
        if (cnt[i%b] and i%b != c) cout << "NO"<< endl,exit(0);
        cnt[i%b]=true;
        i += a;
    }

    cout << "YES" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n, k; cin >> n >> k;
  if(n > k) {
    while(n * 2 >= k) {
      if(n > k) {
        n %= k;
      }
      else {
        n = k % n;
      }
    }
    cout << n << endl;
  }
  else {
    if(n * 2 >= k) {
      cout << k - n << endl;
    }
    else {
      cout << n << endl;
    }
  }
}

Measured memory_bytes: 3612
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import itertools
import math
n,m,x = ma()
cost = [0]*n
A = []
for i in range(n):
    co = list(ma())
    cost[i] = co[0]
    A.append(co[1:])
ans = 10**9
for i in range(2**n):
    tmp = 0
    cnt = [0]*m
    f = True
    for j in range(n):
        if i>>j &1:##book j buy
            tmp+=cost[j]
            for k in range(m):
                cnt[k] +=A[j][k]
    for c in cnt:
        if c<x:
            f =False
    if f:ans = min(ans,tmp)
if ans==10**9:
    print(-1)
else:print(ans)


Measured memory_bytes: 9436
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int INF=INT_MAX;

int main(){
    ll n;
    cin>>n;
    vll a(n),dp(n+1,0);//dp[i]はiが書かれたボールの数
    REP(i,n){
        cin>>a[i];
        dp[a[i]]++;
    }
    ll x;
    REP(i,n+1){
        if(dp[i]!=0){
           x+=(dp[i]-1)*dp[i]/2; 
        }
    }
    REP(i,n){
        cout<<x-dp[a[i]]+1<<endl;
    }
}

Measured memory_bytes: 5760
#include <algorithm>
#include <utility>
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
inline ll quick_pow(ll a, int n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
int arr[105];
std::pair<ll, ll> work(int l, int r, int h)
{
	if (l > r)
		return {1, (MOD + 1) / 2};
	int pos = std::min_element(arr + l, arr + r + 1) - arr;
	ll val = quick_pow(2, arr[pos] - h);
	if (l == r)
		return {val, val};
	auto x = work(l, pos - 1, arr[pos]), y = work(pos + 1, r, arr[pos]);
	return {val * x.first % MOD * y.first % MOD,
			4 * x.second % MOD * y.second % MOD + (val - 1) * x.first % MOD * y.first % MOD};
}
int main()
{
	// freopen("AGC026-D.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	printf("%lld\n", work(0, n - 1, 1).second * 2 % MOD);
	return 0;
}


Measured memory_bytes: 128
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);
        int n = nextInt(sc);

        int result = 1;

        for (int i = 2;i <= n; i++) {
            int num = i * i;

            if (num == n) {
                result = num;
                break;
            } else if (num > n) {
                break;
            } else {
                result = num;
            }
        }

        out(result);
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}

Measured memory_bytes: 23380
def main():
  N = int(input())
  S = input()
  R = 0
  G = 0
  B = 0
  nsum = 0
  for s in S:
      if s == "R":
          R += 1
      elif s == "G":
          G += 1
      else:
          B += 1
  count = 0
  for i in range(N):
      for k in range(i+1,N):
          if not S[i] == S[k]:
              if 2*k - i <= N - 1:
                  if S[i] != S[2*k - i] and S[k] != S[2*k - i]:
                      count += 1
  print(R*G*B - count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 73752
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD 1000000007
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    ll n;
    cin>>n;
    ll c[200005];
    ll cur[200005] = {};
    map< ll, vll > m;
    ll i;
    FOR0(i, n)
        cin>>c[i];
    FORD(i, n-1, 0)
    {
        m[c[i]].push_back(i);
    }
    map< ll, vll >::iterator it;
    FOR0(i, n)
    {
        if(i!=0)
        {
            cur[i] += cur[i-1];
            cur[i] %= MOD;
        }
        it = m.find(c[i]);
        if(it->ss.size()==1)
        {
            m.erase(c[i]);
        }
        else
        {
            it->ss.pop_back();
            int cp;
            cp = it->ss[it->ss.size()-1];
            if((cp-i)==1) continue;
            cur[cp] += (((cur[i]+1)*2) -1 );
            cur[cp] %= MOD;
            cur[cp] -= cur[i];
            cur[cp] += MOD;
            cur[cp] %= MOD;
        }
    }
    ll ans = cur[n-1] + 1;
    ans %= MOD;
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 25216
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var results []int64
	for {
		a := nextInt(sc)
		op := nextString(sc)
		b := nextInt(sc)

		if op == "?" {
			break
		}
		results = append(results, solveLine(a, b, op))
	}

	for _, v := range results {
		fmt.Println(v)
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func solveLine(a, b int64, op string) int64 {
	switch op {
	case "+":
		return a + b
	case "-":
		return a - b
	case "*":
		return a * b
	case "/":
		return a / b
	}
	return -1
}



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

int main()
{
    std::uint64_t A;
    std::string Bs;

    std::cin >> A >> Bs;

    const std::uint64_t B100 = Bs.at(0) - '0';
    const std::uint64_t B010 = Bs.at(2) - '0';
    const std::uint64_t B001 = Bs.at(3) - '0';

    const std::uint64_t B = B100 * 100 + B010 * 10 + B001;

    const auto AxB = A * B;
    if(AxB < 1000)
    {
        std::cout << 0 << std::endl;
        return 0;
    }

    std::string ans = std::to_string(A * B);
    ans.pop_back();
    ans.pop_back();
    std::cout << ans << std::endl;

    return 0;
}


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

int main() {
	int N, x, y, b, p;
	int max = 0;
	int min = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> x >> y >> b >> p;
		max = x*b + y*p;

		if (b < 5) { b = 5; }
		if (p < 2) { p = 2; }

		min= (x*b + y*p)*0.8;

		if (max < min) {
			cout << max << endl;
		}
		else {
			cout << min << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3112
function Main(input){
  var N = input.split("\n")[0].split(" ")[0];
  var T = input.split("\n")[0].split(" ")[1];
  N = parseInt(N,10);
  T = parseInt(T,10);
  var t =input.split("\n")[1].split(" ");

  var jud;
  var count = 0;
  for(i=0;i<N;i++){
    t[i] = parseInt(t[i],10);
    if(i===0){
      jud = t[i] >= T;
    }else{
      jud = (t[i]-t[i-1]) >= T;
    }
    if(jud===true){
      count += T;
    }else{
      if(i===0){
        count += t[i];
      }else{
        count += (t[i]-t[i-1]);
      }
    }
  }
  count += T;
  console.log(count);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));




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

int main(){
int N;
int A[1000];
double all=0;
double ten=1;
int x;
int i=0;
int total;

cin >> N;
while(1){
  if(N == 0){
    break;
  }

x = N%(-2);
if(x==(-1))x=1;
A[i] = x;
i++;
N -= x;
N = N/(-2);
}

if(i==0){cout << "0";}
else{
total = i-1;
for(int k = total; k>=0; k--)
cout << A[k] ;
}
cout << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
vector<int>rec[maxn];
int ans[maxn];
int len[maxn];
int shendu[maxn];
typedef struct
{
    int id,d,color;
}qq;
qq a[maxn];
queue<int>po;
void bfs(int name,int col,int distance)
{
    shendu[name]=0;
    if(len[name]<distance)
    {
        po.push(name);
        if(ans[name]==0)
        {
            ans[name]=col;
        }
        len[name]=distance;
    }
    while(!po.empty())
    {
        int temp=po.front();
        po.pop();
        for(int i=0; i<rec[temp].size(); i++)
        {
            int zhi=rec[temp][i];

            if(len[zhi]<distance-shendu[temp]-1)
            {
                shendu[zhi]=shendu[temp]+1;
                po.push(zhi);
                len[zhi]=distance-shendu[zhi];
                if(ans[zhi]==0)
                {
                    ans[zhi]=col;
                }
            }
        }

    }
}
int n,m;
void init()
{
    for(int i=0;i<=n;i++)
    {
        len[i]=-1;
    }
}
int main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    cin>>n>>m;
    init();
    int le,ri;
    for(int i=0; i<m; i++)
    {
        scanf("%d%d",&le,&ri);
        rec[le].push_back(ri);
        rec[ri].push_back(le);
    }
    int q;
    cin>>q;
//    for(int i=0;i<rec[6].size();i++)
//    {
//        printf("*%d\n",rec[6][i]);
//    }
    for(int i=0; i<q; i++)
    {
        scanf("%d%d%d",&a[i].id,&a[i].d,&a[i].color);
    }
    for(int i=q-1; i>=0; i--)
    {
        bfs(a[i].id,a[i].color,a[i].d);
    }
    for(int i=1; i<=n; i++)
    {
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 13048
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] solution = new int[totalVertex];
		for(int i = 0; i < totalVertex; i++)
		{
			solution[i] = Integer.MAX_VALUE;
		}
		
		solution[s] = 0;
		ifSettled[s] = true;
		
		int settle = s;
		boolean check = true;
		LinkedList<Integer> next;
		
		while(check)
		{
			next = getUnsettledNeighbors(settle);
			for(int i: next)
			{
				if(solution[i] > solution[settle] + getWeight(settle, i))
				{
					solution[i] = solution[settle] + getWeight(settle, i);
				}
			}
			
			settle = getUnsettledNearest(solution);
			ifSettled[settle] = true;
			check = false;
			for(int i = 0; i < totalVertex; i++)
			{
				if(ifSettled[i] == false)
				{
					check = true;
				}
			}
		}
		
		return solution;
	}
}

public class Main{
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


Measured memory_bytes: 40848
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll H, W, K;
ll count(vector<vector<char>> grid, ll index) {
  // cout << "IND" << index << endl;
  for (ll i = 0; i < H + W; ++i) {
    if ((index & (1 << i)) != 0) {
      // cout << i << " ";
      if (i < H) {
        for (ll j = 0; j < W; ++j) {
          grid.at(i).at(j) = '*';
        }
      }
      else {
        for (ll j = 0; j < H; ++j) {
          grid.at(j).at(i - H) = '*';
        }
      }
    }
  }
  // cout << "\n";
  ll res = 0;
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W; ++j) {
      if (grid.at(i).at(j) == '#') {
        res += 1;
      }
    }
  }
  // for (ll i = 0; i < H; ++i) {
  //   for (ll j = 0; j < W; ++j) {
  //     cout << grid.at(i).at(j);
  //   }
  //   cout << "\n";
  // }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> H >> W >> K;
  vector<vector<char>> grid(H, vector<char>(W));
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W; ++j) {
      cin >> grid.at(i).at(j);
    }
  }
  ll ans = 0;
  for (ll i = 0; i < (1 << H + W); ++i) {
    ll temp = count(grid, i);
    // cout << temp << "\n";
    if (temp == K) {
      ans += 1;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3652
using System;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var h1 = a[0] * 60 + a[1];
            var h2 = a[2] * 60 + a[3];
            var r = h2 - h1 - a[4];
            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 28092
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

/*
A B C
B+C C+A A+B
C+2A+B A+2B+C
*/

ll A, B, C, K;

int main()
{
  scanf( "%lld%lld%lld%lld", &A, &B, &C, &K );
  printf( "%lld\n", K%2?B-A:A-B );
  
  return 0;
}

Measured memory_bytes: 128
from bisect import bisect_left


N, *L = map(int, open(0).read().split())
L.sort()

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        ans += bisect_left(L, a + b, lo=j + 1) - (j + 1)
print(ans)


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

int main() {
  long A,B,ans=1,flag=0;
  cin >> A >> B;
  if(A<B)  swap(A, B);
  long x = A * B;
  long r;
  r = A % B;
  while(r!=0){
      A = B;
      B = r;
      r = A % B;
  }
  cout << x / B;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  string s;
  int count1=0,count2=0;
  cin>>s;
  for(int i=0;i<s.length();i++)
  {
    if(i%2==0)
    {
      if(s[i]=='R'||s[i]=='U'||s[i]=='D')
      {
        count1=count1+1;
      }
    }
    if(i%2==1)
    {
      if(s[i]=='L'||s[i]=='U'||s[i]=='D')
      {
        count2=count2+1;
      }
    }
  }
    if((count1+count2)==s.length())
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
  return 0;
}

Measured memory_bytes: 256
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
t=input().rstrip()
print("Yes" if t in s+s else "No")


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

struct Bug {long long a, b;};

bool ok(const vector<Bug>& bug, int n) {
  if(n == 0) return true;
  if(n == 1) return any_of(begin(bug), end(bug), [](Bug b){return b.a <= b.b;});
  priority_queue<Bug, vector<Bug>, function<bool(Bug, Bug)>> a(begin(bug) + 1, end(bug), [](Bug lhs, Bug rhs){return lhs.a != rhs.a ? lhs.a > rhs.a : lhs.b > rhs.b;});
  priority_queue<Bug, vector<Bug>, function<bool(Bug, Bug)>> b([](Bug lhs, Bug rhs){return lhs.b != rhs.b ? lhs.b > rhs.b : lhs.a > rhs.a;});
  b.push(bug.front());
  long long sum = bug.front().a;
  while(!a.empty()) {
    b.push(a.top());
    sum += a.top().a;
    a.pop();
    if(b.size() < n) continue;
    if(sum <= b.top().b * n) return true;
    sum -= b.top().a;
    b.pop();
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<Bug> bug(N);
  for(auto& i: bug) cin >> i.a >> i.b;

  sort(begin(bug), end(bug), [](Bug lhs, Bug rhs){return lhs.b != rhs.b ? lhs.b < rhs.b : lhs.a < rhs.a;});

  int low = 0, high = N + 1;
  while(1 < high - low) {
    int middle = (low + high) >> 1;
    (ok(bug, middle) ? low : high) = middle;
  }
  cout << low << endl;
}

Measured memory_bytes: 24712
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var intArray = IO.ReadIntArray();
			var price = -1;
			for(var iPrice = 1 ; iPrice <= 10000 ; ++ iPrice)
			{
				var a = (int)(iPrice * 0.08);
				var b = (int)(iPrice * 0.1);
				if(a > intArray[0] || b > intArray[1]) { break; }

				if(a == intArray[0] && b == intArray[1])
				{
					price = iPrice;
					break;
				}
			}
			IO.Write(price);
		}
	}

	public static class IO
	{
		public static string   Read()								 { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')		 { return Read().Split(iSplitter); }
		public static int	   ReadInt()							 { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()							 { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static double   ReadDouble()							 { return double.Parse(Read()); }
		public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()						 { return Read().ToCharArray(); }

		public static void Write(string iValue)									   { Console.WriteLine(iValue); }
		public static void Write(int iValue)									   { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue , string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord , iValue)); }
		public static void Write(long iValue)									   { Console.WriteLine(iValue); }
		public static void Write(double iValue)									   { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)								   { Console.WriteLine(iValue); }
		public static void Write(bool iValue)									   { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}
		public static long CombinationNum(int iLeftNumber , int iRightNumber)
		{
			if(iRightNumber == 0) { return 1; }
			if(iLeftNumber == 0)  { return 0; }
			return iLeftNumber * CombinationNum(iLeftNumber - 1 , iRightNumber - 1) / iRightNumber;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


Measured memory_bytes: 13268
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] T = new int[N+1];
        int[] X = new int[N+1];
        int[] Y = new int[N+1];
        T[0] = X[0] = Y[0] = 0;
        boolean yes = true;
        for (int i = 1; i <= N; i++) {
            T[i] = sc.nextInt();
            X[i] = sc.nextInt();
            Y[i] = sc.nextInt();
            int d = Math.abs(X[i] - X[i-1]) + Math.abs(Y[i] - Y[i-1]);
            int dt = T[i] - T[i-1];
            if (d > dt || d%2 != dt%2) {
                yes = false;
                break;
            }
        }
        System.out.println(yes ? "Yes" : "No");
    }
}


Measured memory_bytes: 88200
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 101;
int n, m, a[N][N];

struct BipartiteMatcher {
	vector<vector<int>> G;
	vector<int> L, R, Viz;
 
	BipartiteMatcher(int n, int m) {
		G.resize(n);
		L.resize(n, -1);
		R.resize(m, -1);
		Viz.resize(n);
	}
 
	void AddEdge(int a, int b) {
		G[a].push_back(b);
	}
 
	bool Match(int node) {
		if(Viz[node]) 
			return false;
		Viz[node] = true;
	
		for(auto vec : G[node]) {
			if(R[vec] == -1 || Match(R[vec])) {
				L[node] = vec;
				R[vec] = node;
				return true;
			}
		}
 
		return false;
	}
	void Solve() {
		bool ok = true;
		while(ok) {
			ok = false;
			fill(Viz.begin(), Viz.end(), 0);
			for(int i = 0; i < L.size(); ++i)
				if(L[i] == -1)
					ok |= Match(i);
		}
	}
};
 

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

	cin >> n >> m;
	for(int i= 0; i < n; i++)
		for(int j = 0; j < m; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}

	for(int j = 0; j < m; j++) {
		BipartiteMatcher bm(n, n);
		dbg(j);
		for(int i = 0; i < n; i++)
			for(int k = j; k < m; k++)
				bm.AddEdge(i, a[i][k] / m);
		// dbg_ok;
		bm.Solve();
		// dbg_ok;
		for(int i = 0; i < n; i++) {
			int sch = bm.L[i];
			// dbg(i, sch);
			for(int k = j; k < m; k++)
				if(a[i][k] / m == sch) {
					swap(a[i][k], a[i][j]);
					break;
				}
		}
	}

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cout << a[i][j] + 1 << " \n"[j == m - 1];

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++) 
			for(int k = i; k < n; k++)
				if(a[k][j] / m == i)
					swap(a[i][j], a[k][j]);
		

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cout << a[i][j] + 1 << " \n"[j == m - 1];
}	


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

int main (){
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  vector<int> counts(n);
  for (int i = 1; i < n; ++i) {
    counts[i] = counts[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C')
      ++counts[i];
  }
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin>>l>>r;
    cout<<counts[r - 1] - counts[l - 1]<<'\n';
  }
  return 0;
}

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

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

    vector<int> B(M);
    rep(i, M) cin >> B.at(i);

    vector<vector<int>> A(N, vector<int>(M));
    rep(i, N) rep(j, M) cin >> A.at(i).at(j);

    int ans = 0;

    rep(i, N)
    {
        int tmp = C;
        rep(j, M)
        {
            tmp += A.at(i).at(j) * B.at(j);
        }

        if (tmp > 0)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int n, m;
int ab[8][8];

int dfs(int v, bitset<8> visited){
    if(visited.count() == n) return 1;
    int res = 0;
    rep(i, n){
        if(!ab[v][i] or visited[i]) continue;
        visited.set(i);
        res += dfs(i, visited);
        visited.reset(i);
    }
    return res;
}

int main(){
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b; --a; --b;
        ab[a][b] = ab[b][a] = true;
    }

    cout << dfs(0, bitset<8>("00000001")) << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
// #define int ll
 
bool test = 1;

//............................
#define MAX 300000
signed main(){
  int i,j,k,l;
  while(1) {
	int n,m;
	set< pair<int,int> > s;
	cin >> n;
	if(n == 0) break;
	rep(i,n) {
	  int x,y;
	  cin >> x >> y;
	  s.insert(make_pair(x,y));
	}
	cin >> m;
	int nowx = 10;
	int nowy = 10;
	rep(i,m) {
	  char d;
	  int l;
	  cin >> d >> l;
	  int dir;
	  switch(d) {
	  case 'N' : dir = 0; break;
	  case 'E' : dir = 1; break;
	  case 'S' : dir = 2; break;
	  case 'W' : dir = 3; break;
	  }
	  rep(j,l) {
		nowx += dx[dir];
		nowy += dy[dir];
	    s.erase(make_pair(nowx,nowy));
	  }
	}
	if(s.size() == 0) puts("Yes");
	else puts("No");
  }
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main (){
    int a,b;
    cin>>a>>b;
    if(a>b){
        int t=a;
        a=b;
        b=t;
    }
    
    if(a==1 and b==2){
        cout<<3<<"\n";
    }
    if(a==2 and b==3){
        cout<<1<<"\n";
    }
    if(a==1 and b==3){
        cout<<2<<"\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    int n;
    cin>>n;
    int i,a[n],ans=0;
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i+=2)
    {
        if(a[i]%2)
        ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){

        long long n,p=0,i,j,k;
        cin>>n;
        long long a[n];
        for(i=0;i<n;i++)
        cin>>a[i];
        for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                for(k=j+1;k<n;k++){
                    if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]){
                        if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j])
                        p++;
                    }
                }
            }
        }cout<<p<<endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int        int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,a[20][20],ans=0;
int cost[(1<<17)];
int dp[(1<<17)];
void solve(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    cost[0]=0;
    for(int i=1;i<(1<<n);i++){
        int last = ffs(i)-1;
        int mask = i&(i-1);
        int ans = 0;
        for(int j=0;j<n;j++){
            if((mask>>j)&1){
                ans+=a[last][j];
            }
        }
        cost[i]=ans+cost[mask];
    }
    dp[0]=0;
    for(int mask=1;mask<(1<<n);mask++){
        dp[mask] = cost[mask];
        for(int submask = mask;submask; submask=(submask-1)&mask){
            dp[mask] = max(dp[mask],dp[submask]+cost[mask^submask]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,x;
    cin >> n >> x;
    ll a[n];
    rp(i,n) cin >> a[i];
    ll ans = 0;
    rp(i,n-1){
        if(a[i]+a[i+1] > x) {
            ans += a[i] + a[i+1] -x;
            a[i+1] = max(0LL,x - a[i]);
        }
    }
    cout << ans<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

void solve() {
    int n; cin >> n;
    int arr[4] = {0};
    string inputan;
    for (int i = 0; i < n; i++) {
        cin >> inputan;
        if (inputan == "AC") {
            arr[0]++;
        } else if (inputan == "WA") {
            arr[1]++;
        } else if (inputan == "TLE") {
            arr[2]++;
        } else {
            arr[3]++;
        }
    }
    cout << "AC x " << arr[0] << endl;
    cout << "WA x " << arr[1] << endl;
    cout << "TLE x " << arr[2] << endl;
    cout << "RE x " << arr[3] << endl;     
}

int main() {
    solve();
}

Measured memory_bytes: 3620
#include <cstdio>

int n;
char s[20];

void dfs(int x, char now) {
    if (x == n - 1) {
        printf("%s\n", s);
        return;
    }
    for (char c = 'a'; c <= now; ++c) {
        s[x + 1] = c;
        dfs(x + 1, now);
    }
    s[x + 1] = now + 1;
    dfs(x + 1, now + 1);
}

int main() {
    scanf("%d", &n);
    s[0] = 'a';
    dfs(0, 'a');
    return 0;
}


Measured memory_bytes: 1408
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int n,m;
  cin>>n>>m;
  vector <int> a(m),b(m),c(m);
  vector <vector <int> > dist = vector <vector <int> > (n, vector <int> (n,0));
  
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--; b[i]--;
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j) dist[i][j]=100000000; 
    }
  }

  for(int i=0;i<m;i++){
    dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
    dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
  }

  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }

  int ans=m;
  for(int i=0;i<m;i++){
    bool flag=false;
    for(int j=0;j<n;j++){
      if(dist[j][a[i]]+c[i]==dist[j][b[i]]) flag=true;
    }
    if(flag) ans--;
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
 
object Main extends App {
 
 
  def exec(w:String):Unit =  {
    val len = w.length
 
    def shuffle(i:Int, cnt:Int):String =
      if(i == 0) (w drop (cnt%len))+(w take (cnt%len)) else { val m = readInt;shuffle(i-1, cnt+m) }
 
    if(w=="-") return else { val n = readInt;println(shuffle(n,0));exec(readLine) }
 
  }
  exec(readLine)
}

Measured memory_bytes: 43720