akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int i, j, k;
	int H, W;
	int num_flag;
	cin >> H >> W;

	char a[H][W + 1];
	char dummy[W + 1];
	int lines = 0;

	for (i = 0; i < W; i++) 
		dummy[i] = '.';

	dummy[W] = '\0';
	
	
	for (i = 0; i < H; i++) {
	    cin >> a[i];
		a[i][W] = '\0';

		if (strncmp(a[i], dummy, W + 1) == 0) {
			for (j = 0; j < W + 1; j++) 
				a[i][j] = '\0';
			i--;
			lines++;
		}
	}

	char result[H - lines][W + 1];
	int result_index = 0;

	for (i = 0; i < W + 1; i++) {
		num_flag = 0;
		for (j = 0; j < H - lines; j++) {
			if (a[j][i] == '#') {
				num_flag = 1;
				break;
			}
		}
		if (num_flag == 1) {
			for (j = 0; j < H - lines; j++) {
				result[j][result_index] = a[j][i];
			}
			result_index++;
		}
	}

	for (i = 0; i < H - lines; i++) {
		result[i][result_index] = '\0';
	}
				
	
    for (i = 0; i < H - lines; i++) {
		cout << result[i];
		cout << "\n";
	}
			

	return 0;
}


Measured memory_bytes: 256
n,b,c = map(int,input().split())
count = 0

for i in range(1,n+1): #startnumber, endnumber
  s = str(i)
  numSum = 0
  for si in range(len(s)):
    numSum += int(s[si]) 
  
  if numSum >= b and numSum <= c:
    count += i

print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cassert>
#include <set>
#include <map>
#include <bitset>
#include <unordered_set>
#include <string>
#include <cstring>
#include <cmath>
#include <numeric>
#define forn(x, n)             for (int x = 0; x < n; x++)
#define fore(x, a, b, c)       for (int x = a; x <= b; x += c)
#define forr(x, a)             for (int x = a; x >= 0; x--)
#define all(container)         (container).begin(), (container).end()
#define rall(container)        (container).rbegin(), (container).rend()
#define sz(container)          (int) container.size()
#define mp                     make_pair
#define fi                     first
#define se                     second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector< vector< int > > vvi;
typedef vector<bool> vb;
typedef vector<long long> vll;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define debug(...) 0
#endif

void read(int &a) {scanf("%d", &a);}
void read(ll &a) {scanf("%lld", &a);}
void read(char* a, string& s) {scanf("%s", a); s = string(a);}
void read(float &a) {scanf("%f", &a);}
void read(double &a) {scanf("%lf", &a);}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

void solve() {
    ll a, b, c, k;
    read(a), read(b), read(c), read(k);
    ll ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    if (k) k -= min(b, k);
    if (k) ans -= min(c, k);
    printf("%lld\n", ans);
}

int main(void) {
    int T = 1;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 3764
package main

import "fmt"

func main() {
	cMap := map[rune]int{}
	var s string
	fmt.Scan(&s)
	for _, c := range s {
		cMap[c]++
	}
	output := "Yes"
	for _, c := range cMap {
		if c&1 != 0 {
			output = "No"
			break
		}
	}
	fmt.Println(output)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void){
	int n,i,a,j;
	int de,syo,tem[4];
	while(1){
		scanf("%000d",&n);
		if(n==0000)
			break;
		int cnt=0,flg=0;
		while(n!=6174){
			for(i=0;i<4;i++){
				a=1;
				for(j=0;j<3-i;j++){
					a*=10;
				}
				tem[i]=n/a;
				n-=tem[i]*a;
			}
		/*	if(tem[0]==tem[1]==tem[2]==tem[3]){
				flg=1;
				printf("%d %d %d %d\n",tem[0],tem[1],tem[2],tem[3]);
				break;
			}
	*/		sort(tem,tem+4);
			a=1000;
			de=syo=0;
			for(i=0;i<4;i++){
				syo+=tem[i]*a;
				a/=10;
			}
			sort(tem,tem+4,greater<int>());
			a=1000;
			for(i=0;i<4;i++){
				de+=tem[i]*a;
				a/=10;
			}
			if(de==syo){
				flg=1;
				break;
			}
			cnt++;
		//	printf("a=%d %d\n",de,syo);
			n=de-syo;
		}
		if(flg==0){
			printf("%d\n",cnt);
		}
		else {
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1052
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

char s;

int main()
{
    scanf("%c", &s);
    if(s == 'S') printf("Cloudy\n");
    else if(s == 'C') printf("Rainy\n");
    else printf("Sunny\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

#define MAX_LEN 100

using namespace std;

int a[MAX_LEN];

void printArray(int *a, int len)
{
	for (int i = 0; i < len; i++)
	{
		printf("%d", a[i]);
		if (i != len - 1) printf(" ");
	}
	printf("\n");
}

void swap(int *a, int i, int j)
{
	int temp;
	temp = a[i];
	a[i] = a[j];
	a[j] = temp;
}

int main()
{
	int len;
	scanf("%d", &len);

	for (int i = 0; i < len; i++)
	{
		scanf("%d", &a[i]);
	}

	int count = 0;
	for (int i = 0; i < len - 1; i++)
	{
		int min = i;
		for (int j = i + 1; j < len; j++)
		{
			if (a[j] < a[min])min = j;
		}
		if (min != i)
		{
			count++;
			swap(a, i, min);
		}
	}
	printArray(a, len);
	printf("%d\n", count);
}


Measured memory_bytes: 3204
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        string S = "ACGT";
        string T = "TGCA";

        char A;
        cin >> A;
        for (int i = 0; i < 4; i++)
        {
                if (A==S[i])
                {
                        cout << T[i] << endl;
                }
        }
                return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


H,N = inpl()
AB  = []
for _ in range(N):
    a= inpl()
    AB.append(a)
dp = [[INF]*(H+1) for _ in range(N)]
dp[0][0] = 0
for i in range(N):
    for j in range(H+1):
        at = AB[i][0]
        cost = AB[i][1]
        dp[i][j] = min(dp[i][max(j-at,0)]+cost,dp[max(0,i-1)][j])

print(dp[N-1][H])


Measured memory_bytes: 292548
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, A, B; cin >> N >> A >> B;
  string S; cin >> S;
  int cntA = 0, cntB = 0;
  vector<bool> ans(N, false);
  REP(i, N){
    if(S[i] == 'a'){
      if(cntA + cntB < A+B){
        cntA++;
        ans[i] = true;
      }
    }else if(S[i] == 'b'){
      if(cntA + cntB < A+B && cntB < B){
        cntB++;
        ans[i] = true;
      }
    }
  }
  REP(i, N){
    if(ans[i]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 848
<?php
	$result = array();

	while(true) {
		$stdin = explode(" ", trim(fgets(STDIN)));
	
		if ($stdin[0] == 0 && $stdin[1] == 0) {
			break;
		}

		sort($stdin);
		$result[] = $stdin[0] . " " . $stdin[1];
	}

	foreach ($result as $val) {
		echo $val . PHP_EOL;
	}

Measured memory_bytes: 15512
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)





void solve(){
  int x,a;
  cin >> x >> a;
  if(x<a) cout << 0 << endl;
  else cout << 10 << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

mint com(ll x, ll y) {
	mint ret = 1;
	rep(i, y)ret*= x - i;
	rep(i, y)ret /= (i + 1);
	return ret;
}

mint h(ll x, ll y) {
	return com(x + y - 1, y-1);
}

mint ans(ll N) {
	if (N < 4) { return 0; }
	ll M = N - 5;

	mint ans = 0;
	
	rep(i,12){
		mint kumi = com(11, i);

		if ((M - i) % 2 != 0||M<i) { continue; }
		ll x = (M - i) / 2;

		mint now = h(x, 16) * kumi;
		ans += now;
	}

	return ans;


}


int main() {
	ll T;
	cin >> T;

	repn(t, T) {
		ll N;
		cin >> N;
		cout << ans(N) << endl;
	}

}

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

lli x, y;

int main(void){
	cin >> x >> y;
	lli d = y/x;
	lli t = 1;
	lli k = 0;
	while(t <= d){
		t*=2;
		k++;
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3640
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    while( {n=readInt;n} != 0 ) {
      val b = new ArrayBuffer[Array[Int]]
      for(i<-1 to n) {
        b += readLine.split(" ").map(_.toInt)
      }
      val limit = readLine.split(" ").map(_.toInt)
      val p = limit(0);val q = limit(1);val r = limit(2);val c = limit(3)
      val list = b.toArray.filter { i => i(1) <= p && i(2) <= q && i(3) <= r && i(1)*4 + i(2)*9 + i(3)*4 <= c }
      if(list.length == 0) println("NA")
      else list.foreach(i=>println(i(0)))
    }
  }
}

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

#define rep(i,j) for (int (i)=0;(i)<(int)(j);++(i))

int N, M;
int squ[21][21];

void init() {
    rep(i, 21) rep(j, 21) squ[i][j] = 0;
}

bool chk() {
    rep(i, 21) rep(j, 21) if (squ[i][j]) return false;
    return true;
}

int main() {
    while (cin >> N, N) {
        init();
        rep(i, N) {
            int x, y; cin >> x >> y;
            squ[x][y] = 1;
        }
        cin >> M;
        int posx = 10, posy = 10;
        rep(i, M) {
            char h; int v; bool ns = 0, ew = 0;
            cin >> h >> v;
            switch (h) {
                case 'N': ns = 1;
                case 'S':
                    rep(j, v) {
                        posy += (ns) ? 1 : -1;
                        squ[posx][posy] = 0;
                    }
                    break;
                case 'E': ew = 1;
                case 'W':
                    rep(j, v) {
                        posx += (ew) ? 1 : -1;
                        squ[posx][posy] = 0;
                    }
                    break;
            }
        }
        if (chk()) puts("Yes");
        else puts("No");
    }
}

Measured memory_bytes: 2944
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    map<ll,ll>mp;
    ll n;
    cin>>n;
    vector<ll>v;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        if(mp[x]==0)
        v.push_back(x);
        mp[x]++;
    }
    sort(v.begin(),v.end());
   // cout<<v.size();
    ll ans=0;
    for(int i=0;i<v.size();i++)
    {
        for(int j=0;j<v.size();j++)
        {
            for(int k=0;k<v.size();k++)
            {
                if(i!=j&&j!=k&&i!=k&&i<j&&j<k)
                {
                    if(v[i]+v[j]>v[k]&&v[i]+v[k]>v[j]&&v[j]+v[k]>v[i])
                    {
                        ans=ans+mp[v[i]]*mp[v[j]]*mp[v[k]];
                    }
                }
            }
        }
    }
    cout<<ans;}
    
    
    
    
    

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;




struct edge {
    int from, to;
    number cost;
    edge(int a, int b, number c) : from(a), to(b), cost(c) {}
};


using Edges = vector< edge >;

vector< number > bellman_ford(int s, int V, vi &prev, const Edges &edges) {
    vector< number > dist(V, INF);
    prev.assign(V, -2);
    dist[s] = 0;
    for (int i = 0; i < V; i++) {
        for (auto &e : edges) {
            if (dist[e.from] == INF) continue;
            if (dist[e.from] + e.cost < dist[e.to]) {
                dist[e.to] = dist[e.from] + e.cost;
                prev[e.to] = e.from;
                if (i == V - 1) dist[e.to] = - INF;
            }
        }
    }
    return dist;
}


int main() {
    int N, M; cin >> N >> M;
    Edges G;
    int a, b; ll c;
    rep(i, M) {
        cin >> a >> b >> c;
        a--, b--;
        G.pb(edge(a, b, -c));
    }
    vi prev(N);

    vll dist = bellman_ford(0, N, prev, G);

    bool can = false;
    int v = N - 1;
    rep(i, N) {
        v = prev[v];
        if(v == -2){
            can = true;
            break;
        }
    }

    if(can) cout << -dist[N - 1] << endl;
    else cout << "inf" << endl;

}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	t = 1;
	while(t--) {
	 cin >> n;
	 if(n == 7 || n == 5 || n == 3)
	  cout << "YES" << endl;
	 else
	  cout << "NO" << endl;
	}
	return 0;
}



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

signed main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    for(int i=0;i<n;i++)
    cin>>p[i];
    for(int i=0;i<n;i++)
    cin>>q[i];
    int count=0,i;
    vector<int> arr(n);
    for(i=0;i<n;i++)
    arr[i]=i+1;
    int a,b;
    do{
        count++;
        if(arr==p)
        a=count;
        if(arr==q)
        b=count;
    }while(next_permutation(arr.begin(),arr.end()));
    cout<<abs(a-b);
    //return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
	
int main(){
	int N, M;
  	cin >> N >> M;
	vector<pair<long long, long long>> stu(N);
	vector<pair<long long, long long>> CP(M);
	vector<long long> Point(N);
	rep(i, N) cin >> stu[i].first >> stu[i].second;
	rep(i, M) cin >> CP[i].first >> CP[i].second;
	rep(i, N){
		long long dis = 1e9;
		rep(j, M){
			long long th = abs(stu[i].first - CP[j].first) + abs(stu[i].second - CP[j].second);
			if(dis > th){
				dis = th;
				Point[i] = j + 1;
			}
		}
		cout << Point[i] << endl;
	}
}

Measured memory_bytes: 256
n = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in input( ).split( " " ) ]
t.sort( )

cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )//2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Measured memory_bytes: 21080
// https://atcoder.jp/contests/abc171/tasks/abc171_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int num = N;
    string ans = "";
    while (num > 0) {
        num--;
        ans += ('a' + num % 26);
        num /= 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
N, K = map(int, input().split())
ret = 0
ret2 = 0
for i in range(1, N+1):
    judge = (i % K) == 0
    if judge:
        ret += 1
    if K % 2 == 0:
        judge = (i % K) == K // 2
        if judge:
            ret2 += 1

print(ret**3+ret2**3)


Measured memory_bytes: 39024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

int w,n,ans[32];
pair<int,int> list[32];

int main(){	
	scanf("%d%d",&w,&n);
	rep(i,n){
		int a,b; scanf("%d,%d",&a,&b);
		list[i].first = a;
		list[i].second = b;
	}
	REP(i,1,w+1){
		int cur = i;
		rep(j,n){
			if( list[j].first == cur ){
				cur = list[j].second;
				//printf("i:%d , cur:%d\n",i,cur);
			}else if( list[j].second == cur ){
				cur = list[j].first;
				//printf("i:%d , cur:%d\n",i,cur);
			}
		}
		ans[cur] = i;
	}
	REP(i,1,w+1)printf("%d\n",ans[i]);
	
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

struct BIT {
  int n;
  vector<int> xs;
  BIT(int n) : n(n) {
    xs.resize(n+1);
  }
  void add(int i, int v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  int sum(int i) {
    int s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
};

int N;
int A[40000], B[40000], C[40000];
bool cmp(const P2 &a, const P2 &b) {
  if (a._1._1*b._1._2 == a._1._2*b._1._1) return a._2 < b._2;
  return a._1._1*b._1._2 < a._1._2*b._1._1;
}

BIT bit(40000);
vector<P2> ls;
int pos[40000];

long long f(double X) {
  vector< pair<double, int> > ps;
  rep(j, N) {
    int i = ls[j]._2;
    double y = (-X*(double)A[i] + (double)C[i]) / (double)B[i];
    ps.pb(make_pair(y, j));
  }
  sort(all(ps));
  rep(i, N) pos[ps[i]._2] = i;
  fill(all(bit.xs), 0);


  long long s = 0;
  rep(i, N) {
    s += i-bit.sum(pos[i]);
    bit.add(pos[i], 1);
  }
  //cout<<"f("<<X<<"): ";
  //rep(i, N) cout<<ps[i]._2<<",";cout<<"->"<<s<<"\n";
  return s;
}

double solve() {
  long long n = (1LL*N*(N-1))/2;
  ls.clear();
  rep(i, N) {
    int p = -A[i], q = B[i];
    if (q < 0) p = -p, q = -q;
    ls.pb(P2(P(p, q), i));
  }
  sort(all(ls), cmp);
  reverse(all(ls));

  double lo = -1e10, hi = 1e10;
  rep(_, 80) {
    double mid = (lo + hi) / 2;
    if (f(mid) >= (n+1)/2) hi = mid;
    else lo = mid;
  }
  return hi;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i] >> B[i] >> C[i];
  double x = solve();
  rep(i, N) swap(A[i], B[i]);
  double y = solve();
  cout << fixed << setprecision(20) << x << " " << y << "\n";
  return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll ans = 0;
  for (ll r = 0; r <= 3000; r++)
  {
    for (ll g = 0; g <= 3000 - r; g++)
    {
      if ((N - R * r - G * g) % B != 0)
        continue;
      ll b = (N - R * r - G * g) / B;
      if (0 <= b)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={0, 1, 0, -1};
int dy[]={-1, 0, 1, 0};





int maxg,ans,n,t[10][10];

int getxy(int g){
	int x=1,y;
	int plus = n-1;
//	cout << "n" << n << endl;
	for(int i = n-1;plus >= 1;x++){
//		cout << "g:" << g  <<  ", i;" << i << endl;
		plus--;
		if(g <= i){
	//		cout << "g:" << g  <<  ", i;" << i << endl;
			y = n - (i - g);
			break;
		}
		i += plus;
	}
//	cout << "g:" << g  << " ,x:" << x << ", y;" << y << endl;
	return (10*x+y);
}

void solve(int g,int l[10],int w[10]){
	int xy = getxy(g);
	int x = xy / 10,y = xy % 10;
//	cout << "xy:" << xy << endl;
//	cout << "x:" << x << ", y:" << y << endl;
	int eq = (n-1)/2;
	if(g == maxg){ //finish solve
		if(t[x][y] == 1){  //win
			if(w[x] == eq && l[y] == eq){
				ans++;
			}
		}else if(t[x][y] == -1){
			if(w[y] == eq && l[x] == eq){
				ans++;
			}
		}else{
			if(w[x]+1 == eq && l[y]+1 == eq){
				ans++;
			}
			if(w[y]+1 == eq && l[x]+1 == eq){
				ans++;
			}
		}
		return;
	}else if(t[x][y] == 0){
		if(w[x]+1 <= eq && l[y]+1 <= eq){
			w[x]++; l[y]++;
			solve(g+1,l,w);
			w[x]--; l[y]--;
		}
		if(w[y]+1 <= eq && l[x]+1 <= eq){
			w[y]++; l[x]++;
			solve(g+1,l,w);
			w[y]--; l[x]--;
		//	cout << "hey";
		}
	}else if(t[x][y] == -1){
		if(w[y] <= eq && l[x] <= eq){
			solve(g+1,l,w);
		}
	}else{
		if(w[x] <= eq && l[y] <= eq){
			solve(g+1,l,w);
		}
	}
	return;
}


int d[40][2];
int l[10],w[10],g;

int main(){
	int m;
	while(true){
		cin >> n;
		if(n == 0)break;
		cin >> m;
		maxg = 0;
		ans = 0;
		for(int i = n-1;i >= 1;i--){
			maxg += i;
		}
	//	cout << "gmax:" << maxg << endl;
		for(int i = 1;i <= n;i++){
			l[i] = 0;
			w[i] = 0;
			for(int j = 1;j <= n;j++){
				t[i][j] = 0;
			}
		}

		for(int i = 0;i < m;i++){
			int x,y;
			cin >> x >> y;
			w[x]++;
			l[y]++;
			t[x][y] = 1;
			t[y][x] = -1;
		}
		solve(1,l,w);
		cout << ans << endl;

	}

}


Measured memory_bytes: 3080
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
bool ans[500][500];
bool in[505][505];
int main(){
    int h,w;
    cin >> h >> w;
    rep(i,h){
        rep(j,w-1){
            if(i%2==0)ans[i][j] = true;
            else if(j==0)ans[i][j] = true;
        }
    }
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            in[i][j] = s[j]=='#';
        }
    }
    rep(i,h){
        rep(j,w){
            if(ans[i][j] or in[i][j]){
                cout << '#';
            }else{
                cout << '.';
            }
        }
        cout << endl;
    }
    cout << endl;
    rep(i,h){
        rep(j,w){
            if(!ans[i][j] or in[i][j]){
                cout << '#';
            }else{
                cout << '.';
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(){
    int n,x=1,a=0;
    int i = 1;
    scanf("%d",&n);
 
    do{
        x=i;
        if(x % 3 == 0){
            printf(" %d",i);
            a=1;
        }
        if(a==0){
            do{
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
                x/=10;
 
            }while(x);
        }
        else{
            a=0;
        }
    }while(++i<=n);
    printf("\n");
    return 0;
}


Measured memory_bytes: 2108
#pragma GCC optimize("O3")
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 201000


int main() {
	long long t, n;
	priority_queue<long long>pq;
	vector<pair<long long, long long> >a;
	vector<pair<long long, long long> >b;
	long long ans;
	long long k, idx;
	long long x, y, z;
	scanf("%lld", &t);
	f(tt, t) {
		scanf("%lld", &n);
		ans = 0;
		k = 0;
		a.clear();
		b.clear();
		f(i, n) {
			scanf("%lld %lld %lld", &x, &y, &z);
			if (y >= z) {
				x--;
				ans += z;
				a.push_back(make_pair(x, y-z));
				k++;
			}
			else {
				ans += y;
				b.push_back(make_pair(x, z - y));
			}
		}
		a.push_back({ -100,0 });
		b.push_back({ 10000000,0 });
		sort(a.begin(), a.end(), greater<pair<long long, long long> >());
		sort(b.begin(), b.end());
		idx = 0;
		while (!pq.empty())pq.pop();
		for (int i = k - 1; i >= 0; i--) {
			while ((a[idx].first) >= i) {
				pq.push(a[idx].second);
				idx++;
			}
			if (!pq.empty()) {
				x = pq.top();
				ans += x;
				pq.pop();
			}
		}
		idx = 0;
		while (!pq.empty())pq.pop();
		for (int i = k; i < n; i++) {
			while ((b[idx].first) <= i) {
				pq.push(b[idx].second);
				idx++;
			}
			if (!pq.empty()) {
				x = pq.top();
				ans += x;
				pq.pop();
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 7752
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    map<int, int> m;
    for(int i=2; i<=N; i++){
        map<int, int> mt;
        int t = i;
        for(int j=2; j<=t; j++){
            if(t % j != 0) continue;
            int cnt = 0;
            while(t % j == 0){
                cnt++;
                t = t / j;
            }
            mt[j] = cnt;
            if(t == 1) break;
        }
        for(auto f : mt){
            if(m.count(f.first) == 0)m[f.first] = f.second;
            else m[f.first] += f.second;
        }
    }

    ll ans = 1;
    for(auto n : m){
        ans = ans * (n.second+1);
        ans = ans % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

n, k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

t = float('inf')

for i in range(n - k + 1):
    l, r = x[i], x[i + k - 1]
    t = min(t, r - l + min(abs(r), abs(l)))

print(t)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    ll M = a[0];
    double m = (a[0]+0.0)/2;
    double sa = 1e9;
    ll ans = 0;
    rep(i,n){
        if(i==0)continue;
        if(abs(a[i]-m)<sa){
            ans = a[i];
            sa=a[i]-m;
        }
    }
    cout << M <<' ' <<  ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[400010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    string S; cin >> S;
    vector<int> v;
    int len = 0;
    if(S[0] == '1') v.push_back(0);
    rep(i, N) {
        if(i == 0 || S[i - 1] == S[i]) len++;
        else {
            v.push_back(len);
            len = 1;
        }
    }
    if(len > 0) v.push_back(len);
    int ans = 0;
    int res = 0;
    int right = 0;
    int cnt = 0;
    for(int left = 0; left < v.size(); left++) {
        while(right < v.size() && (right % 2 == 0) + cnt <= K) {
            res += v[right];
            cnt += (right % 2 == 0);
            ++right;
        }
        //cout << left << " " << right << " " << cnt << " " << res << endl;
        ans = max(ans, res);
        if(left == right) right++;
        else {
            cnt -= (left % 2 == 0);
            res -= v[left];
        }
    }
    cout << ans << endl;


    return 0;
}
// 0 

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
int sum[3<<17],cnt[3<<17],ans[3<<17],N,i,acc,t,A;
main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&A);
		++sum[++cnt[A]];
	}
	i=0;
	for(t=N;t>0;t--)
	{
		while(acc>=i*t)acc+=sum[++i];
		ans[t]=i-1;
	}
	for(i=1;i<=N;i++)printf("%d\n",ans[i]);
}


Measured memory_bytes: 4608
H,W = map(int,input().split())
S = [input() for i in range(H)]
blk = sum(row.count('#') for row in S)

from collections import deque
dxy = [(0,1),(1,0),(0,-1),(-1,0)]
dist = [[0]*W for i in range(H)]
visited = [[0]*W for i in range(H)]
visited[0][0] = 1
q = deque([(0,0)])
while q:
    x,y = q.popleft()
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if visited[ny][nx]: continue
        if S[ny][nx] == '#': continue
        visited[ny][nx] = 1
        dist[ny][nx] = dist[y][x] + 1
        q.append((nx,ny))
if visited[-1][-1]:
    print(H*W - blk - dist[-1][-1] - 1)
else:
    print(-1)

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

const M: usize = 1_000_000_007;

fn main() {
    input! {
        h: usize, w: usize,
        grid: [chars; h],
    }

    let mut dp = vec![vec![0; w]; h];
    dp[0][0] = 1;
    for i in 0..h {
        for j in 0..w {
            if j + 1 < w && grid[i][j + 1] == '.' {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= M;
            }
            if i + 1 < h && grid[i + 1][j] == '.' {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= M;
            }
        }
    }

    println!("{}", dp[h - 1][w - 1]);
}


Measured memory_bytes: 16636
#include<iostream>
using namespace std;
int main(){
	int t,n;
	cin>>t>>n;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	int b[n];
	for(int i=0;i<n-1;++i)
		b[i]=a[i+1]-a[i];
	b[n-1]=t-a[n-1]+a[0];
	int maxv=0;
	for(int i=0;i<n;++i)
		maxv=max(maxv,b[i]);
	cout<<t-maxv<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
signed main(){
    int n,m;
    cin>>n>>m;
    map<int,int> cnt;
    int ans=0;
    int sum=0;
    cnt[0]=1;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        sum+=a;
        if(cnt.count(sum%m)){
            ans+=cnt[sum%m];
            cnt[sum%m]++;
        }else{
            cnt[sum%m]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var N = NM[0];
            var M = NM[1];

            var L = new int[M];
            var R = new int[M];

            for (int i = 0; i < M; i++)
            {
                var LM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                L[i] = LM[0];
                R[i] = LM[1];

            }

            if(R.Min() - L.Max() + 1 >= 0)
            {

                Console.WriteLine(R.Min() - L.Max() + 1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }

       
    }
}


Measured memory_bytes: 15944
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>
#include <iomanip>

#define rep(i,n) for(int (i) = 0; (i)<(n); (i)++)
#define FOR(i,s,e) for(int (i) = (s); (i)<(e); (i)++)
#define vecall(itr,vec) for(auto (itr) = (vec).begin(); (itr) != (vec).end(); (itr)++)
#define vecshow(vec) for(auto itr = (vec).begin(); itr != (vec).end(); itr++)cout << *itr << " ";

using namespace std;
using p = pair<int, int>;
using ll = long long;

int gcd(int a, int b) {
	int l = max(a, b);
	int s = min(a, b);
	while (l * s != 0) {
		int tmp = s;
		s = l % s;
		l = tmp;
	}

	return l;
}

vector<vector<int>> path;

int main() {
	int x;

	rep(i, 5) {
		cin >> x;
		if (x == 0)cout << i + 1 << endl;
	}
	
	return 0;

}

Measured memory_bytes: 3560
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


#define REP(i, n) for(ll i = 0; i < n; i++)






























int main(){
    ll n, x, t;
    cin >> n >> x >> t;
    cout << ((n % x == 0)? t * n / x : t * (n / x + 1)) << endl;
}

Measured memory_bytes: 3604
s = gets.chomp.split("")
flag = true
flag = false if s.include?("N") && !s.include?("S")
flag = false if s.include?("S") && !s.include?("N")
flag = false if s.include?("W") && !s.include?("E")
flag = false if s.include?("E") && !s.include?("W")
puts flag ? "Yes" : "No"


Measured memory_bytes: 1788
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

type area struct {
	x, y int
}

func check(e []area, M, N int) {
	m := make([][]bool, N)
	n := make(map[int]int)
	for i := 0; i < N; i++ {
		m[i] = make([]bool, N)
		n[i] = i
	}
	out(e)
	for i := 0; i < N; i++ {
		// out(n)
		for j := 0; j < M; j++ {
			a := n[e[j].x]
			b := n[e[j].y]
			// out(a, b)
			if a == b {
				out("error")
				return
			}
			if m[a][b] == false && m[b][a] == false {
				m[a][b] = true
				m[b][a] = true
			} else {
				out("error")
				return
			}
		}
		for j := 0; j < N; j++ {
			n[j] = (i + j + 1) % N
		}
	}

	for i := 0; i < N; i++ {
		out(m[i])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	_, M := getInt(), getInt()

	// e := make([]area, M)
	// for i := 0; i < M; i++ {
	// 	a := i + 1
	// 	b := 2*M - i
	// 	e[i] = area{a - 1, b - 1}
	// 	out(a, b, abs(a-b), N-abs(a-b))
	// }
	// check(e, M, N)

	for i := 0; i < M; i++ {
		a := i + 1
		b := M - i
		if a < b {
			out(a, b)
		} else {
			break
		}
	}

	for i := 0; i < M; i++ {
		a := M + i + 1
		b := 2*M - i + 1
		if a < b {
			out(a, b)
		} else {
			break
		}
	}
}


Measured memory_bytes: 3304
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <string.h>
#include <stdio.h>

typedef long long ll;
using namespace std;

typedef vector<vector<pair<int, int> > > graph_t;
typedef vector<tuple<int, int, int>> edges_t;
const int INF = 1e9+1;

int solve(int N, const edges_t &roads, const edges_t &searoute, const vector<int> &path)
{
	vector<vector<int>> gr;
	gr.resize(N);
	for (int i = 0; i < N; i++) {
		gr[i].resize(N, INF);
		gr[i][i] = 0;
	}
	for (auto i = roads.begin(); i != roads.end(); ++i) {
		int s = get<0>(*i);
		int e = get<1>(*i);
		int d = get<2>(*i);
		gr[s][e] = min(gr[s][e], d);
		gr[e][s] = min(gr[e][s], d);
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++)
				gr[i][j] = min(gr[i][j], gr[i][k] + gr[k][j]);
		}
	}
	
	vector<vector<int>> gs;
	gs.resize(N);
	for (int i = 0; i < N; i++) {
		gs[i].resize(N, INF);
		gs[i][i] = 0;
	}
	for (auto i = searoute.begin(); i != searoute.end(); ++i) {
		int s = get<0>(*i);
		int e = get<1>(*i);
		int d = get<2>(*i);
		gs[s][e] = min(gs[s][e], d);
		gs[e][s] = min(gs[e][s], d);
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++)
				gs[i][j] = min(gs[i][j], gs[i][k] + gs[k][j]);
		}
	}

	vector<vector<int>> dp; // [??????????????????][????????´???]
	dp.resize(path.size());
	for (auto i = dp.begin(); i != dp.end(); ++i)
		i->resize(N+1, INF);
	for (int j = 0; j < N; j++) {
		dp[0][j] = min(INF, gs[path[0]][j] + gr[j][path[0]]);
		//cout << "dp[" << 0 << "][" << j << "] = " << dp[0][j] << endl;
	}
	for (int i = 1; i < (int)path.size(); i++) {
		for (int j = 0; j < N; j++) {
			int d = INF;
			for (int l = 0; l < N; l++) {
				if (l == j) {
					d = min((ll)d, (ll)dp[i-1][l] + gr[path[i-1]][path[i]]);
				} else {
					ll e = (ll)dp[i-1][l] + gs[l][j];
					e += gr[path[i-1]][l];
					e += gr[j][path[i]];
					d = min((ll)d, e);
				}
			}
			dp[i][j] = d;
			//cout << "dp[" << i << "][" << j << "] = " << d << endl;
		}
	}
	int ans = INF;
	for (int i = 0; i < N; i++) {
		ans = min(ans, dp[path.size()-1][i]);
	}
	return ans;
}

void solve_stdio()
{
	while (true) {
		int N, M;
		if (!(cin >> N >> M))
			break;
		if (N == 0 || M == 0)
			break;
		edges_t roads;
		edges_t searoute;
		for (int i = 0; i < M; i++) {
			int s, e, t;
			string sl;
			cin >> s >> e >> t >> sl;
			s--; e--;
			if (sl == "L")
				roads.emplace_back(s, e, t);
			else
				searoute.emplace_back(s, e, t);
		}
		int R;
		cin >> R;
		vector<int> path;
		path.resize(R);
		for (int i = 0; i < R; i++) {
			int z;
			cin >> z;
			z--;
			path[i] = z;
		}
		int ans = solve(N, roads, searoute, path);
		cout << ans << endl;
	}
}

int main()
{
	solve_stdio();
}


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


const double eps = 1e-10;
int sgn(double x) {
    if(fabs(x) < eps) return 0;
    return x < 0 ? -1 : 1;
}
struct Point {
    double x, y;
    Point(double xp=0, double yp=0): x(xp), y(yp) { }
    Point operator + (const Point& rhs) const { return Point(x+rhs.x, y+rhs.y); }
    Point operator - (const Point& rhs) const { return Point(x-rhs.x, y-rhs.y); }
    Point operator * (const double& k) const { return Point(x*k, y*k); }
    Point operator / (const double& k) const { return Point(x/k, y/k); }
    bool operator < (const Point& rhs) const { return x < rhs.x || (x==rhs.x && y<rhs.y); }
    bool operator == (const Point& rhs) const {return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0; }
    Point turn(double rad) { return Point(x*cos(rad)-y*sin(rad), x*sin(rad)+y*cos(rad)); }
    void scan() { scanf("%lf%lf", &x, &y); }
};
typedef Point Vector;

double dot(Vector x, Vector y) { return x.x*y.x + x.y*y.y; }
double length(Vector x) { return sqrt(dot(x, x)); }
double cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }


Point LineProjection(Point P, Point A, Point B) {
    Vector v = B - A;
    return A + v * (dot(P-A, v) / dot(v, v));
}
Point LineReflection(Point P, Point A, Point B) {
    Point proj = LineProjection(P, A, B);
    return proj + proj - P;
}

int Clockwise(Point O, Point A, Point B) {
    /* Clockwise: -1
       Counterclockwise: 1
       Otherwise: 0
    */
    return sgn(cross(A - O, B - O));
}

void SegCheck(Point a, Point b, Point p) {
    Vector d = b - a, e = p - a;
    if(sgn(dot(d, e)) == -1) puts("ONLINE_BACK");
    else if(sgn(length(e) - length(d)) == 1) puts("ONLINE_FRONT");
    else puts("ON_SEGMENT");
}

int JudgeLLParOrth(Point a1, Point a2, Point b1, Point b2) {
    /* 2: parallel
       1: orthogonal
       0: otherwise
    */
    Vector v = a2 - a1, w = b2 - b1;
    if(sgn(cross(v, w)) == 0) return 2;
    if(sgn(dot(v, w)) == 0) return 1;
    return 0;
}

bool CheckSSProperIntersection(Point a1, Point a2, Point b1, Point b2) {
    double c1 = cross(a1 - b1, b2 - b1), c2 = cross(a2 - b1, b2 - b1);
    double c3 = cross(b1 - a1, a2 - a1), c4 = cross(b2 - a1, a2 - a1);
    return sgn(c1) * sgn(c2) == -1 && sgn(c3) * sgn(c4) == -1;
}
bool OnSeg(Point P, Point A, Point B) {
    Vector v = B - P, w = A - P;
    if(sgn(cross(v, w)) != 0) return false;
    return sgn(dot(v, w)) == -1;
}

bool CheckSSIntersection(Point a1, Point a2, Point b1, Point b2) {
    if(a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2) return true;
    if(OnSeg(a1, b1, b2) || OnSeg(a2, b1, b2) || OnSeg(b1, a1, a2) || OnSeg(b2, a1, a2))
        return true;
    return CheckSSProperIntersection(a1, a2, b1, b2);
}

int main() {
    Point a1, a2, b1, b2;
    int q; scanf("%d", &q);
    while(q--) {
        a1.scan(), a2.scan();
        b1.scan(), b2.scan();
        printf("%d\n", CheckSSIntersection(a1, a2, b1, b2));
    }
    
    return 0;
}


Measured memory_bytes: 3228