akhauriyash/Code-Regression huggingface dataset:
// dont fuck with my love
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.stream.*;

public class Main
{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            } catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }
    static int modPower(int x, int y, int mod){
        int res = 1;
        x %= mod;
        if(x==0) return 0;
        while(y>0){
            if(y%2==1){
                res = (res*x)%mod;
            }
            y = y>>1;
            x = (x*x)%mod;
        }
        return res;
    }
    public static int[] readArray(int n){
        FastReader in = new FastReader();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = in.nextInt();
        return a;
    }
    static class pair{
        int first, second;
        pair(int first, int second){
            this.first = first;
            this.second = second;
        }
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        FastReader in = new FastReader();
        String s = in.nextLine(), t = in.nextLine();
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i <= s.length() - t.length(); i++) {
            int c = 0;
            for(int j = 0; j < t.length(); j++) {
                if(s.charAt(j+i) != t.charAt(j)) c++;
            }
            ans = Math.min(c, ans);
        }
        System.out.println(ans);
    }
}


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

int main(){
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++){
    if ((i+1) % 2 == 0){
      if (s[i] == 'R'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if (s[i] == 'L'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXSIZE 1005

int h,w;
int tab[MAXSIZE][MAXSIZE];
int dp[MAXSIZE][MAXSIZE];

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>h>>w;
	
	REP(i,h){
		string s;
		cin>>s;
		REP(j,w)
			tab[i][j]=((s[j]=='.')?0:1);
	}
	
	REP(i,h){
		REP(j,w){
			if(i==0&&j==0)
				dp[i][j]=1;
			else{
				if(i==0){
					if(!tab[i][j-1])
						dp[i][j]=dp[i][j-1];
				}
				else if(j==0){
					if(!tab[i-1][j])
						dp[i][j]=dp[i-1][j];
				}
				else{
					if(!tab[i][j-1])
						dp[i][j]+=dp[i][j-1];
					if(!tab[i-1][j])
						dp[i][j]+=dp[i-1][j];
					dp[i][j]%=MOD;
				}
			}
		}
	}
	cout<<dp[h-1][w-1];
	
	return 0;
}


Measured memory_bytes: 8192
c = [list(map(int, input().split())) for _ in range(3)]
if (c[0][0]-c[0][1] == c[1][0]-c[1][1]) and (c[1][0]-c[1][1] == c[2][0]-c[2][1]) and (c[0][1]-c[0][2] == c[1][1]-c[1][2]) and (c[1][1]-c[1][2] == c[2][1]-c[2][2]):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int arraymax(int num[], int x, int y) {
  int ma = 0;
  for(int i = x; i <= y; i++) {
    ma = max(ma, num[i]);
  }
  return ma;
}

int main() {
  int n,h[200];
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> h[i];
  
  int sum = h[0];
  for(int i = 1; i < n; i++) {
    if(h[i] > h[i-1])
			sum += h[i] - h[i-1];
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  string s;
  cin>>s;
  int n=s.size();
  if(s.at(0)=='k'&&s.at(1)=='e'&&s.at(2)=='y'&&s.at(3)=='e'&&s.at(4)=='n'&&s.at(5)=='c'&&s.at(6)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(0)=='k'&&s.at(1)=='e'&&s.at(2)=='y'&&s.at(3)=='e'&&s.at(4)=='n'&&s.at(5)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(0)=='k'&&s.at(1)=='e'&&s.at(2)=='y'&&s.at(3)=='e'&&s.at(4)=='n'&&s.at(n-2)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(0)=='k'&&s.at(1)=='e'&&s.at(2)=='y'&&s.at(3)=='e'&&s.at(n-3)=='n'&&s.at(n-2)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(0)=='k'&&s.at(1)=='e'&&s.at(2)=='y'&&s.at(n-4)=='e'&&s.at(n-3)=='n'&&s.at(n-2)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(0)=='k'&&s.at(1)=='e'&&s.at(n-5)=='y'&&s.at(n-4)=='e'&&s.at(n-3)=='n'&&s.at(n-2)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(0)=='k'&&s.at(n-6)=='e'&&s.at(n-5)=='y'&&s.at(n-4)=='e'&&s.at(n-3)=='n'&&s.at(n-2)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else if(s.at(n-7)=='k'&&s.at(n-6)=='e'&&s.at(n-5)=='y'&&s.at(n-4)=='e'&&s.at(n-3)=='n'&&s.at(n-2)=='c'&&s.at(n-1)=='e'){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;

vector<bool> Prime;
vector<int> PrimeStk;
void initPrime(long num) {
	Prime = vector<bool>(num + 1, true);
	Prime[1] = Prime[0] = false;
	long sq_num = sqrt((double)num);
	for (long i = 2; i < sq_num; i++) {
		if (Prime[i]) {
			for (long j = i + i; j <= num; j += i) {
				Prime[j] = false;
			}
		}
	}
}
void initPrimeStk(long begin) {
	PrimeStk.clear();
	for (long i = begin; i < Prime.size(); i++) {
		if (Prime[i]) {
			PrimeStk.push_back(i);
		}
	}
}

int main(void) {
	initPrime(1299709);
	initPrimeStk(0);

	int N;
	while (cin >> N, N) {
		if (Prime[N]) {
			cout << 0 << endl;
			continue;
		}
		vector<int>::iterator it = upper_bound(PrimeStk.begin(), PrimeStk.end(), N);

		cout << *it - *(it - 1) << endl;
	}


	return 0;
}

Measured memory_bytes: 1880
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, k = sp()
graph = dd(set)
for i in range(k):
    d = int(data())
    arr = l()
    for j in arr:
        graph[j].add(i+1)
answer = 0
for i in range(1, n+1):
    if len(graph[i]) == 0:
        answer += 1
out(answer)


Measured memory_bytes: 73136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,b,a) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define debug(x) cerr<<#x" = "<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nex)
typedef pair<int,int> pii;
typedef long long ll;
const int inf=~0u>>1,MOD=1e9+7;/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=((TT=but)+fread(but,1,1<<15,stdin)),TT==mo))?-1:*TT++)//*/
inline int rd() {
	int x=0,c=0,f=1;
	for(; c<'0'||c>'9'; c=getchar())f=c!='-';
	for(; c>='0'&&c<='9'; c=getchar())x=x*10+c-'0';
	return f?x:-x;
}
const int N=2e5+11;
int n,A[N],B[N],C[N],Log[N];
struct ST{
	int mi[25][N],*f;
	void init(int *g){
		f=g;
		rep(i,1,n)mi[0][i]=i;
		for(int i=1;(1<<i)<=n;i++){
			for(int j=1;j+(1<<i)-1<=n;j++){
				mi[i][j]=mi[i-1][j];
				if(f[mi[i-1][j+(1<<i-1)]] < f[mi[i][j]])
					mi[i][j] = mi[i-1][j+(1<<i-1)];
			}
		}
	}
	int query(int l,int r){
		int c=Log[r-l+1];
		int t=mi[c][l];
		if(f[mi[c][r-(1<<c)+1]]<f[t])
			return mi[c][r-(1<<c)+1];
		else return t;
	}
} st[2];
int Ans[N],cnt;
struct node{
	int x,y,l,r;
	bool operator<(const node&t)const{
		return A[x]>A[t.x];
	}
};
priority_queue<node> H;
pii calc(int l,int r){
	int x=st[l&1].query(l,r-1);
	int y=st[x+1&1].query(x+1,r);
	return mp(x,y);
}
int main(){
	n=rd();
	Log[0]=-1;
	rep(i,1,n)Log[i]=Log[i>>1]+1;
	rep(i,1,n)A[i]=rd();
	
	rep(i,1,n)B[i]=(i+1&1)?A[i]:inf;
	st[0].init(B);
	rep(i,1,n)C[i]=(i&1)?A[i]:inf;
	st[1].init(C);
	
	int x,y;
	/*
	while(cin>>x>>y){
		cout<<st[0].query(x,y)<<endl;
		cout<<st[1].query(x,y)<<endl;
	}//*/
	pii tmp=calc(1,n);
	H.push((node){tmp.x,tmp.y,1,n});
	while(!H.empty()){
		node x=H.top();H.pop();
		//debug(x.l),debug(x.r),debug(x.x),debug(x.y);
		Ans[++cnt]=A[x.x],Ans[++cnt]=A[x.y];
		if(x.x!=x.l) {
			tmp=calc(x.l,x.x-1);
			H.push((node){tmp.x,tmp.y,x.l,x.x-1});
		}if(x.x+1!=x.y){
			tmp=calc(x.x+1,x.y-1);
			H.push((node){tmp.x,tmp.y,x.x+1,x.y-1});
		}if(x.y!=x.r){
			tmp=calc(x.y+1,x.r);
			H.push((node){tmp.x,tmp.y,x.y+1,x.r});
		}
	}
	rep(i,1,n)printf("%d%c",Ans[i]," \n"[i==n]);
}

Measured memory_bytes: 39028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;


int main()
{
    Go_
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    
    cin>>n>>k;

    ct=0;
    while(n) n/=k,++ct;
    cout<<ct<<endl;
    
}

Measured memory_bytes: 256
s = list(input())
lis = []
for i in range(len(s)):
    if s[i] == '1' or s[i] == '0':
        lis.append(s[i])
    elif len(lis) >= 1 and s[i] == 'B':
        lis.pop(-1)
ans = lis[0]
for i in range(1, len(lis)):
    ans += lis[i]
print(ans)


Measured memory_bytes: 3060
#include "stdio.h"
#include <stdlib.h>
 
int main (){
  int N, A, B;
  scanf("%d %d %d",&N, &A, &B);

  int answer=0;
  if (N*A>=B){
    answer=B;
  } else {
    answer=N*A;
  }
  printf("%d\n",answer);

  return 0;
}

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

using namespace std;

typedef long long ll;

int gre[4005][4005]={}, gere[4005][4005]={};
ll dp[4005][4005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	vector<int> a(2*n);
	
	map<int,int> mp;
	for(int i=0;i<2*n;i++){
		char p;
		cin >> p >> a[i];
		a[i]--;
		if(p=='B'){
			a[i]+=n;
		}
		mp[a[i]]=i;
	}
	
	for(int i=0;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			if(i)
				gre[i][j]=gre[i-1][j], gere[i][j]=gere[i-1][j];
			
			if(j<n){
				gre[i][j]+=(a[i]<n)&&(a[i]>j);
				gere[i][j]+=(a[i]<n)&&(a[i]>=j);
			}
			else{
				gre[i][j]+=(a[i]>j);
				gere[i][j]+=(a[i]>=j);
			}
		} 
	}
	
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	
	for(int i=0;i<2*n;i++){
		for(int j=0;j<=n;j++){
			if(j>i)
				continue;
			
			int lw=j, lb=i-j;
			
			if(lw<n){
				int indw = mp[lw];
				
				dp[i+1][j+1]=min(dp[i+1][j+1], dp[i][j]+gre[indw][lw]+((lb>0)?gre[indw][lb+n-1]:gere[indw][n]));
			}
			if(lb<n){
				int indb = mp[lb+n];
				
				dp[i+1][j]=min(dp[i+1][j], dp[i][j]+gre[indb][lb+n]+((lw>0)?gre[indb][lw-1]:gere[indb][0]));
			}
			
		}
	}
	
	cout << dp[2*n][n] << endl;
	return 0;
}

Measured memory_bytes: 251008
// bfs

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<string> field;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int tmp_max = 0;

int main(){
  int h, w;
  cin >> h >> w;

  field.resize(h);
  for(int i = 0; i < h; ++i)cin >> field[i];

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(field[i][j] == '#')continue;

      int sy, sx;
      sy = i;
      sx = j;

      vector<vector<int>> dist(h, vector<int>(w, -1)); // init
      queue<pair<int, int>> que;

      dist[sy][sx] = 0;
      que.push(make_pair(sx, sy));

      while(!que.empty()){
        pair<int, int> v = que.front();
        que.pop();

        for(int i = 0; i < 4; ++i){
          int nx = v.first + dx[i];
          int ny = v.second + dy[i];

          if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
          if(field[ny][nx] == '#')continue;

          if(dist[ny][nx] != -1)continue;

          dist[ny][nx] = dist[v.second][v.first] + 1;
          tmp_max = max(tmp_max, dist[ny][nx]);
          que.push(make_pair(nx, ny));
        }
      }
    }
  }

  cout << tmp_max << endl;
}


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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

struct UnionFind {
  vint par ;  //iの親
  vint rank ; //木の深さ
  vll siz ; //iの属する集合の要素数
  
  //n要素の初期化
  void init(int n){
    REP(i,n){
      par.PB(i) ;
      rank.PB(0) ;
      siz.PB(1) ;
    }
  }
  
  //木の根を求める
  //根が一緒なら同じ集合と判断するため
  int find(int x){
    if(par[x]==x){
      return x ;
    }
    else{
      return par[x] = find(par[x]) ;
    }
  }
  
  //木の併合
  //記録してあるrankをもとに併合
  void unite(int x,int y){
    x = find(x) ;
    y = find(y) ;
    if(x==y){
      return ;
    }
    
    if(rank[x] < rank[y]){
      par[x] = y ;
      siz[y] += siz[x] ;
    }
    else{
      par[y] = x ;
      siz[x] += siz[y] ;
      if(rank[x]==rank[y]){
        rank[x]++ ;
      }
    }
  }
  
  //xとyが同じ集合に属するか
  bool same(int x,int y){
    return find(x) == find(y) ;
  }
  
  //iが根であるかを返す
  bool root(int x){
    return x==find(x) ;
  }
    
  
  //xの属する集合の要素数を返す
  ll size(int x){
    return siz[find(x)] ;
  }
  
  //グラフ全体で何個の集合があるか返す
  ll cnt(int n){
    ll res = 0 ;
    REP(i,n){
      if(i==find(i)){
        res++ ;
      }
    }
    return res ;
  }
  
};


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m ;
  cin >> n >> m ;
  vll ans(m,0) ;
  
  UnionFind tree ;
  tree.init(n) ;
  
  UnionFind memo ;
  memo.init(n) ;
  
  vpii pai(m) ;
  
  REP(i,m){
    int a, b ;
    cin >> a >> b ;
    pai[i] = MP(a-1,b-1) ;
    memo.unite(a-1,b-1) ;
  }
  
  reverse(ALL(pai)) ;
  
  
  ans[0] = 0 ;
  
  REP(i,n){
    if(memo.root(i)){
      ans[0] += memo.size(i)*(memo.size(i)-1)/2 ;
    }
  }
  
  REP(i,m-1){
    int A, B ;
    A = pai[i].FI ;
    B = pai[i].SE ;
    if(!tree.same(A,B)){
      ans[i+1] = ans[i] - (tree.size(A)*tree.size(B)) ;
    }
    else{
      ans[i+1] = ans[i] ;
    }
    tree.unite(A,B) ;
  }
  
  REP(i,m){
    cout << ans[m-i-1] <<endl ;
  }

  return 0 ;
}



Measured memory_bytes: 7144
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
	        var p = Console.ReadLine().Split().Select(s=>long.Parse(s)).OrderBy(i=>i).AsEnumerable();
            Console.WriteLine(p.Aggregate(p.First(),(s,n)=>gcd(s,n)));
        }
        public static long gcd(long a,long b)
        {
            return b == 0 ? a : gcd(b, a % b);
        }
    }
}

Measured memory_bytes: 26592
#include<stdio.h>
char str[128];
int g[7][2]={{1,2},{6,3},{1,6},{4,5},{5,2},{2,1},{6,6}};
int main(){
	while(1){
		scanf("%s",str);
		if(str[0]=='#')return 0;
		int now=0;
		for(int i=0;str[i];i++)now=g[now][str[i]-'0'];
		if(now==5)printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 944
#include<iostream>
#include<queue>
#include<algorithm>
#include <limits.h> 
#define MAX 20
#define DMAX 10
using namespace std;

class Point{
    public:
    int y, x;
    Point(){}
    Point( int y, int x ): y(y), x(x){}
    bool operator == ( const Point &p ) const{
        return ( x == p.x && y == p.y );
    }
};

int W, H;
char G[MAX][MAX];
Point start;
Point dirty[DMAX];
int dsize;
int T[DMAX]; // start to all dirty;
int M[DMAX][DMAX]; // all dirty to all dirty

int bfs( Point p1, Point p2 ){
    bool visited[MAX][MAX];
    int d[MAX][MAX];
    queue<Point> q;
    
    for ( int i = 0; i < H; i++ ){
        for ( int j = 0; j < W; j++ ){
            visited[i][j] = false;
            d[i][j] = INT_MAX;
        }
    }
    
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, -1, 0, 1};
    
    q.push( p1 );
    d[p1.y][p1.x] = 0;
    
    Point u;
    
    while ( !q.empty() ){
        u = q.front(); q.pop();
        
        if ( u == p2 ) return d[u.y][u.x];
        
        int nx, ny;
        for ( int r = 0; r < 4; r++ ){
            ny = u.y + dy[r];
            nx = u.x + dx[r];
            
            if ( !( 0 <= nx && 0 <= ny && ny < H && nx < W ) ) continue;
            
            if ( !visited[ny][nx] && G[ny][nx] != 'x' ){
                visited[ny][nx] = true;
                d[ny][nx] = d[u.y][u.x] + 1;
                q.push( Point( ny, nx ) );
            }
        }
    }
    
    return INT_MAX;
}

void computeDistanceTable(){
    for ( int i = 0; i < dsize; i++ ){
        T[i] = bfs( start, dirty[i]);
    }
    for ( int i = 0; i < dsize-1; i++ ){
        for ( int j = i; j < dsize; j++ ){
            if ( i == j ) M[i][j] = M[j][i] = 0;
            M[i][j] = M[j][i] = bfs( dirty[i], dirty[j] );
        }
    }
}

int getMinimumMove(){
    int order[DMAX];
    for ( int i = 0; i < dsize; i++ ){
        order[i] = i;
    }
    
    int minMove = INT_MAX;
    
    do{
        int move = T[ order[0] ];
        
        for ( int i = 1; i < dsize; i++ ){
            move += M[ order[i-1] ][ order[i] ];
        }
        
        if ( minMove > move ) minMove = move;
        
    } while( next_permutation(order, order + dsize )) ;
    
    return minMove;
}

bool notReachable(){
    for ( int i = 0; i < dsize; i++ ){
        if ( T[i] == INT_MAX ) return true;
    }
    return false;
}

void compute(){
    computeDistanceTable();
    if ( notReachable() ) cout << "-1" << endl;
    else {
        cout << getMinimumMove() << endl;
    }
}

bool read(){
    cin >> W >> H;
    if ( W == 0 && H == 0 ) return false;
    dsize = 0;
    char ch;
    for ( int i = 0; i < H; i++ ){
        for ( int j = 0; j < W; j++ ){
            cin >> ch;
            G[i][j] = ch;
            if ( ch == 'o' ){
                start = Point(i, j);
            } else if ( ch == '*' ){
                dirty[dsize++] = Point(i, j);
            }
        }
    }
    return true;
}

main(){
    while ( read() ) compute();
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a[3];
    cin >> a[0] >> a[1] >>  a[2];
    sort(a,a + 3);
    intl k;
    cin >> k;
    cout << a[0] + a[1] + (a[2] * (intl)pow(2,k)) << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == 'o') ++counter;
    if (s[1] == 'o') ++counter;
    if (s[2] == 'o') ++counter;
    cout << (counter*100 + 700) << endl;
}

Measured memory_bytes: 256
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N=int(input())
    T=list(map(int,input().split()))
    M=int(input())
    P, X = [0] * M, [0] * M
    for i in range(M):
        P[i], X[i] = map(int, input().split())

    for i in range(M):
        print(sum(T)-T[P[i]-1]+X[i])

resolve()

Measured memory_bytes: 3064
#include<stdio.h>

int search(int a[], int n, int key){
        int i=0;
        while(1){
                if(a[i]==key){
                        break;
                }
                i++;
        }
        return i==n?-1:i;
}

int main(){
        int i, n, q, count=0;
        scanf("%d", &n);
        int s[n+1];
        for(i=0;i<n; i++){
                scanf("%d", &s[i]);
        }
        scanf("%d", &q);
        for(i=0; i<q; i++){
                scanf("%d", &s[n]);
                if(search(s, n, s[n])!=-1)
                        count++;
        }
        printf("%d\n", count);
        return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    vector<vector<int> > c(3,vector<int> (3,0));
    rep(i,0,3) {
        rep(j,0,3) {
            cin >> c[i][j];
        }
    }
    bool j=true;
    rep(i,1,3) {
        if (!(c[i][0]-c[0][0]==c[i][1]-c[0][1]&&c[i][0]-c[0][0]==c[i][2]-c[0][2])) j=false;
    }
    if (j) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a * b) / 2 << endl;
    return 0;
}

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

int main()
{
    string str;
    cin >> str;
    vector<int> p(26,0);
    for(int i = 0; i < str.size(); i++){
        p[str[i] - 'a']++;
    }

    bool ex = true;
    for(int i = 0; i < 26; i++){
        if(p[i] % 2 == 1){
            ex = false;
            break;
        }
    }

    if(ex) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v;
int main() {
	int n[10000], m[10000], i; char s[10000]; i = 0;
	for (int i = 0;;i++) {
		cin >> n[i] >> s[i] >> m[i];
		if (s[i] == '+') {
			v.push_back(n[i] + m[i]);
		}
		else if (s[i] == '-') {
			v.push_back(n[i] - m[i]);
		}
		else if (s[i] == '*') {
			v.push_back(n[i] * m[i]);
		}
		else if (s[i] == '/') {
			v.push_back(n[i] / m[i]);
		}
		else
			break;
	}
	for (int j = 0; j < v.size(); j++) {
		cout << v[j] << endl;
	}
}


Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll H,W; cin >> H >> W;
  if(H==1 || W==1) cout << 1 << endl;
  else cout << (H*W+1)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np

n=int(input())
tmp=input()
a=[int(k) for k in tmp.split()]
tmp=input()
b=[int(k) for k in tmp.split()]
x=int(0)

a_arr = np.array(a)
b_arr = np.array(b)
c_arr = a_arr - b_arr
c_arr.sort()

if sum(a_arr) < sum(b_arr) :
    x=-1
elif c_arr[0]>=0:
    x=0
else:
    minus_arr= c_arr[c_arr<0]
    m_=len(minus_arr)
    pls_arr= c_arr[c_arr>0]
    m=sum(minus_arr)
    pls=pls_arr.tolist()
    pls.sort()
    pls.reverse()
    i=int(0)
    pls_=int(0)
    while i <= -m :
        i = i + pls.pop(0)
        pls_=pls_+1
    x=m_+pls_

print(x)

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

#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define per(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
#define rep0(i, a) for (int i = 0, i##end = a; i < i##end; ++i)
#define per0(i, a) for (int i = (int)a-1; ~i; --i)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
#define enter putchar('\n')

typedef long long ll;
typedef double DB;

const DB eps = 1e-12;

int sgn(DB x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); }

struct Point {
	DB x, y;
	Point(DB x = 0, DB y = 0) : x(x), y(y) {}
	Point operator + (Point a) { return Point(x + a.x, y + a.y); }
	Point operator - (Point a) { return Point(x - a.x, y - a.y); }
	Point operator - () { return Point(-x, -y); }
	friend Point operator * (DB k, Point a) { return Point(k * a.x, k * a.y); }
	DB operator % (Point a) { return x * a.x + y * a.y; }
	DB operator / (Point a) { return x * a.y - y * a.x; }
	operator DB() { return sqrt(x*x + y*y); }
};

Point gp() { Point a; scanf("%lf%lf", &a.x, &a.y); return a; }
void wp(Point a) { printf("%.10lf %.10lf ", a.x, a.y); }

struct Poly {
	std::vector<Point> a;
	Poly(int n = 0) { a.resize(n); rep0(i, n) a[i] = gp(); }
	int size() { return a.size(); }
	Point &operator [] (int i) { int n = size(); return a[i >= n ? i-n : i]; }
};

DB Area(Poly A) {
	DB res = 0;
	rep(i, 2, A.size()-1) res += (A[i]-A[0])/(A[i-1]-A[0]);
	return fabs(res)/2;
}

int Direct2(Point P, Point P1, Point P2) { return sgn((P1-P)/(P2-P)); }

bool IsConvex(Poly A) {
	bool f1 = 1, f2 = 1;
	rep0(i, A.size()) {
		int t = Direct2(A[i], A[i+1], A[i+2]);//sgn((A[i+1]-A[i])/(A[i+2]-A[i+1]));
		t && (t == 1 ? f1 = 0 : f2 = 0);
	}
	return f1 || f2;
}

int q;

int main() {
	scanf("%d", &q);
	printf("%d\n", IsConvex(Poly(q)));
	/*
	scanf("%d", &q);
	while (q--) {
		Point P1 = gp(), P2 = gp(), Q1 = gp(), Q2 = gp();
		printf("%.10lf\n", SegDist(P1, P2, Q1, Q2));
		//wp(GetSegInter(P1, P2, Q1, Q2)); enter;
		//printf("%d\n", IsInter(P1, P2, Q1, Q2));
		//wp(Proj(P, P1, P2)); enter;
	}*/
	return 0;
}


Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/


const long long mod = 1e+7 ;
const int N = 1e5+5;
const double PI=acos(-1);


#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i,l,m) for(ll i=l;i<m;i++)
#define frr(i,l,m) for(int i=l;i>m;i--)
# define vii vector<int>
#define vll vector<ll>
#define vpr vector<pair<ll,ll> >
#define dbg(x) cout << #x << " is " << x << endl;
#define gcd(l,r) __gcd(l,r)
#define cd complex<double>
#define vcd vector<cd>
#define clr(x) memset(x,0,sizeof(x))
/*
pow(2,20)->1e6;
pow(2,30)->1e9;
stoll - string to ll;
string with space getline(cin, str);
*/
ll pwr(ll x,ll y, ll m);
ll mult(ll a,ll b,ll m);

////

///
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);

int n,w;
cin>>n>>w;
int wt[n+5],ct[n+5];
fr(i,1,n+1)
{
    cin>>wt[i]>>ct[i];
}
ll dp[n+5][w+5];
clr(dp);
fr(i,1,n+1)
{
    fr(j,1,w+1)
    {
        if(wt[i]<=j)
        {
            dp[i][j]=max(dp[i-1][j-wt[i]]+ct[i],dp[i-1][j]);
        }
        else
        {
            dp[i][j]=dp[i-1][j];
        }
    }
}
cout<<dp[n][w]<<endl;
return 0;

 }
 ////
 ////

ll pwr(ll x,ll y,ll m)
{ll ans=1;x=x%m;while(y){if(y&1)ans=(x*(ans%m))%m;x=(x*x)%m;y>>=1;}
return ans%mod;}
////
////
ll mult(ll x,ll y, ll m){
    ll ans=0;
    while(y){if(y&1)ans=(ans+x)%m;
x=(x+x)%m;
y>>=1;}
return ans%m;}


Measured memory_bytes: 82304
public class Main {


		public static void main(String[] args) {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int n = scan.nextInt(); 
		int i;
	
		if(3 <= n && n <= 10000){
			for(i = 1; i <= n; i++){
				if(i % 3 == 0 || i % 10 == 3 || i/10 % 10 == 3 || i/100 % 10 == 3 || i/1000 % 10 == 3){
					
				System.out.print(" "+ i);
				}
				}
	
		}
		System.out.println();
		
		}
			
			
		}

Measured memory_bytes: 28380
#include <bits/stdc++.h>
using namespace std;
 
#define hell 1000000007
#define PI acos(-1.0)
#define S second
#define F first
#define lli long long int
#define li long int
#define ld long double
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define run(j, n) for(auto ii=j;ii!=n;ii++)
#define out(j, n) for(auto ii=j;ii!=n;ii++) cout<<(*ii)<<" ";




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


int n;cin>>n;
int ar[]={0, 0, 0, 0};
string v[]={"AC", "WA", "TLE", "RE"};
for(int i=0;i<n;i++)
{
  string s;cin>>s;
  if(s=="AC") ar[0]+=1;
  else if(s=="WA") ar[1]+=1;
  else if(s=="TLE") ar[2]+=1;
  else if(s=="RE") ar[3]+=1;

}
for(int i=0;i<4;i++)
{
   cout<<v[i]<<" x "<<ar[i]<<"\n";
}

return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(void) {
  int N; cin >> N;
  VI A(N);
  vector<ll> count(200001);
  REP(i, N) {
    cin >> A[i];
    count[A[i]]++;
  }

  ll common = 0;
  REP(a, 200001) {
    common += count[a] * (count[a] - 1) / 2;
  }

  REP(i, N) {
    int a = A[i];
    ll c = count[a];
    ll res = common - c * (c - 1) / 2;
    if (c > 2) res += (c - 1) * (c - 2) / 2;
    cout << res << endl;
  }

    return 0;
}


Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {
    int n;
    cin>>n;
    float t, a;
    cin>>t>>a; float h[10001]; float m=INT_MAX;
    for(int i =0;i<n;i++){
        cin>>h[i];
        h[i] = t-(h[i]*0.006);
        m = min(abs(h[i]-a), m);
    }
   // cout<<m<<'\n';
    for(int i=0;i<n;i++){
        if(abs(h[i]-a)==m){
            cout<<i+1<<'\n';
            break;
        }
    }

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test=1;
    while (test--) {
        solve();
    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    bool b = true;
    for (char c : s) {
        if (ans == 0 && c == 'R') {
            ans++;
            b = true;
        } else if (c == 'R' && b) {
            ans++;
        } else {
            b = false;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3588
open Scanf
open Printf

let (n,a,b,c) = sscanf (read_line ()) "%d %d %d %d" (fun n a b c -> (n,a,b,c))
let list = 
let rec input_list n l =
match n with 
  0 -> l
| x -> input_list (x-1) (sscanf (read_line ()) "%d" (fun x -> x):: l)
in input_list n [];;

let rec loop a_in b_in c_in mp l =
match l with
  [] -> 
  if (a_in * b_in * c_in = 0) then 3000
  else 
    abs(a - a_in) + abs(b - b_in) + abs(c - c_in) + mp - 30
  | x::rest -> 
  let a_use = loop (a_in + x) b_in c_in (mp+10) rest in
  let b_use = loop a_in (b_in + x) c_in (mp+10) rest in
  let c_use = loop a_in b_in (c_in + x) (mp+10) rest in
  let no_use= loop a_in b_in c_in mp rest in
  List.fold_left min 3000 [a_use; b_use; c_use; no_use];;

printf ("%d\n") (loop 0 0 0 0 list)


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a ; i<=b;i++)
using namespace std;
const int N =52;
int n;
int a[N] , b[N] , c[N] ;
int main()
{
    ios::sync_with_stdio(0)  ;
    cin.tie(0) ; cout.tie(0) ;
 //   freopen("ch.inp","r",stdin)   ;
    cin >> n ;
    FOR(i,1,n) cin >> a[i] ;
    int kq = 0;
    FOR(i,1,n) cin >> b[i] , kq += b[i] ;
    FOR(i,1,n) cin >> c[i] ;
    int pre = -1;
    FOR(i,1,n)
    {
        if( a[i]-pre ==1 ) kq += c[pre] ;
        pre = a[i] ;
    }
    cout << kq;
}


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

using namespace std;

#define ll long long int

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(b*d, max(b*c, a*d)))<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,ans=1,a[N],du[N],pre[N],cnt[N],f[N];
bool vis[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),du[a[i]]++;
    for(int i=1;i<=n;i++) {
        if(du[i]>2) return puts("0"),0;
        if(du[i]<2||vis[i]) continue;
        int p=i;
        do {
            if(vis[p]) return puts("0"),0;
            vis[p]=1;pre[a[p]]=p;p=a[p];
        } while(p!=i);
    }
    for(int i=1;i<=n;i++)
        if(!du[i]) {
            int p=i,l1=0,l2=0;
            while(!vis[p]) vis[p]=1,p=a[p],l1++;
            do l2++,p=pre[p]; while(du[p]!=2);
            if(l1<l2) ans=2ll*ans%mod;
            else if(l1>l2) return puts("0"),0;
        }
    for(int i=1;i<=n;i++)
        if(!vis[i]) {
            int p=i,l=0;
            do p=a[p],l++,vis[p]=1; while(p!=i);
            cnt[l]++;
        }
    for(int i=1;i<=n;i++) {
        int mul=1;if(i!=1&&(i&1)) mul++;
        f[0]=1;f[1]=mul;
        for(int j=2;j<=cnt[i];j++) f[j]=(1ll*f[j-2]*(j-1)%mod*i%mod+1ll*f[j-1]*mul%mod)%mod;
        ans=1ll*ans*f[cnt[i]]%mod;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>

int main(void)
{
   int n, m, c, b[20], a[20][20], i, f, x, z=0;

   scanf("%d%d%d",&n,&m,&c);
   for(i=0;i<m;i++)
      scanf("%d",&b[i]);
   for(i=0;i<n;i++)
      for(f=0;f<m;f++)
         scanf("%d",&a[i][f]);

   for(i=0;i<n;i++){
      x=c;
      for(f=0;f<m;f++)
         x+=a[i][f]*b[f];
      if(x>0)
         z++;
   }
   printf("%d",z);
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
string A, B, C;

int main() {
	while(cin >> A, A != "0") {
		cin >> B >> C;

		reverse(A.begin(), A.end());
		reverse(B.begin(), B.end());
		reverse(C.begin(), C.end());

		int n = B.size();

		ll dp[55][2] = { 0 };

		dp[0][0] = 1;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 2; j++) {
				int q = 0, s = 0, t = 0;
				if(A[i] == '?') q++;
				else s += A[i] - '0';
				if(B[i] == '?') q++;
				else s += B[i] - '0';
				if(C[i] != '0') t = C[i] - '0';

				if(q == 2) {
					for(int a = 0; a <= 9; a++) {
						for(int b = 0; b <= 9; b++) {
							if(i == n - 1 && (a == 0 || b == 0)) continue;
							if(i == n - 1 && (a + b + j) % 10 == 0) continue;
							if(C[i] == '?' || (a + b + j) % 10 == t) {
								int nj = a + b + j >= 10;
								(dp[i + 1][nj] += dp[i][j]) %= MOD;
							}
						}
					}
				}
				else if(q == 1) {
					for(int a = 0; a <= 9; a++) {
						if(i == n - 1 && a == 0) continue;
						if(i == n - 1 && (s + a + j) % 10 == 0) continue;
						if(C[i] == '?' || (s + a + j) % 10 == t) {
							int nj = s + a + j >= 10;
							(dp[i + 1][nj] += dp[i][j]) %= MOD;
						}
					}
				}
				else { // q == 0
					if((i == n - 1 && (s + j) % 10 == 0)) continue;
					if(C[i] == '?' || (s + j) % 10 == t) {
						int nj = (s + j) >= 10;
						(dp[i + 1][nj] += dp[i][j]) %= MOD;
					}
				}
			}// for j
		}// for i
		cout << dp[n][0] << endl;
	}// while
}// main

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

ll cnt[60][60];
ll h, w, n, k;

ll ppow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = (res*a) % k;
		a = (a*a) % k;
		b >>= 1;
	}
	return res;
}
int main() {
	cin >> h >> w >> n >> k;
	int c = 0;
	rep(i, h)rep(j, w) {
		cout << "? " << i << ' ' << j << ' ' << i << ' ' << j << endl;
		cin >> cnt[i][j];
		c += cnt[i][j];
		if (c >= 250)goto goal;
	}
goal:;
	ll ans = 0;
	rep(i, h)rep(j, w) {
		ans = (ans + cnt[i][j] * ppow(2, i*w + j)) % k;
	}
	cout << "! " << ans << endl;
}

Measured memory_bytes: 724
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);  
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    int Al = 0, Bo = 0;
    for (int i = 0; i < N; i++){
        if (i%2 == 0) Al+= a[i];
        else Bo += a[i];
    }
    int ans = Al - Bo;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
using namespace std;

int main()
{
	int n, tmp = 0;
	cin >> n;
	vector<int>a(n), memo;
	for (int i = 0; i < n; i++) {cin >> a[i], memo.push_back(a[i]); }
	sort(memo.begin(), memo.end());
	for (int i = 0; i < n; i++) {
		if (memo[memo.size() - 1] > a[i])cout << memo[memo.size() - 1] << endl;
		else {
			for (int j = n - 2; j >= 0; j--) {
				if (memo[memo.size() - 1] == memo[j]) { cout << memo[j] << endl; break; }
				else {
					cout << memo[j] << endl; break;
				}
			}
		}
	}
}

Measured memory_bytes: 3316
/*
 * GCA : "Computer is artificial subject absolutely,Math is God"
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cctype>
#include <utility>
#include <ctime>
using namespace std;
#ifdef DEBUG
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...) printf("DEBUG: "),printf(__VA_ARGS__)
#else
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...)
#endif
typedef unsigned int uint;
typedef long long int Int;
typedef unsigned long long int UInt;
#define Set(a,s) memset(a,s,sizeof(a))
#define Pln() printf("\n")
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define M 105
#define PB push_back
#define oo INT_MAX
#define FOR(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)
#define eps 1e-9
#define X first
#define Y second
inline bool xdy(double x,double y){return x>y+eps;}
inline bool xddy(double x,double y){return x>y-eps;}
inline bool xcy(double x,double y){return x<y-eps;}
inline bool xcdy(double x,double y){return x<y+eps;}
const Int mod=1000000007;
map<string,int> isgroup;
set<string> s;
int n;
vector<string> g[M];
bool vis[M];
void dfs(int index){
	vis[index]=1;
	FOR(it,g[index]){
		if(isgroup.count(*it)){
			int j=isgroup[*it];
			if(!vis[j])dfs(j);
		}else s.insert(*it);
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	while(~scanf("%d%*c",&n)&&n){
		s.clear();
		Set(vis,0);
		isgroup.clear();
		for(int i=1;i<=n;i++)g[i].clear();
		for(int i=1;i<=n;i++){
			char str[105];
			scanf("%[^:]%*c",str);
			isgroup[str]=i;
			char c=',';
			while(c!='.'){
				scanf("%[^,.]%c",str,&c);
				g[i].PB(str);
			}
			getchar();
		}
		dfs(1);
		printf("%d\n",s.size());
	}

















}

Measured memory_bytes: 1388
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int n, r;
  cin >> n >> r;
  if (n >= 10) cout << r << endl;
  else cout << r + 100 * (10 - n) << endl;
  return 0;
}

Measured memory_bytes: 256
# ARC080D - Grid Coloring (ABC069D)
def main():
    H, W = tuple(map(int, input().split()))
    N = int(input())
    A = tuple(map(int, input().split()))
    G = []  # grid
    for color, cnt in enumerate(A, 1):
        G += [color] * cnt
    par = 0  # parity
    for i in range(1, H + 1):
        if not par:
            print(*G[(i - 1) * W : i * W])
        else:
            print(*G[(i - 1) * W : i * W][::-1])
        par ^= 1


if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
private class A {
    fun solve() {
        val x = nextInt()
        if (x >= 30) {
            println("Yes")
        } else {
            println("No")
        }
    }

    var tokenBuffer = listOf<String>()
    var bufferPosition = 0

    private fun checkBuffer() {
        if (bufferPosition == tokenBuffer.size) {
            tokenBuffer = nextLine().split(" ")
            bufferPosition = 0
        }
    }

    fun nextLine() = readLine()!!
    fun nextInt(): Int {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toInt()
    }

    fun nextLong(): Long {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toLong()
    }

    fun nextDouble(): Double {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toDouble()
    }

    fun nextToken(): String {
        checkBuffer()
        return tokenBuffer[bufferPosition++]
    }
}

fun main() {
    val reader = A().solve()

}


Measured memory_bytes: 36500
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func main() {
	var A, B int
	fmt.Scanf("%d %d\n", &A, &B)

	if B*2 >= A {
		fmt.Println(0)
	} else {
		fmt.Println(A - B*2)

	}

}


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

using namespace std;

#define MAX 120
#define INF 1e9

struct Edge{
  int to,cost;
  Edge(int t,int c) : to(t),cost(c) {}
};

struct State{
  int cost,v,tic;
  State(int c,int v,int t) : cost(c),v(v),tic(t) {}
  bool operator < (const State &s)const{
    return cost > s.cost;
  }
};

int C,V,E,src,dst;
vector<Edge> G[MAX];

int dijkstra(){
  priority_queue<State> Q;
  Q.push(State(0,src,C));
  int dist[MAX][11];
  fill(dist[0],dist[0]+MAX*11,INF);
  dist[src][C] = 0;
  
  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    int v = s.v,t = s.tic;
    if(dist[v][t] < s.cost) continue;
    if(v == dst) return dist[v][t];
    
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      if(dist[v][t] + e.cost < dist[e.to][t]){
        dist[e.to][t] = dist[v][t] + e.cost;
        Q.push(State(dist[e.to][t],e.to,t));
      }
      if(t > 0){
        if(dist[v][t] + e.cost/2 < dist[e.to][t-1]){
          dist[e.to][t-1] = dist[v][t] + e.cost/2;
          Q.push(State(dist[e.to][t-1],e.to,t-1));
        }
      }
    }
  }
}

int main(){
  while(cin >> C >> V >> E >> src >> dst, C){
    src--; dst--;
    for(int i = 0 ; i < V ; i++){
      G[i].clear();
    }
    for(int i = 0 ; i < E ; i++){
      int a,b,c;
      cin >> a >> b >> c; a--; b--;
      G[a].push_back(Edge(b,c));
      G[b].push_back(Edge(a,c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){return (x%y==0?y:gcd(y,x%y));}
int main(){
  int N;cin>>N;
  vector<int>A(N);for(int i=0;i<N;i++)cin>>A[i];
  vector<int>R(N),L(N);L[0]=A[0];R[N-1]=A[N-1];
  for(int i=1;i<N;i++)L[i]=gcd(L[i-1],A[i]);
  for(int i=N-2;i>=0;i--)R[i]=gcd(R[i+1],A[i]);
  int M=0;
  for(int i=0;i<N;i++){
    if(i==0) M=max(M,R[1]);
    else if(i==N-1)M=max(M,L[N-2]);
    else M=max(M,gcd(L[i-1],R[i+1]));
  }
  cout<<M<<endl;
}

Measured memory_bytes: 1408