akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int n, m;
        n = int.Parse(s[0]);
        m = int.Parse(s[1]);
        Graph g = new Graph(n);
        for (int i = 0; i < m; i++)
        {
            s = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(s[0]);
            b = int.Parse(s[1]);
            g.SetEdge(a, b);
            g.SetEdge(b, a);
        }
        bool f = false;
        foreach (var e in g.node[0].edge)
        {
            f = f || e.G.Child.Contains(g.node[n - 1]);
            if (f)
                break;
        }
        Console.WriteLine(f ? "POSSIBLE" : "IMPOSSIBLE");
    }
}
class Node
{
    public int id;
    public List<Edge> edge = new List<Edge>();
    public List<Node> Child = new List<Node>();
    public Node(int id) { this.id = id; }
}
class Edge
{
    public Node S;
    public Node G;
    public Edge(Node S, Node G)
    {
        this.S = S;
        this.G = G;
    }
}
class Graph
{
    public Node[] node;
    public Graph(int n)
    {
        node = new Node[n];
        for (int i = 0; i < n; i++)
            node[i] = new Node(i + 1);
    }
    public void SetEdge(int n1, int n2)
    {
        if (n1 > node.Length || n1 <= 0 || n2 > node.Length || n2 <= 0)
            return;
        Edge e = new Edge(node[n1 - 1], node[n2 - 1]);
        node[n1 - 1].edge.Add(e);
        node[n1 - 1].Child.Add(node[n2 - 1]);
    }
}

Measured memory_bytes: 81516
#include<stdio.h>
#define N 101
#define INF 1000000
#define BLACK 2

int n,g[N][N],d[N];

void Dijkstra(){
  int i,min,u=0,color[N];

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=0;
  }

  d[0]=0;
  color[0]=1;

  while (1) {
    min=INF;
    u=-1;

    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < min){
        min=d[i];
        u=i;
      }
    }

    if(min == INF) break;

    color[u]=BLACK;

    for(i=0;i<n;i++){
      if(color[i] != BLACK && g[u][i] != INF && d[u]+g[u][i] < d[i]){
        d[i]=d[u]+g[u][i];
        color[i]=1;
      }
    }
  }
}

int main(){

  int i,j,k,a,v,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) g[i][j]=INF;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&a,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      g[i][v]=c;
    }
  }

  Dijkstra();

  for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);

  return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>

#define MOD 1000000007

typedef struct node{int value;struct node* right;struct node* left;}node;

void swap(int* a,int* b){int c=*a;*a=*b;*b=c;}
int gcd(int a, int b){if(a<b){swap(&a,&b);}while(a%b!=0){int c=a%b;a=b;b=c;}return b;}
int* mid(int* a, int* b, int* c){if(*b<*a&&*a<*c){return a;}if(*a<*b&&*b<*c){return b;}return c;}
void sort(int is_ascending,int* a,int n){if(n<=1){return;}srand((unsigned int)time(NULL));int l=0,r=n-1;int* p=mid(a,a+n-1,a+(rand()%n));while(l<=r){if(is_ascending){while(*(a+l)<*p){l++;}while(*p<*(a+r)){r--;}}else{while(*(a+l)>*p){l++;}while(*p>*(a+r)){r--;}}if(r<=l){break;}swap(a+l,a+r);l++;r--;}sort(is_ascending,a,l);sort(is_ascending,a+r+1,n-r-1);}
int permutations(int n, int r){int a=n;for(int i=1;i<=r;i++){a*=n-i;}return a;}
int combination(int n, int r){if(r==0||r==n){return 1;}if(r==1){return n;}return combination(n-1,r-1)+combination(n-1,r);}
int isPrime(int n){if(n==1){return 0;}if(n==2||n==3){return 1;}if(n%2==0||n%3==0){return 0;}for(int i=5;i*i<=n;i+=2){if(i%3==0){continue;}if(n%i==0){return 0;}}return 1;}

int main(){
    char sd[51], t[51];
    scanf("%s", sd);
    scanf("%s", t);
    int l = 0;
    while(sd[l] != '\0'){
        l++;
    }
    l--;
    int flag = 0, bflag = 1, ansflag = 0;
    char min[51], buf[51];
    while(l >= 0){
        if(sd[l] == t[0] || sd[l] == '?'){
            int x = 0;
            while(sd[l+x] != '\0' && t[x] != '\0'){
                if(!(sd[l+x] == '?' || sd[l+x] == t[x])){
                    break;
                }
                x++;
            }
            if(t[x] == '\0'){
                flag = 1;
                ansflag = 1;
            }
        }
        if(flag){
            int k=0;
            while(sd[k] != '\0'){
                if(sd[k] == '?'){
                    if(k < l){
                        buf[k] = 'a';
                    }else{
                        if(k-l < strlen(t)){
                            buf[k] = t[k-l];
                        }else{
                            buf[k] = 'a';
                        }
                    }
                }else{
                    buf[k] = sd[k];
                }
                k++;
            }
            buf[k] = '\0';
            //printf("%s\n", buf);
            if(bflag){
                strcpy(min, buf);
                bflag = 0;
            }else{
                int y = 0;
                while(buf[y] != '\0'){
                    if(buf[y] < min[y]){
                        strcpy(min, buf);
                        break;
                    }else if(buf[y] > min[y]){
                        break;
                    }
                    y++;
                }
            }
            flag = 0;
        }
        l--;
    }
    if(ansflag){
        printf("%s", min);
    }else{
        printf("UNRESTORABLE\n");
    }

    return 0;
}

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

bool judge(int s){
  for(int i=2;i*i<=s;i++){
    if(s%i!=0 && (i+1)*(i+1)>s){return true;}
    if(s%i==0){return false; break;}
    }
}


int main(){
  unsigned long long a;
  int m,n,b;
  cin>>m>>n;
  a=m;
  b=1000000007;


  int l=n;
  int k[1000]={};

  if(judge(l)){k[0]=l;}

  else{
    int count=0;
    for(int j=2;;){
      if(l==1){break;}
      if(l%j==0){l=l/j; k[count]=j; count++; continue;}
      j++;
    }}




  for(int j=0;k[j]!=0;j++){
    for(int i=1;i<k[j];i++){
      a=a*m;
      if(a>=b){a=a%b; if(a==m && k[j]-i>k[j]%i){k[j]=k[j]%i; i=0;}  if(a==1){break;}}
  }
    m=a;
  }

  cout<<a<<endl;
 
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>

//#include <map>

using namespace std;

class HW{
public:
	int H, W;
};

int main()
{
	vector<HW> vData;

	while (1)
	{
		int H, W;
		cin >> H >> W;
		if (H == 0 && W == 0)break;

		HW thw;
		thw.H = H;
		thw.W = W;
		vData.push_back(thw);
	}

	for (int i = 0; i < vData.size(); i++)
	{
		int H, W;
		H = vData.at(i).H;
		W = vData.at(i).W;
		for (int y = 0; y < H; y++)
		{
			for (int x = 0; x < W; x++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int A,B,C;
	cin>>A>>B>>C;
	
	if(A>B)swap(A,B);
	if(B>C)swap(B,C);
	
	int ans = 0;
	
	ans += (C-A)/2;
	ans += (C-B)/2;
	
	if(A%2==C%2)A=C;
	else A=C-1;
	
	if(B%2==C%2)B=C;
	else B=C-1;
	
	if(A==C&&B==C){}
	else if(A==B)ans++;
	else ans+=2;
	
	cout<<ans<<endl;
		
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    ll a,b,n,d;
    cin>>n>>d;
    int cnt=0;
    for(int i=0;i<n;++i) {
        cin>>a>>b;
        ll x = a*a + b*b;
        if(x<=d*d) ++cnt;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3624
void main()
{
    long n = rdElem;
    long[] a = rdRow;
    long m = rdElem;
    long[] b = rdRow;

    foreach (x; b)
    {
        long idx = a.binSrch!"a <= b"(x);
        if (idx == -1 || a[idx] != x)
        {
            0.writeln;
            return;
        }
    }

    1.writeln;
}

long binSrch(alias pred = "a < b")(long[] arr, long val)
{
    alias predFun = binaryFun!pred;
    long l = -1, r = arr.length;
    if (!predFun(l, r)) swap(l, r);
    while (abs(r - l) > 1)
    {
        long m = (l + r) / 2;
        if (predFun(arr[m], val)) l = m;
        else r = m;
    }
    return l;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;


Measured memory_bytes: 13892
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n;
  string s;
  cin >> n >> s;
  for (ll i = 0; i < s.size(); i++) {
    char x = s.at(i);
    x -= 65;
    x = (x + n) % 26;
    char y = x + 65;
    cout << y;
  }
  cout << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());  
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
  
  cout << vec.size() << endl;

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
vector<ll> g[111111];
ll n,m,qq,ans[111111],was[111111][11],u,v,st[111111],dist[111111],col[111111],used[111111][11];
deque< pair<ll, pair<ll,ll> > > q;
void read(ll &x)
{
	scanf("%lld",&x);
}
int main()
{
	cin>>n>>m;
	for(ll i=1;i<=m;i++)
	{
		read(u);
		read(v);
		g[u].pb(v);
		g[v].pb(u);
	}
	cin>>qq;
	for(ll i=1;i<=qq;i++)
	{
		read(st[i]);
		read(dist[i]);
		read(col[i]);
		q.push_front(mp(st[i], mp(dist[i], col[i])));
	}
	for(;q.size()>0;)
	{
		auto x=q.front();
		q.pop_front();
		int v=x.first, d=x.second.first, c=x.second.second;
		if(used[v][d])
			continue;
		if(!ans[v]) ans[v]=c;
		used[v][d]=1;
		if(d==0) continue;
		for(int to:g[x.first])
		{
			if(!used[to][d-1]&&!was[to][d-1])
			{
				was[to][d-1]=1;
				q.push_front(mp(to,mp(d-1,c)));	
			}
		}
	}
	for(int i=1;i<=n;++i)
		printf("%lld\n",ans[i]);
}

Measured memory_bytes: 41460
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

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

#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file freopen("out.out","w",stdout);
#define RE cout<<233<<endl;
#define Tnum(x) cout<<x<<endl;
#define Tall(x,n) for(int i=0;i<n;i++)cout<<x[i]<<(i==n-1?"\n":" ");
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

string n;

int main() {
  fastio;
  cin>>n;
  if(n.size()==1){
  	cout<<n[0]-'0'<<endl;
  	return 0;
	}
	int cur=0;
	FOR(i,0,n.size())cur+=n[i]-'0';
  cout<<max(cur,(int)(n.size()-1)*9+(n[0]-'1'))<<endl;
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 256
k = input()
d = int(input())

MOD = 10**9 + 7

k_len = len(k)
dp = [[0] * d for _ in range(k_len)]
dp[0][0] = 1

# if( k_len == 1 ):
#     k = int(k)
#     print(k//d)
#     exit()
#
# for i in range(10):
#     dp[0][i%d] += 1

for i in range(1, k_len):
    for j in range(10):
        dp[i][0] += dp[i-1][(0-j)%d]
    dp[i][0] = dp[i][0] % MOD
    for j in range(1,d):
        dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][(j-10)%d]) % MOD

ans = 0
heads = 0
for i in range(k_len):
    pick = int(k[i])
    for j in range(pick):
        ans += dp[k_len - 1 - i][(0 - j - heads) % d]
        ans = ans % MOD
    heads += pick

if(heads % d == 0):
    ans += 1

print((ans - 1)%MOD)


Measured memory_bytes: 50396
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int r = scan.nextInt();
    if(r < 1200){
      System.out.println("ABC");
    }else if(r < 2800){
      System.out.println("ARC");
    }else{
      System.out.println("AGC");
    }
  }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();
        int x3 = 0;
        int y3 = 0;
        int x4 = 0;
        int y4 = 0;

        if (x1 >= x2) {
            y3 = y2 - Math.abs(x1 - x2);
            y4 = y1 - Math.abs(x1 - x2);
        } else {
            y3 = y2 + Math.abs(x1 - x2);
            y4 = y1 + Math.abs(x1 - x2);
        }
        if (y1 >= y2) {
            x3 = x2 + Math.abs(y1 - y2);
            x4 = x1 + Math.abs(y1 - y2);
        } else {
            x3 = x2 - Math.abs(y1 - y2);
            x4 = x1 - Math.abs(y1 - y2);
        }
        System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
    }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
map<ll,ll> ma;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int n,m;  cin >> n >> m;
  vector<vector<int> > v(15),v2(m);
  rep(i,0,m){
    int k;  cin >> k;
    rep(j,0,k){
      int x;  cin >> x;
      --x;
      v[x].pb(i);
      v2[i].pb(x);
    }
  }
  vector<int> p(m);
  rep(i,0,m){
    cin >> p[i];
  }
  int cnt = 0;
  for(int bit=0 ; bit<(1<<n) ; bit++){
    bool ok=true;
    for(int i=0 ; i<m ; i++){
      int con=0;
      for(auto j : v2[i]){
        if(bit & (1<<j)) con++;
      }
      if(con%2!=p[i]) ok=false;
    }
    if(ok) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, k;
long long F[N];

bool read() {
    if (!(cin >> n >> k))
        return false;

    return true;
}

long long binpow(long long a, int n) {
    auto res = 1ll;

    for (; n > 0; n /= 2, a = a * a % MOD)
        if (n & 1)
            res = res * a % MOD;

    return res;
}

long long rev(long long x) {
    return binpow(x, MOD - 2);
}

long long binomial(int n, int k) {
    return n < k ? 0ll : F[n] * rev(F[k] * F[n - k] % MOD) % MOD;
}

void solve() {
    F[0] = 1;

    for (int i = 1; i <= n; ++i)
        F[i] = i * F[i - 1] % MOD;

    for (int i = 1; i <= k; ++i)
        cout << binomial(k - 1, i - 1) * binomial(n - k + 1, i) % MOD << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <limits>

constexpr int MAXN = 100;
int C[MAXN + 1][MAXN + 1];
int M[MAXN][2];

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> M[i][0] >> M[i][1];
    }

    for (int i = 0; i < n; i++) {
        C[i][i] = 0;
    }

    for (int j = 1; j < n; j++) {
        for (int i = j - 1; i >= 0; i--) {
            C[i][j] = std::numeric_limits<int>::max();
            for (int k = i; k < j; k++) {
                C[i][j] = std::min(C[i][j], C[i][k] + C[k+1][j] + M[i][0] * M[j][1] * M[k][1]);
            }
        }
    }
    std::cout << C[0][n-1] << std::endl;
}


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

using namespace std;

typedef struct{
	string name;
	int Anum;
	int Pnum;
}DATA;

int main(void){
	std::ios_base::sync_with_stdio();

	DATA goast[10];

	for(int i=0;i<9;i++){
		cin>>goast[i].name>>goast[i].Anum>>goast[i].Pnum;
	}
	for(int i=0;i<9;i++){
		cout<<goast[i].name<<" ";
		cout<<goast[i].Anum+goast[i].Pnum<<" ";
		cout<<goast[i].Anum*200+goast[i].Pnum*300<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define alla(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000000;

int n, m;


int main(){
  cin >> n >> m;
  vector<vector<int>> connected(m,vector<int>());
  rep(i, m){
    int k;
    cin >> k;
    rep(j, k){
      int s;
      cin >> s;
      connected.at(i).push_back(s);
    }
  }
  /*rep(i, m){
    for(int x:connected.at(i)){
      cout << x << " ";
    }cout <<endl;
  }*/
  bitset<10> p;
  rep(i, m){
    int p_p;
    cin >> p_p;
    if(p_p == 1) p.set(i);
  }
  int ans = 0;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<10> bulb;
    bitset<10> s(tmp); //1になっているスイッチをオン
    rep(i, m){//電球のつながっている先のスイッチがオンになっているかどうか
      for(int x:connected.at(i)){
        if(s.test(x-1)){
          bulb.flip(i);
        }
      }
    }
    //cout << bulb << " " << p <<endl;
    if((~(bulb^p)).all()) ans++;
  }
  cout << ans <<endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	long double N;
	cin >> N;

	Int temp1 = N / 1.08;
	Int temp2 = temp1 * 1.08;
	Int temp3 = (temp1 + 1) * 1.08;
	if (temp2 == N) {
		cout << temp1 << "\n";
		return 0;
	}
	if (temp3 == N) {
		cout << temp1+1 << "\n";
		return 0;
	}

	cout << ":(" << "\n";
}


Measured memory_bytes: 256
N,M,*X=`dd`.split.map(&:to_i)
h=Hash.new{|h,k|h[k]=[]}
X.each{|e|h[e%M]<<e}
r=0
q=[0]*M
(0...M).each{|i|
	opp=M-i
	opp=0 if opp==M
	if i==opp
		s=h[i].size/2
		q[i]=s*2
	else
		s=[h[i].size,h[opp].size].min
		q[i]=q[opp]=s
	end
	t=h[i].group_by{|e|e}.reduce(0){|s,(k,v)|s+v.size/2}
	r+=[(h[i].size-q[i])/2,t].min
	i<=M/2&&r+=s
}
p r

Measured memory_bytes: 26888
#include <stdio.h>
#include <string.h>

char* strrev(char *target, char *str)
{
	int i;
	int len;

	len = strlen(str);
	for (i = 0; i < len; i++){
		target[len - i - 1] = str[i];
	}
	target[len] = '\0';

	return (target);
}

int isPalindrome(char *str)
{
	char rev[128];

	strrev(rev, str);
	
	if (strcmp(rev, str) != 0){
		return (0);
	}
	else {
		return (1);
	}
}

int main(void)
{
	char str[128];
	int count_palindrome;

	count_palindrome = 0;
	while (~scanf("%s", str)){
		count_palindrome += isPalindrome(str);
	}

	printf("%d\n", count_palindrome);

	return (0);
}

Measured memory_bytes: 556
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int main(){
  string str;
  string ans="CODEFESTIVAL2016";
  cin>>str;
  int aa=0;
  for(int i=0;i<str.length();i++){
    if(str[i]!=ans[i]){
        aa++;
    }
  }
    cout<<aa<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
signed main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    unordered_map<int,int> u;
    for(int i=0;i<n;i++)
    u[a[i]]++;
    unordered_map<int,pii> ans;
    int res=0;
    for(auto x: u)
    {
        ans[x.first]={(x.second*(x.second-1))/2,((x.second-1)*(x.second-2))/2};
        res+=(x.second*(x.second-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<res-ans[a[i]].first+ans[a[i]].second<<endl;
    }
    // int vis[1000000];
    // memset(vis,-1,sizeof(vis));
    // for(int i=0;i<n;i++)
    // {
    //     if(vis[a[i]]!=-1)
    //     {
    //         cout<<vis[a[i]]<<endl;
    //         continue;
    //     }
    //     int ans=0;
    //     for(auto x:u)
    //     {
    //       // cout<<x.first<<" "<<x.second<<endl;
    //         if(x.first==a[i])
    //         {
    //             ans+=((x.second-1)*(x.second-2))/2;
    //         }
    //         else{
    //             ans+=((x.second)*(x.second-1))/2;
    //         }
    //     }
    //     cout<<ans<<endl;
    //     vis[a[i]]=ans;
    // }
}


Measured memory_bytes: 17992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

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


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

int main(){
    int h, w;
    int ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    vector<vector<char>> s(h, vector<char>(w));
    vector<vector<int>> dist(h, vector<int>(w, INF));
    ch--; cw--; dh--; dw--;
    for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
            cin >> s[i][j];
        }
    }

    dist[ch][cw] = 0;
    deque<pair<int, int>> q;
    q.emplace_back(ch, cw);

    while(!q.empty()){
        int y = q.front().first;
        int x = q.front().second;
        q.pop_front();

        int cost = dist[y][x];

        for (int i = 0;i < 4;i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (s[ny][nx] == '#') continue;
            if (dist[ny][nx] <= cost) continue;

            dist[ny][nx] = cost;
            q.emplace_front(ny, nx);
        }

            cost++;
        for (int i = -2;i <= 2;i++){
            for (int j = -2;j <= 2;j++){
                int ny = y + i;
                int nx = x + j;
                if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if (s[ny][nx] == '#') continue;
                if (dist[ny][nx] <= cost) continue;

                dist[ny][nx] = cost;
                q.emplace_back(ny, nx);
            }
        }
    }

    if (dist[dh][dw] == INF) cout << -1 << endl;
    else {
        cout << dist[dh][dw] << endl;
    }

}

Measured memory_bytes: 8512
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
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<P,int> 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=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvi g,a,b;
vi s,t,used;

void dfs(int v,int p){
	a[p][v]=1;
	for(auto u:g[v]) if(!a[p][u]) dfs(u,p);
}

void DFS(int v,int p){
	used[v]=1;
	for(auto u:g[v]) if(!used[u]&&u!=p) DFS(u,p);
}

void f(int v){
	fill(used.begin(),used.end(),0);
	for(auto u:g[v]){
		if(used[u]) b[v][u]=1;
		else DFS(u,v);
	}
	reverse(g[v].begin(),g[v].end());
}

int main(){
	cin>>n>>m;
	g=vvi(n);
	a=b=vvi(n,vi(n));
	used=vi(n);
	s=t=vi(m);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		s[i]=u;t[i]=v;
		g[u].push_back(v);
	}
	for(int i=0;i<n;i++) dfs(i,i);
	for(int i=0;i<n;i++){
		f(i);f(i);
	}
	for(int i=0;i<m;i++){
		int u=s[i],v=t[i];
		cout<<(a[v][u]^b[u][v]?"diff":"same")<<endl;
	}
}

Measured memory_bytes: 13824
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define boolv vector<bool>
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define ull unsigned long long

bool flag = 0;
const ll mod = 1e9 + 7;
const ll N = (ll)5e5 + 4;
// template <typename... T>
// void read(T &... args)
// {
//     ((cin >> args), ...);
// }

// template <typename... T>
// void write(T &&... args) //rvalue references
// {
//     ((cout << args << endl), ...);
//     ans = 1;
// }

void vjudge()
{
#ifndef ONLINE_JUDGE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void solve()
{
    int x, n;
    cin >> x >> n;
    intvect a(n);
    fo(i, n) cin >> a[i];
    sort(all(a));
    int u = upper_bound(all(a), x) - a.begin();
    int v = lower_bound(all(a), x) - a.begin();

    int minn = INT32_MAX;
    int ans;
    Fo(i, 0, 200)
    {
        if (!binary_search(all(a), i))
        {
            if (minn > abs(x - i))
                ans = i;
            minn = min(minn, abs(x - i));
        }
    }
    // if (!binary_search(all(a), minn - x))
    //     cout << minn - x;
    // else if (!binary_search(all(a), x - minn))
    //     cout << x - minn;
    // else
    //     cout << x + minn;
    // cout << " " << ans;
    cout << ans;
}

int main()
{
    vjudge();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  int c=0; for(int i=0; i<n; i++){if(s[i]=='R') c++;}
  int w=0; for(int i=0; i<c; i++){if(s[i]!='R') w++;}
  int r=0; for(int i=c; i<n; i++){if(s[i]!='W') r++;}
  cout << ((w>r)?w:r) << endl;
}

Measured memory_bytes: 3736
<?php

$format = array(
    '%d %s %d %s %d %s %d',
    '(%d %s %d %s %d) %s %d',
    '((%d %s %d) %s %d) %s %d',
    '(%d %s (%d %s %d)) %s %d',
    '%d %s (%d %s %d %s %d)',
    '%d %s ((%d %s %d) %s %d)',
    '%d %s (%d %s (%d %s %d))',
    '(%d %s %d) %s %d %s %d',
    '%d %s (%d %s %d) %s %d',
    '%d %s %d %s (%d %s %d)',
    '(%d %s %d) %s (%d %s %d)'
);

while (($line = trim(fgets(STDIN))) !== '0 0 0 0') {
    sscanf($line, '%d %d %d %d', $a, $b, $c, $d);
    $group = getGroup($a, $b, $c, $d);
    $result = 0;
    foreach ($format as $f) {
        foreach ($group as $g) {
            $ptn = getPattern($f, $g);
            foreach ($ptn as $str) {
                eval("\$n = $str;");
                if ($n === 10) {
                    $result = $str;
                    break 3;
                }
            }
        }
    }

    echo $result, PHP_EOL;
}

function getGroup($a, $b, $c, $d)
{
    $arr = array($a, $b, $c, $d);
    $group = array();
    $check = array();
    for ($i = 0; $i < 4; $i++) {
        for ($j = 0; $j < 4; $j++) {
            if ($i === $j) {
                continue;
            }
            for ($k = 0; $k < 4; $k++) {
                if ($i === $k || $j === $k) {
                    continue;
                }
                $l = 6 - $i - $j - $k;
                $arr2 = array($arr[$i], $arr[$j], $arr[$k], $arr[$l]);
                $str = implode(',', $arr2);
                if (!in_array($str, $check)) {
                    $check[] = $str;
                    $group[] = $arr2;
                }
            }
        }
    }

    return $group;
}

function getPattern($format, $group)
{
    $ptn = array();
    $arr = explode(',', '+,-,*');
    list($a, $b, $c, $d) = $group;
    for ($i = 0; $i < 3; $i++) {
        for ($j = 0; $j < 3; $j++) {
            for ($k = 0; $k < 3; $k++) {
                $ptn[] = sprintf($format, $a, $arr[$i], $b, $arr[$j], $c, $arr[$k], $d);
            }
        }
    }
    return $ptn;
}

Measured memory_bytes: 6748
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 300;
int a[N][N], b[N][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &a[i][j]);
      b[i][j] = a[i][j];
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
      }
    }
  }
  bool found = false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a[i][j] != b[i][j]) {
        found = true;
      }
    }
  }
  if (found) {
    puts("-1");
    return 0;
  }
  int64 ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      bool found = false;
      for (int k = 0; k < n; ++k) {
        if (k == i || k == j) continue;
        if (a[i][j] == a[i][k] + a[k][j]) found = true;
      }
      if (!found) ret += a[i][j];
    }
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
#define swap(type, x, y)  do{ type t = x; x = y; y = t; }while(0)

void quick(int array[], int left, int right){
  int pl = left, pr = right, x = array[(left + right) / 2];
  do{
    while(array[pl] > x)  pl++;
    while(array[pr] < x)  pr--;
    if(pl <= pr){
      swap(int, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)  quick(array, left, pr);
}

int main(){
  long n, k;
  scanf("%ld %ld", &n, &k);
  int h[200005];
  for(int i=0; i<n; i++)  scanf("%d", h+i);
  if(n <= k){
    printf("0\n");
    return 0;
  }

  quick(h, 0, n-1);

  long ans = 0;
  for(int i=k; i<n; i++)
    ans = ans + h[i];

  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 5;
const int INF = 0x7f7f7f7f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\n'

int n, s, t, f[MAXN];
ll f_pow(ll a, ll b){
    ll res = 1;
    for(; b; b >>= 1, a = a * a % p)
        if(b & 1) res = res * a % p;
    return res;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    cin >> n >> s;
    f[0] = f_pow(2, n);
    ll inv2 = f_pow(2, p - 2);
    for(int i = 1; i <= n; i++){
        cin >> t;
        for(int j = s - t; j >= 0; j--)
            f[j+t] = (f[j+t] + f[j] * inv2) % p;
    }
    cout << f[s];
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<pair<int,int>> c(100001),d(100001);
  for(int i=1;i<100001;i++){
    c[i]={0,i};
    d[i]={0,i};
  }
  for(int i=0;i<n;i++){
    int a;cin >> a;
    if(i%2==0){
      c[a].first++;
    }
    else{
      d[a].first++;
    }
  }
  sort(c.begin(),c.end(),greater<pair<int,int>>());
  sort(d.begin(),d.end(),greater<pair<int,int>>());
  if(c[0].second==d[0].second){
    cout << n-max(c[0].first+d[1].first,c[1].first+d[0].first) << endl;
  }
  else{
    cout << n-c[0].first-d[0].first << endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll =  long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }


	// 標準入出力
	struct inp {
		std::size_t sz;
		inp(std::size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one

	struct Monster {
	public:
		int x;
		int h;
		int need;
	};
}

int main() {

	int n, d, a;
	cin >> n >> d >> a;
	vector<Monster> monster(n);
	vector<int> x(n);
	rep(i, n) {
		cin >> monster[i].x >> monster[i].h;
		x[i] = monster[i].x;
	}
	ll ans = 0;

	sort(allof(x));
	sort(allof(monster), [&](Monster lhs, Monster rhs) {
		return lhs.x < rhs.x;
		});

	// 何回必要かに置き換える
	rep(i, n) {
		if (monster[i].h % a) monster[i].need = monster[i].h / a + 1;
		else monster[i].need = monster[i].h / a;
	}

	// queue
	// 左から貪欲
	queue<pll> que; // firstにどこまでか，secondに爆発回数
	int num = 0; // 爆発回数
	rep(i, n) {
		while (!que.empty() and que.front().first < i) {
			num -= que.front().second;
			que.pop();
		}
		if (monster[i].need > num) {
			int cnt = monster[i].need - num;
			if (cnt < 0) continue;
			ans += cnt;
			// どこまで影響がでるか
			int to = upper_bound(allof(x), x[i] + 2 * d) - x.begin() - 1;
			que.push(make_pair(to, cnt));
			num += cnt;
		}
	}

	// 完全理解 図に加工

	Cout(ans);

	return 0;
}

Measured memory_bytes: 4992
main = do
  s <- getContents
  mapM_ putStrLn $ map func $ lines s

func:: [Char] -> [Char]
func [] = []
func ('@':xs) = func2 (head xs) (head (tail xs)) ++ func (tail (tail xs))
func (x:xs) = x : func xs

c_to_i c = (read (c:[])) :: Int


func2 c s = replicate (c_to_i c) s

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  int n,i,j;
  cin >> n;
  int u[n];
  int k[n];
  int G[n][n];

  rep(i,n){
    rep(j,n){
      G[i][j]=0;
    }
  }
   
  rep(i,n){
    cin >> u[i] >> k[i];
    int v=k[i];
    int v2[v];
    rep(j,v){
      cin >> v2[j];
      G[u[i]-1][v2[j]-1]=1;
    }
  }

  
  rep(i,n){
    rep(j,n-1){
      cout << G[i][j] <<' ';
    }
    cout << G[i][n-1] << '\n';
  }

  return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = (int) 1e6;
const int MOD = 998244353;

int n, a[20], o[8] = {7, 6, 5, 3, 1, 2, 4, 0};
char s[N];

int get(char ch) {
	if (ch == 'R') {
		return 1;
	} else if (ch == 'G') {
		return 2;
	} else {
		return 4;
	}
}

int main() {

	scanf("%d %s", &n, s);

	memset(a, 0, sizeof a);

	a[0] = n;

	long long res = 1;

	for (int i = 0; i < 3 * n; i++) {
		int m = get(s[i]);
		for (int j = 0; j < 8; j++) {
			int mask = o[j];
			if ((mask & m) == 0 && a[mask] > 0) {
				res = res * a[mask] % MOD;
				a[mask]--;
				a[mask | m]++;
				break;
			}
		}
	}

	printf("%lld\n", res);

	return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
vector<P> graph[110000];
int dist[110000];
const int INF = 1001001001001ll;
signed main(){
    int v,e,r;cin >> v >> e >> r;
    rep(i,e){
        int s,t,d;cin >> s>> t >> d;
        graph[s].emplace_back(t,d);
    }
    rep(i,110000)dist[i] = INF;
    priority_queue<P,vector<P>,greater<P>> q;
    q.emplace(0,r);
    dist[r] = 0;
    while(q.size()){
        auto hoge = q.top();q.pop();
        int now = hoge.second,d = hoge.first;
        if(dist[now] < d)continue;
        for(auto next:graph[now]){
            if(dist[next.first]  > dist[now] +next.second ){
                dist[next.first]  = dist[now] +next.second;
                q.emplace(dist[next.first],next.first);
            }
        }
    }
    rep(i,v){
        if(dist[i] == INF)cout << "INF" << endl;
        else cout << dist[i] << endl;
    }

    

    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

struct edge{
  int to, id;
};

ll dfs(int now, int par, int dst, vector<vector<edge>> &G){
  if(now == dst) return 0;

  ll res = -1;
  for(auto &e: G[now]){
    if(e.to == par) continue;
    ll val = dfs(e.to, now, dst, G);
    if(val>=0){
      val |= (1ll<<e.id);
      chmax(res, val);
    }
  }
  return res;
};

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

    int N;
    cin >> N;
    vector<vector<edge>> G(N);
    REP(i, N-1){
      int a, b;
      cin >> a >> b;
      a--, b--;
      edge e = {b, i};
      edge f = {a, i};
      G[a].push_back(e);
      G[b].push_back(f);
    }

    int M;
    cin >> M;
    vector<ll> masks(M); 
    REP(i, M){
      int u, v;
      cin >> u >> v;
      u--, v--;
      masks[i] = dfs(u, -1, v, G);
    }

    ll res = 0;

    REP(mask, (1ll<<M)){
      ll tmp = 0;
      REP(i, M){
        if(mask>>i & 1){
          tmp |= masks[i];
        }
      }

      ll ne = __builtin_popcountll(tmp);

      ll val = (1ll<<(N-1-ne));

      if(__builtin_popcount(mask)%2){
        res -= val;
      }else{
        res += val;
      }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n,k,d,a;
	cin>>n>>k;
	set<int> ms;
	while(k--){
		cin>>d;
		while(d--){
			cin>>a;
			ms.insert(a);
		}
	}
	cout<<n-ms.size()<<endl;
	
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1> {}(p.first);
        auto h2 = hash<T2> {}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "NO";
    exit(0);
}
const int NMAX = 2 * 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

#define index INDEX
int h, w, n;
int v[NMAX];
pair<int, int> cur;
bool dir;
int sol[105][105];
int index = 1;

int main()
{
    FASTIO;
    cin >> h >> w >> n;
    for1(i, n) cin >> v[i];
    cur = mp(1, 1);
    while(v[n])
    {
        if(v[index] == 0) index++;
        sol[cur.first][cur.second] = index;
        print(cur.first);
        print(cur.second);
        print("\n");
        v[index]--;
        if(dir == 0)
        {
            cur.second++;
            if(cur.second == w + 1)
            {
                cur.second = w;
                dir = 1;
                cur.first++;
            }
        }
        else
        {
            cur.second--;
            if(cur.second == 0)
            {
                cur.second = 1;
                dir = 0;
                cur.first++;
            }
        }
    }
    for1(i, h) for1(j, w) cout << sol[i][j] << " \n"[j == w];

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int ar[4];
    ar[0]=a*c,ar[1]=a*d,ar[2]=b*c,ar[3]=b*d;
    sort(ar,ar+4);
    cout<<ar[3];
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        boolean[] pushed = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            pushed[i] = false;
        }

        long count = 0;
        int i = 0;
        while (true) {
            if (pushed[i]) {
                System.out.println(-1);
                return;
            }
            count++;
            if (a[i] == 2) {
                break;
            }
            pushed[i] = true;
            i = a[i] - 1;
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 52124
#include <cstdio>
int main(){
 int d,n,a,b; 
 while(true){
  d=0;
  if (scanf("%d %d",&a,&b)==EOF) break;
  n=a+b;
  while(n>0) { d++, n/=10;  };
  printf("%d\n",d);
 };
 return 0;
};

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

using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int x[maxn],y[maxn];
int main(){ 
     int n;
     scanf("%d",&n);
     for(int i=1;i<=n;++i){ 
        int a,b;
        scanf("%d%d",&a,&b);
        x[i]=a+b;y[i]=a-b;
     }
     sort(x+1,x+1+n);
     sort(y+1,y+1+n);
     cout<<max(y[n]-y[1],x[n]-x[1])<<endl;
}


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

int main() {

	int n,s=0; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) { cin>>a[i]; s+=a[i]; }
	long long int sum=0;
	for(int i=0;i<n;i++) 
		sum+=a[i]*(s-a[i]);
	cout<<sum/2<<endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;

  stack<char> st;
  for (int i = 0; i < s.size(); i++) {
    if (st.size() == 0) {
      st.push(s[i]);
      continue;
    }
    if (s[i] == 'S') {
      st.push(s[i]);
    } else {
      if (st.top() == 'S') {
        st.pop();
      } else {
        st.push(s[i]);
      }
    }
  }

  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 644
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
import collections
cd = collections.Counter(t)
ct = collections.Counter(d)

ans = 1
for i in range(m):
    if ct[t[i]] < cd[t[i]]:
        ans = 0
if ans == 0:
    print("NO")
else:
    print("YES")

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

int findSumOfDigits(int n){
  int sum = 0;
  while (n>0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1;i<=N;i++){
    int sum = findSumOfDigits(i);
    if (sum >=A && sum<=B){
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256