akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  Graph g(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int dist[n];
  rep(i,n)dist[i]=1000000000;
  dist[0]=0;
  queue<int> q;
  q.push(0);
  int a=0,b=0;//a=0との距離が最大となる点
    //cout << 1 << endl;
  while(q.size()!=0){
    int u=q.front();
    q.pop();
    for(int v: g[u]){
      if(dist[v]>=1000000000){
        if(b<dist[u]+1){
          b=dist[u]+1;
          a=v;
        }
        dist[v]=dist[u]+1;
        q.push(v);
      }
    }
  }
  rep(i,n)dist[i]=1000000000;
  dist[a]=0;
  int ans=0;
  q.push(a);
  while(q.size()!=0){
    int u=q.front();
    q.pop();
    for(int v: g[u]){
      if(dist[v]>=1000000000){
        if(ans<dist[u]+1){
          ans=dist[u]+1;
        }
        dist[v]=dist[u]+1;
        q.push(v);
      }
    }
  }
  if(ans%3==1)cout << "Second" << endl;
  else cout << "First" << endl;
}


Measured memory_bytes: 16404
#include <stdio.h>
#include <stdlib.h>

typedef struct Node_ Node;

struct Node_
{
    int key;
    Node* parent;
    Node* left;
    Node* right;
};

Node* root;

static void insert(int key)
{
    Node* node = (Node*)malloc(sizeof(Node));
    node->key = key;
    node->parent = NULL;
    node->left = NULL;
    node->right = NULL;

    Node* parent = NULL;
    Node* cur = root;
    while (cur != NULL) {
        parent = cur;
        if (node->key < cur->key) {
            cur = cur->left;
        } else {
            cur = cur->right;
        }
    }

    node->parent = parent;

    if (parent == NULL) {
        root = node;
    } else {
        if (node->key < parent->key) {
            parent->left = node;
        } else {
            parent->right = node;
        }
    }
}

static void printInorder(Node* node)
{
    if (node == NULL)
        return;
    printInorder(node->left);
    printf(" %d", node->key);
    printInorder(node->right);
}

static void printPreorder(Node* node)
{
    if (node == NULL)
        return;
    printf(" %d", node->key);
    printPreorder(node->left);
    printPreorder(node->right);
}

static void printTree()
{
    printInorder(root);
    printf("\n");
    printPreorder(root);
    printf("\n");
}

static void freeTree(Node* node)
{
    if (node->left != NULL) {
        freeTree(node->left);
    }
    if (node->right != NULL) {
        freeTree(node->right);
    }
    free(node);
}

int main()
{
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char command[10];
        scanf("%s", command);

        if (command[0] == 'i') {
            int key;
            scanf("%d", &key);
            insert(key);
        } else if (command[0] == 'p') {
            printTree();
        }
    }

    freeTree(root);
    return 0;
}


Measured memory_bytes: 25176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int> que;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        que.push(tmp);
    }
    for(int i=0;i<m;i++){
        if(!que.empty()){
            int tmp=que.top();
            que.pop();
            que.push(tmp/2);
        }
    }
    ll ans=0;
    while(!que.empty()){
        ans+=que.top();
        que.pop();
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
  string s, t;

  cin >> s >> t;

  int n = s.size()*2;

  int flag;

  s = s + s;
  rep(i, n)
  {
    if (s.at(i) == t.at(0))
    {
      // cout << i+1 << endl;
      flag = 0;
      // cout << s.substr(i, s.size()/2) << endl;
      if (s.substr(i, s.size()/2) == t)
      {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}


Measured memory_bytes: 3644
N, A, B = map(int, raw_input().split())
X = map(int, raw_input().split())
ans = 0
for i in range(N-1):
    if (X[i+1] - X[i]) * A < B:
        ans += (X[i+1] - X[i]) * A
    else:
        ans += B
print ans

Measured memory_bytes: 11320
#include <iostream>
#include <vector>

int main(void)
{
	int N;
	std::cin >> N;
	std::vector<int> p;

	for (int i = 0; i<N; i++)
	{
		p.push_back(0);
		std::cin >> p[i];
	}

	int max = 0;
	int max_num = -1;
	for (int i = 0; i < N; i++)
	{
		if (max < p[i])
		{
			max = p[i];
			max_num = i;
		}
	}

	p[max_num] /= 2;

	int answer = 0;

	for (int i = 0; i < N; i++)
	{
		answer += p[i];
	}

	std::cout << answer << std::endl;


	return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut a: u32 = sc.read();
    let mut b: u32 = sc.read();
    let k: usize = sc.read();
    for i in (0..k) {
        if i % 2 == 0 {
            if a % 2 == 1 {
                a -= 1;
            }
            b += a / 2;
            a /= 2
        } else {
            if b % 2 == 1 {
                b -= 1;
            }
            a += b / 2;
            b /= 2
        }
    }
    println!("{} {}", a, b);
}

Measured memory_bytes: 2124
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
const long double PI = acos(-1);
using namespace std;
int main (){
    int n; cin >> n;
    vector<int>a(n);
    long long g=0;
    for(int i=0; i<n; i++){
        cin >> a[i];  g += a[i];
    } 
    sort(a.begin(), a.end());
    cout << a[0] << " " << a[n-1] << " " << g << endl;
    return 0;
}


Measured memory_bytes: 3152
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Bismillahirrahmanirrahim
#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 500005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k,x,y,PS[li];
string s;
string ss;
vector<lo> v;

int main(){
	fio();
	cin>>n>>m;
	cin>>s;
	ss=s;
	for(lo i=0;i<(lo)s.size();i++){
		if(s[i]=='A' && s[i+1]=='C') s[i]='1';
		//~ else if(s[i]=='C' && s[i-1]=='A') s[i]='1';
		else s[i]='0';
	}
	for(lo i=0;i<(lo)s.size();i++){
		if(s[i]=='1') PS[i+1]=PS[i]+1;
		else PS[i+1]=PS[i];
	}
	for(lo i=1;i<=m;i++){
		cin>>x>>y;
		if(ss[y-1]=='A' && ss[y]=='C'){cout<<PS[y]-PS[x-1]-1<<endl;}
		else cout<<PS[y]-PS[x-1]<<endl;
	}
	//~ cout<<s<<endl;
	return 0;
}


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

int main() {
	long long n,i,k,j,sum=0,count=0,ans=0;
	n=3;
	long long a[n];
	for(i=0;i<n;i++)
	{cin>>a[i];
	sum+=a[i];
	}
	if(sum>=22)
	cout<<"bust";
	else cout<<"win";
	
	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9
int D, G;
vector<int> p, c;
int main(){
  cin >> D >> G;
  p.resize(D), c.resize(D);
  REP(i, D){
    cin >> p[i] >> c[i];
  }
  int ans = INF;
  for(int b = 0; b < (1<<D); b++){
    int score = 0, cnt = 0;
    for(int i = 0; i < D; i++){
      if(b & (1<<i)){
        score += p[i]*100*(i+1) + c[i];
        cnt += p[i];
      }
    }
    REPR(i, D-1){
      if((b&(1<<i)) == 0 && score < G){
        if(p[i] * 100 * (i+1) + score <= G){
          score += p[i] * 100 * (i+1);
          cnt += p[i];
        }
        else{
          int c = (G-score) /(100*(i+1));
          if(score + c * 100 * (i+1) < G){
            c++;
          }
          score += c * 100 * (i+1);
          cnt += c;
        }
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
li = [ [int(it) for it in input().split()] for i in range(N)]

po = [0]*N
for i in range(N):
  po[i] = ( sum(li[i]) , i )
po.sort ( key = lambda x: -x[0] )

s = 0
it = 0
for i in range(N):
  s += li[ po[i][1] ][it] * ( 1 - it * 2  )
  it = 1-it           
print (s)

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


int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    ll rev1=0;
    
    for(int i = 0; i < N-1; i++){
        ll cnt=0;
        for(int j = i+1; j < N; j++){
            //ll cnt=0;
            if(A[i] > A[j]){
                rev1++;
                //cout << A[i] << " " << A[j] << endl;
                cnt++;
            }
        }
        //cout << i << " A[i] : " << A[i]  << "  : " << cnt << endl;
    }
    sort(A.rbegin(), A.rend());
    ll rev2 = 0;
    for(int i = 0; i < N-1; i++){
        ll cnt=0;
        for(int j = i+1; j < N; j++){
            if(A[i] > A[j]){
                rev2++;
                cnt++;
            }
        }
    }
    
    ll sigma = ((K*(K-1))/2)%MOD;
    //cout << sigma << " " << rev1 << " " << rev2 << endl;
    cout << ((sigma*rev2)%MOD + K*rev1)%MOD  << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt[50][256]={};
  int ans[256];
  for(int i=0;i<256;i++)ans[i]=1e9;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    for(int j=0;j<s.size();j++)
      cnt[i][s[j]]++;
  }
  for(int i=0;i<n;i++)
    for(int j='a';j<='z';j++)
      ans[j]=min(ans[j],cnt[i][j]);
  
  for(int i='a';i<='z';i++)
    for(int j=0;j<ans[i];j++)
      cout<<(char)i;
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include <set>

using namespace std;

// 頂点数、変数
int v, e;
const int MAX_N = 100010;
// 隣接リスト
vector<int> g[MAX_N];
bool used[MAX_N];
// トポロジカルソートされた数列
vector<int> ans;

void dfs(int u) {
    if (used[u]) return;
    used[u] = true;
    for (auto &i: g[u]) dfs(i);
    // 帰りがけ順で追加
    ans.push_back(u);
}

void tsort() {
    for (int i = 0; i < v; ++i) dfs(i);
    reverse(ans.begin(), ans.end());
}

int ans2[100100];
vector<int> G2[100100];
int order[100100];

int ansi(int i) {
    int maxorder = -1;
    for (auto p:G2[i]) {
        maxorder = max(maxorder, order[p]);
    }
    if (maxorder == -1)return 0;
    return ans[maxorder] + 1;
}

signed main(void) {
    cin >> v >> e;
    e += v - 1;
    for (int i = 0; i < e; ++i) {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        g[s].push_back(t);
        G2[t].push_back(s);
    }

    tsort();

    for (int i = 0; i < v; ++i) {
        order[ans[i]] = i;
    }
    for (int i = 0; i < v; ++i) {
        cout << ansi(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 16380
#include<iostream>
#include<vector>
#include<string>

int main(){
    int x[2], y[2];
    std::cin >> x[0] >> y[0] >> x[1] >> y[1];
    std::string out = std::string(y[1] - y[0], 'U') + std::string(x[1] - x[0], 'R');
    out += std::string(y[1] - y[0], 'D') + std::string(x[1] - x[0], 'L');
    out += "L";
    out += std::string(y[1] - y[0] + 1, 'U');
    out += std::string(x[1] - x[0] + 1, 'R');
    out += "D";
    out += "R";
    out += std::string(y[1] - y[0] + 1, 'D');
    out += std::string(x[1] - x[0] + 1, 'L');
    out += "U";
    std::cout << out << std::endl;
    return 0;
}


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

namespace ConsoleApp15
{
    class Class9
    {
        static int M = 1000000007;
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(A);
            bool frag = true;
            long ans = 1;
            if (N % 2 == 0)
            {
                for(int i = 0; i < N / 2; i++)
                {
                    ans *= 2;
                    ans %= M;
                }
                for(int i = 0; i < N; i++)
                {
                    if (!(A[i] == i/2 *2+1))
                        frag = false;
                }
            }
            else
            {
                for(int i = 0; i < (N - 1) / 2; i++)
                {
                    ans *= 2;
                    ans %= M;
                }
                if (A[0] == 0)
                {
                    for(int i = 1; i < N; i++)
                    {
                        if (!(A[i] == (i + 1) / 2 *2))
                        {
                            frag = false; break;
                        }
                        
                    }
                }
                
            }
            Console.WriteLine(frag ? ans : 0);
        }
    }
}


Measured memory_bytes: 18016
n = int(input())
w = [0]*n
for i in range(n):
  w[i] = input()
for i in range(1,n):
  for j in range(i):
    if w[i] == w[j]:
      print('No')
      exit()
  if w[i][0] != w[i-1][-1]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    string s;
    cin >> s;
    int n = s.length() - 2;
    int x, ans = INF;
    rep(i,n){
        x = abs(stoi(s.substr(i,3)) - 753);
        if(x < ans) ans = x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  vector<string> s(N);
  for(int i=0;i<N;i++)
    cin>>s.at(i);
  sort(s.begin(),s.end());
  string D;
  for(int i=0;i<N;i++)
    D+=s.at(i);
  cout<<D;
}

Measured memory_bytes: 3628
N=int(input())
if N<10:
  print(N)
elif 10<=N<100:
  print(9)
elif 100<=N<1000:
  print(N-90)
elif 1000<=N<10000:
  print(909)
elif 10000<=N<100000:
  print(N-9090)
else:
  print(90909)

Measured memory_bytes: 2940
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

int n;

vector<int> dijkstra(int s, vector<vector<P>> &G){
    vector<int> dist(n, 1e9);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv;
        tie(ccost, cv) = que.top(); que.pop();

        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = nxt;

            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

int diameter(vector<vector<P>> &G){
    vector<int> dist1 = dijkstra(0, G);
    int v1 = max_element(dist1.begin(), dist1.end()) - dist1.begin();
    vector<int> dist2 = dijkstra(v1, G);
    return *max_element(dist2.begin(), dist2.end());
}

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

    cin>>n;
    vector<vector<P>> G(n);
    for(int i=0; i<n-1; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        G[a].emplace_back(b, 1);
        G[b].emplace_back(a, 1);
    }

    bool first_win[n];
    for(int i=0; i<n; i++) first_win[i] = false;
    first_win[0] = true;
    for(int i=2; i<n; i++){
        first_win[i] |= (!first_win[i-1]);
        first_win[i] |= (!first_win[i-2]);
    }

    int K = diameter(G);

    cout << (first_win[K] ? "First" : "Second") << endl;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    vector<LL> ans;
    LL all_cnt = 0;
    vector<pair<LL,int> > memo;
    int n;

    cin >> n;
    REP(i, n){
        LL a;
        cin >> a;
        all_cnt += a;
        memo.PB(MP(a, i));
        ans.PB(0);
    }

    sort(ALL(memo));
    int idx = n;
    LL stone = 0;
    int cnt = 0;
    LL used_stone = 0;
    int insert_index = INF;
    while(true){
        idx--;
        cnt++;
        pair<LL,int> now = memo[idx];
        if(now.second == 0){
            ans[0] = all_cnt - used_stone;
            break;
        }
        insert_index = min(insert_index, now.second);

        pair<LL,int> next = memo[idx-1];
        stone += now.first;
        LL used = stone - cnt * next.first;
        ans[insert_index] += used;
        stone -= used;
        used_stone += used;
    }

    REP(i, n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b == c || b+c == a || c+a == b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

#include<atcoder/scc>
using namespace atcoder;

int n,m;

int main(){
	cin>>n>>m;
	scc_graph g(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--,v--;
		g.add_edge(u,v);
		g.add_edge(v,u);
	}
	cout<<g.scc().size()-1<<endl;
}

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


int main() {
  int N, M;
  cin >> N >> M;
  
  int max_L = 1, min_R = N;
  int L, R;
  rep(i,M) {
    cin >> L >> R;
    max_L = max(max_L, L);
    min_R = min(min_R, R);
  }
  
  int ans = max(0, min_R - max_L + 1);
  cout << ans << endl;
  return 0;
}


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

#define endl '\n'

using namespace std;

#define int long long

signed main(){

  string str;

  while(1){

    cin>>str;

    if(str=="#"){
      break;
    }

    int day[]={31,28,31,30,31,30,31,31,30,31,30,31};
    
    if(count(str.begin(),str.end(),'.')==2){

      long long y,m,d;
      
      sscanf(str.c_str(),"%lld.%lld.%lld",&y,&m,&d);

      int year=2013;

      long long year_cnt=0;
      
      if(y==2012){
	year_cnt+=(d-21);

      }else{

	year_cnt+=10;
	
	while(1){
	  
	  if(year==y){
	    break;
	  }
	  if((year%4==0&&year%100!=0)||year%400==0){
	    year_cnt+=366;
	  }else{
	    year_cnt+=365;
	  }

	  year++;
	    
	}

	for(int i=0;i<(m-1);i++){

	  if(i==1){
	    if((year%4==0&&year%100!=0)||year%400==0){
	      year_cnt+=(day[i]+1);
	    }else{
	      year_cnt+=(day[i]);
	    }
	  }else{
	    year_cnt+=(day[i]);
	  }
	}
	
	year_cnt+=d;
	
	year_cnt%=1872000;
	
      }


      long long a_ans=0,b_ans=0,c_ans=0,d_ans=0,e_ans=0;      
      
      if(year_cnt>=(20*20*18*20)){
	a_ans=year_cnt/(20*20*18*20);
	year_cnt%=(20*20*18*20);
	
      }
      if(year_cnt>=(20*18*20)){
	b_ans=year_cnt/(20*18*20);
	year_cnt%=(20*18*20);
      }
      if(year_cnt>=(18*20)){
	c_ans=year_cnt/(18*20);
	year_cnt%=(18*20);
      }
      if(year_cnt>=(20)){
	d_ans=year_cnt/(20);
	year_cnt%=(20);
      }
      e_ans=year_cnt;
      
      
      printf("%lld.%lld.%lld.%lld.%lld\n",a_ans,b_ans,c_ans,d_ans,e_ans);
      
	
    }else if(count(str.begin(),str.end(),'.')==4){
      long long a,b,c,d,e;
      
      sscanf(str.c_str(),"%lld.%lld.%lld.%lld.%lld",&a,&b,&c,&d,&e);

      long long cnt=0;


      //日数
      cnt+=(20*20*18*20*a);
      cnt+=(20*18*20*b);
      cnt+=(18*20*c);
      cnt+=(20*d);
      cnt+=(e);

      //2012年から
      long long year=2013;
      long long ans=0;

      if(cnt<=10){

	cout<<2012<<"."<<12<<"."<<21+cnt<<endl;
	
      }else{
	cnt-=10;	
	while(1){
	  
	  if((year%4==0&&year%100!=0)||year%400==0){
	    
	    if(cnt>366){
	      cnt-=366;
	    }else{
	      break;
	    }
	  }else{
	    if(cnt>365){
	      cnt-=365;
	    }else{
	      break;
	    }
	  }
	  
	  year++;
	  ans++;
	  
	}
	int m_cnt=1;
       
	if((year%4==0&&year%100!=0)||year%400==0){
	  for(int i=0;i<12;i++){
	    if(i==1){
	      
	      if(cnt>(day[i]+1)){
		cnt-=(day[i]+1);
		m_cnt++;
	      }else{
		break;
	      }
	    }else{
	      if(cnt>(day[i])){
		cnt-=(day[i]);
		m_cnt++;
	      }else{
		break;
	      }
	    }
	    
	  }
	}else{
	  for(int i=0;i<12;i++){
	    if(cnt>(day[i])){
	      cnt-=(day[i]);
	      m_cnt++;
	    }else{
	      break;
	    }
	  }
	}
	cout<<year<<"."<<m_cnt<<"."<<cnt<<endl;
      }
      
    }
  
  }    
  
  
  return 0;

}



Measured memory_bytes: 3332
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < m; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            map.computeIfAbsent(a, v -> new ArrayList<>()).add(b);
        }

        final boolean answer = map.get(1).stream()
                .flatMap(i -> Optional.ofNullable(map.get(i)).orElse(Collections.emptyList()).stream())
                .anyMatch(i -> i == n);

        System.out.println(answer ? "POSSIBLE" : "IMPOSSIBLE");
    }
}


Measured memory_bytes: 127192
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool a=true;
  char ans;
  for(char c='a';c<='z';c++){
    bool b=false;
    for(int i=0;i<s.size();i++){
      if(c==s[i]){
        b=true;
        break;
      }
    }
    if(!b){
      a=false;
      ans=c;
      break;
    }
  }
  if(a){
    cout << "None" << endl;
  }
  else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 512
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)

  int dp[105][4][2];

  int main(){
    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;

    dp[0][0][0] = 1;
    rep(i,n) rep(j,4) rep(k,2){
      int nd = s[i]-'0';
      rep(d,10){
        int ni = i+1,nj = j,nk = k;
        if (d != 0) nj++;
        if (nj > K) continue;
        if (k == 0){
          if (d > nd) continue;
          if (d < nd) nk = 1;
        }
        dp[ni][nj][nk] += dp[i][j][k];
      }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;

    return 0;
  }


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ll k;
  cin >> k;
  vector<ll> vec(k+1, 0);
  ll x = 7 % k;
  for (ll i = 1; i <= k; i++) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    x = (x * 10 + 7) % k;
  }
  
  cout << - 1 << endl;
  
  return 0;
}

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

int N, P[10009], S;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> P[i];
		if (i != P[i]) S++;
	}
	if (S <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
t,x,y=[0]*(n+1),[0]*(n+1),[0]*(n+1)
for i in range(1,n+1):
  t[i],x[i],y[i]=map(int,input().split())
for i in range(n):
  d = abs(x[i+1]-x[i])+abs(y[i]-y[i+1])
  time = t[i+1]-t[i]
  #print(d,time)
  if d > time or abs(d - time) % 2 == 1:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 11636
#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]

def main():
    from heapq import heappush, heappop, heapify
    H, W, K = MAP()
    HH = max(H, W) + 2
    x1, y1, x2, y2 = LIST()
    c = [[-1] + [0 if c == "." else -1 for c in input()] + [-1]
         for i in range(H)]
    c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]

    # 0123: 上下左右
    stack = []
    heappush(stack, (0, x1, y1, 0))
    heappush(stack, (0, x1, y1, 1))
    heappush(stack, (0, x1, y1, 2))
    heappush(stack, (0, x1, y1, 3))
    DX = (1, 0, -1, 0)
    DY = (0, 1, 0, -1)
    while stack:
        new_stack = []
        while stack:
            curr, x, y, d = heappop(stack)
            dx, dy = DX[d], DY[d]
            flag = True
            a = curr + 1
            for k in range(1, K + 1):
                xx, yy = x + k * dx, y + k * dy
                if c[xx][yy] == 0:
                    b = c[xx + DX[(d - 1) % 4]][yy + DY[(d - 1) % 4]]
                    if b == 0 or b == a + 1:
                        heappush(new_stack, (a, xx, yy, (d - 1) % 4))
                    b = c[xx + DX[(d + 1) % 4]][yy + DY[(d + 1) % 4]]
                    if b == 0 or b == a + 1:
                        heappush(new_stack, (a, xx, yy, (d + 1) % 4))
                    c[xx][yy] = a
                elif c[xx][yy] != a:
                    flag = False
                    break
            if flag:
                heappush(new_stack, (a, xx, yy, d))
            if c[x2][y2] > 0:
                print(c[x2][y2], flush=True)
                exit(0)
        stack = new_stack

    print(-1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Scanner;
import java.util.Set;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class TaskD {
        private ArrayList<ArrayList<Integer>> edges;
        private HashMap<Set<Integer>, Integer> length = new HashMap<>();
        private int[] color;

        private void dfs(int par, int v) {
            for (int child : edges.get(v)) {
                if (child != par) {
                    int l = length.get(new HashSet<>(Arrays.asList(v, child)));
                    if ((l & 1) == 0) {
                        color[child] = color[v];
                    } else {
                        color[child] = color[v] ^ 1;
                    }
                    dfs(v, child);
                }
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int nVertices = in.nextInt();
            edges = new ArrayList<>(nVertices + 1);
            for (int i = 0; i <= nVertices; i++) {
                edges.add(new ArrayList<>());
            }
            for (int i = 0; i < nVertices - 1; i++) {
                int u = in.nextInt();
                int v = in.nextInt();
                int l = in.nextInt();
                edges.get(u).add(v);
                edges.get(v).add(u);
                length.put(new HashSet<>(Arrays.asList(u, v)), l);
            }
            color = new int[nVertices + 1];
            color[1] = 0;
            dfs(0, 1);
            for (int i = 1; i <= nVertices; i++) {
                out.println(color[i]);
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

    }
}



Measured memory_bytes: 163204
n, m = map(int, input().split())
swtiches = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2 ** n):
    is_on = True
    for j in range(m):
        k = swtiches[j][0]
        s = swtiches[j][1:]
        cnt = 0
        for si in s:
            if i >> (si - 1) & 1:
                cnt += 1
        if cnt % 2 != p[j]:
            is_on = False
    if is_on:
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstdlib>
using namespace std;
int main() {
  string s;
  stringstream ss;
  cin >> s;
  int m = 100000;
  for(int i=0;i<s.length()-2;i++){
    string sub = s.substr(i,3);
    m = min(m,abs(stoi(sub)-753));
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  
  if (a[0] == a[1] && a[1] != a[2]) cout << "Yes" << endl;
  else if (a[2] == a[1] && a[1] != a[0]) cout << "Yes" << endl;
  else cout << "No" << endl;


  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A_list = [int(elem) for elem in input().split(' ')]
assert len(A_list) == N

modified_A_list = [A - i for i, A in enumerate(A_list, start=1)]

minus_A_list = sorted([A for A in modified_A_list if A < 0])[::-1]
zero_A_list = [A for A in modified_A_list if A == 0]
plus_A_list = sorted([A for A in modified_A_list if A > 0])
#print(minus_A_list, zero_A_list, plus_A_list)

len_minus = len(minus_A_list)
len_zero = len(zero_A_list)
len_plus = len(plus_A_list)
assert len_minus + len_zero + len_plus == N
current_sum = abs(sum(minus_A_list)) + sum(plus_A_list)
#print(current_sum)

if len_minus > len_plus + len_zero:
    i = 0
    old_num = 0
    while i < len(minus_A_list):
        current_num = minus_A_list[i]
        current_sum -= abs(current_num - old_num) * (len_minus - len_plus - len_zero)
        # 数の更新
        num_current_val = 0
        while i < len(minus_A_list) and (minus_A_list[i] == current_num):
            i += 1
            num_current_val += 1
        len_minus -= num_current_val
        len_zero_old = len_zero
        len_zero += num_current_val - len_zero_old
        len_plus += len_zero_old
        old_num = current_num
        if len_minus <= len_plus + len_zero:
            break

elif len_plus > len_minus + len_zero:
    i = 0
    old_num = 0
    while i < len(plus_A_list):
        current_num = plus_A_list[i]
        current_sum -= (current_num - old_num) * (len_plus - len_minus - len_zero)
        # 数の更新
        num_current_val = 0
        while i < len(plus_A_list) and plus_A_list[i] == current_num:
            i += 1
            num_current_val += 1
        len_plus -= num_current_val
        len_zero_old = len_zero
        len_zero += num_current_val - len_zero_old
        len_minus += len_zero_old
        old_num = current_num
        if len_plus <= len_minus + len_zero:
            break

print(current_sum)


Measured memory_bytes: 26784
#include <iostream>
#include <string>

using namespace std;

int main() {
    int A, B;
    string s;

    cin >> A >> B >> s;

    for (int i = 0; i < A; i++) {
        if (!('0' <= s[i] && s [i] <= '9')) {
            cout << "No" << endl; return 0;
        }
    }
    if (s[A] != '-') {
        cout << "No" << endl; return 0;
    }
    for (int i = A+1; i <= A+B; i++) {
        if (!('0' <= s[i] && s[i] <= '9')) {
            cout << "No" << endl; return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

int n,m;
int al,ar,bl,br;

signed main()
{
	cin>>n>>m;
	al=1,ar=m+1;
	bl=m+2,br=bl+m-1;
	
	for (int i=1;i<=m;i++)
	{
		if (al>=ar)  break;
		else cout<<al<<' '<<ar<<endl;
		
		if (bl>=br)  break;
		else cout<<bl<<' '<<br<<endl;
		
		al++,bl++;
		ar--,br--;
	}
	return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    prints()(lcm(2, N));
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

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

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

    int dist[3];
    for (int & d : dist) {
        cin >> d;
    }
    sort(dist, dist + 3);
    cout << dist[0] + dist[1] << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<vector>

#define PI 3.141592654
#define RADIUS 1.0
#define EPS 1e-10

struct POINT{
	double x;
	double y;

	POINT& operator += ( const POINT& p )
	{
		x += p.x;
		y += p.y;
		return *this;
	}
	POINT& operator -= ( const POINT& p )
	{
		x -= p.x;
		y -= p.y;
		return *this;
	}
	POINT& operator *= ( double factor )
	{
		x *= factor;
		y *= factor;
		return *this;
	}
	POINT& operator /= ( double factor )
	{
		x /= factor;
		y /= factor;
		return *this;
	}
};

POINT operator + ( const POINT& a , const POINT& b )
{
	POINT p(a);
	p += b;
	return p;
}

POINT operator - ( const POINT& a , const POINT& b )
{
	POINT p(a);
	p -= b;
	return p;
}

POINT operator * ( const POINT& a , double factor )
{
	POINT p(a);
	p *= factor;
	return p;
}

POINT operator / ( const POINT& a , double factor )
{
	POINT p(a);
	p /= factor;
	return p;
}

typedef POINT VECTOR;

std::istream& operator >> ( std::istream& s , POINT& p )
{
	char c;
	return s >> p.x >> c >> p.y;
}

double getDistance( const POINT& a , const POINT& b )
{
	return sqrt( pow( a.x - b.x , 2 ) + pow( a.y - b.y , 2 ) );
}

double getSizeofVector( const VECTOR& vec )
{
	return sqrt( pow( vec.x , 2 ) + pow( vec.y , 2 ) );
}

void getCrossPoint( const POINT& a , const POINT& b , POINT *p1 , POINT *p2 )
{
	POINT mid = ( a + b ) / 2;
	if( fabs(getDistance( a , b ) - 2.0) < EPS ){
		*p1 = mid;
		*p2 = mid;
		return;
	}
	else{
		VECTOR ab = b - a;
		double theta = atan( ab.y / ab.x );
		double h = sqrt( pow( RADIUS , 2 ) - pow( getSizeofVector(ab)/2 , 2) );
		p1->x = mid.x + h * cos( theta + PI/2 );
		p1->y = mid.y + h * sin( theta + PI/2 );
		p2->x = mid.x + h * cos( theta - PI/2 );
		p2->y = mid.y + h * sin( theta - PI/2 );
		return;
	}
}

int getMax( int a , int b )
{
	return a > b ? a : b;
}

int main(void)
{
	while(1){
		int n;
		std::cin >> n;
		if( n == 0 ){
			break;
		}
		std::vector<POINT> o;
		for( int i = 0 ; i < n ; i++ ){
			POINT p;
			std::cin >> p;
			o.push_back(p);
		}
		int overlap = 1;
		for( int i = 0 ; i < n-1 ; i++ ){
			for( int j = i+1 ; j < n ; j++ ){
				int cnt1 , cnt2;
				if( getDistance( o[i] , o[j] ) <= 2.0 + EPS ){
					POINT p1, p2;
					getCrossPoint( o[i] , o[j] , &p1 , &p2 );
					cnt1 = 2;
					cnt2 = 2;
					for( int k = 0 ; k < n ; k++ ){
						if( k == i || k == j ){
							continue;
						}
						if( getDistance( o[k] , p1 ) <= 1.0 + EPS ){
							cnt1++;
						}
						if( getDistance( o[k] , p2 ) <= 1.0 + EPS ){
							cnt2++;
						}
					}
				}
				else{
					cnt1 = 0;
					cnt2 = 0;
				}
				if( overlap < getMax( cnt1 , cnt2 ) ){
					overlap = getMax( cnt1 , cnt2 );
				}
			}
		}

		std::cout << overlap << std::endl;
	}

	return 0;
}

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

string S;
string divide[4]{"dream", "dreamer", "erase", "eraser"};

int main(int argc, char **argv)
{
	cin >> S;

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

	double flags;
	while (true)
	{
		flags = false;
		for (int i = 0; i < 4; ++i)
		{
			string target = divide[i];
			if (S.size() < target.size()) continue;
			string tmp = S.substr(0, target.size());
			if (tmp == target)
			{
				S.erase(0, target.size());
				flags = true;
			}
		}
		if (!flags) break;
	}
	std::cout << ((S.empty()) ? "YES" : "NO") << std::endl;
}


Measured memory_bytes: 640
def main():
    # import sys
    # readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    M = 0
    grid = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            m = abs(A[i][j] - B[i][j])
            grid[i][j] = m
            M = max(M, m)

    L = (H + W) * M
    dp = [[[0] * (L + 1) for _ in range(W)] for _ in range(H)]
    dp[0][0][grid[0][0]] = 1

    for i in range(H):
        for j in range(W):
            for k in range(L + 1):
                if dp[i][j][k] == 1:
                    if i < H - 1:
                        nk = grid[i + 1][j]
                        dp[i + 1][j][k + nk] |= 1
                        dp[i + 1][j][abs(k - nk)] |= 1
                    if j < W - 1:
                        nk = grid[i][j + 1]
                        dp[i][j + 1][k + nk] |= 1
                        dp[i][j + 1][abs(k - nk)] |= 1

    for k in range(L + 1):
        if dp[-1][-1][k] == 1:
            print(k)
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 678024
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
ac = [0] * N
pn = [0] * N
for i in range(M):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC':
        ac[p] = 1
    elif s == 'WA' and not ac[p]:
        pn[p] += 1

for i in range(N):
    if not ac[i]:
        pn[i] = 0

print(sum(ac), sum(pn))


Measured memory_bytes: 4724
#include <iostream>
using namespace std;
int main(){
    int k, a, b;
    cin >> k >> a >> b;
    bool ok = false;
    for(int i=a; i<=b; ++i){
        if(i % k == 0){
            ok = true; break;
        }
    }
    if(ok) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3588
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long T1 = sc.nextLong(), T2 = sc.nextLong();
        long A1 = sc.nextLong(), A2 = sc.nextLong();
        long B1 = sc.nextLong(), B2 = sc.nextLong();
        long D1 = A1-B1, D2 = A2-B2;

        /*easier problem:
         * Yoichi runs D1 m/min for T1 minutes, and then runs D2 m/min for T2 minutes.
         * How many times will Yoichi pass the start point?
         * Notice: D1 and/or D2 might be negative.
         */

        if(T1*D1+T2*D2==0) System.out.println("infinity");
        else if((T1*D1>0)==(T1*D1+T2*D2>0)) System.out.println(0);
        else{
            if(D1>0){
                D1 *= -1;
                D2 *= -1;
            }
            //now we can assume them: D1<0, D2>0, and T1*D1+T2*D2>0.
            long cycleDistance = T1*D1+T2*D2;
            long backLimit = Math.abs(D1*T1);
            System.out.println(2 * (backLimit/cycleDistance) + (backLimit%cycleDistance==0 ? 0 : 1));

        }
    }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 200010;
int a[SIZEN],b[SIZEN],c[SIZEN];
int s[SIZEN];
int N,M;
struct Link{
    int to,next,id;
}link[SIZEN << 2];
int head[SIZEN] = {0},tot = 0;
void add(int from,int to,int id){
    link[++tot].to = to;
    link[tot].id = id;
    link[tot].next = head[from];
    head[from] = tot;
}
bool used[SIZEN] = {0};
bool vis[SIZEN] = {0};
bool dfs(int x){
    vis[x] = true;
    bool t = c[x];
    // printf("c[%d]=%d\n",x,c[x]);
    for(int i = head[x];i;i=link[i].next){
        if(!vis[link[i].to] && dfs(link[i].to)){
            t ^= 1;
            used[link[i].id] = true;
        }
    }
    return t;
}
int main(){
    scanf("%d%d",&N,&M);
    for(int i = 1;i <= N;i++){
        scanf("%d%d",&a[i],&b[i]);
        s[i] = a[i];
    }
    sort(s+1,s+1+N);
    for(int i = 1;i <= N;i++){
        a[i] = lower_bound(s+1,s+1+N,a[i]) - s;
        c[a[i]] = b[i];
    }
    for(int i = N+1;i >= 1;i--)c[i] ^= c[i-1];
    for(int i = 1;i <= M;i++){
        int l,r;scanf("%d%d",&l,&r);
        l = lower_bound(s+1,s+1+N,l) - s;
        r = upper_bound(s+1,s+1+N,r) - s - 1;
        if(l > r)continue;
        add(l,r+1,i);add(r+1,l,i);
    }
    for(int i = 1;i <= N+1;i++){
        if(!vis[i] && dfs(i)){
            puts("-1");
            return 0;
        }
    }
    int ans = 0;
    for(int i = 1;i <= M;i++)ans += used[i];
    printf("%d\n",ans);
    for(int i = 1;i <= M;i++)if(used[i])printf("%d ",i);
    printf("\n");
    return 0;
}

Measured memory_bytes: 12424