akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> P;
static const int INF=1<<24;

int m1[30][30]={0};


int main(){
	int n,m;
	while(cin>>n,n){
		rep(i,30){
			rep(j,30){
				m1[i][j]=0;
			}
		}
		rep(i,n){
			int t1,t2;
			cin>>t1>>t2;
			m1[t2][t1]=1;
		}
		cin>>m;
		int x=10,y=10;
		rep(i,m){
			char c1;
			int t1;
			cin>>c1>>t1;
			int xt,yt;
			if(c1=='N'){
				xt=0;
				yt=1;
			}
			else if(c1=='W'){
				xt=-1;
				yt=0;
			}
			else if(c1=='E'){
				xt=1;
				yt=0;
			}
			else if(c1=='S'){
				xt=0;
				yt=-1;
			}
			rep(j,t1){
				x+=xt;
				y+=yt;
				//cout<<x<<" "<<y<<endl;
				if(m1[y][x]==1){
					m1[y][x]=0;
					n--;
				}
			}
		}
		if(n==0){
			cout<<"Yes\n";
		}
		else cout<<"No\n";
			
	}
	return 0;
}

Measured memory_bytes: 1120
# -*- coding: utf-8 -*-
"""
C - Streamline
https://atcoder.jp/contests/abc117/tasks/abc117_c

"""
import sys


def solve(N, M, positions):
    gaps = sorted([b-a for a, b in zip(positions, positions[1:])])
    if len(gaps) < N:
        return 0
    return sum(gaps[:-(N-1)]) if N > 1 else sum(gaps)


def main(args):
    N, M = map(int, input().split())
    positions = sorted(map(int, input().split()))
    ans = solve(N, M, positions)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 58280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

    string s;
    int n;
    cin >> n;
    cin >> s;
    int c = 0;
    for (int i = 1; i < n; ++i) if (s[i] == 'E') ++c;
    int cst = c;
    for (int i = 1; i < n; ++i)
    {
        if (s[i-1] =='W') ++c;
        if (s[i] == 'E') --c;
        if (c < cst) cst = c;
    } 
    cout << cst << endl;

    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	cout<<n*(n-1)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000
using namespace std;
typedef pair<int, int> P;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main()
{
    int N, W, H;
    cin >> N >> W >> H;
    vector<int> h(H + 10, 0);
    vector<int> w(W + 10, 0);
    rep(i, N)
    {
        int x, y, p;
        //cin >> x >> y >> p;
        scanf("%d%d%d", &x, &y, &p);
        h[max(0, y - p)]++;
        h[min(y + p, H)]--;
        w[max(0, x - p)]++;
        w[min(x + p, W)]--;
    }
    for (int i = 0; i <= W; i++)
    {
        if (i == 0)
            continue;
        w[i] += w[i - 1];
    }
    for (int i = 0; i <= H; i++)
    {
        if (i == 0)
            continue;
        h[i] += h[i - 1];
    }
    bool flag = false;
    for (int i = 0; i < W; i++)
    {
        if (w[i] == 0)
            //0があったらもう片方を確認する
            flag = true;
    }
    if (flag == false)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        for (int i = 0; i < H; i++)
        {
            if (h[i] == 0)
                flag = false;
        }
    }
    if (!flag)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    //return 0;
    /*rep(i, W + 1) cout << w[i] << " ";
    cout << endl;
    rep(i, H + 1) cout << h[i] << " ";
    cout << endl;*/
    return 0;
}



Measured memory_bytes: 3624
N = int(input())
result = []
def change(num):
    if num != 0:
        div = num // (-2)
        mod = num % (-2)
        if mod == -1:
            div += 1
            mod = 1
        result.append(mod)
        if div == 1:
            result.append(div)
            print(''.join(map(str, result[::-1])))
        else:
            n = div
            change(n)
    else:
        print(0)
change(N)

Measured memory_bytes: 3064
def solve(N, H, W, ABs):
    ans = 0
    for A, B in ABs:
        ans += min(A // H, B // W)
    return ans


if __name__ == "__main__":
    N, H, W = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, H, W, ABs))


Measured memory_bytes: 3060
#include <stdio.h>

#define N 200000

long a[N+1];

int main(void){
    long n;
    scanf("%ld", &n);
    a[0] = -1;
    for(long i=1; i<=n; i++){
        scanf("%ld", a+i);
    }
    long count=-1;
    for(long i=n; i>=1; i--){
        long d = a[i]-a[i-1];
        if(d>=2){
            puts("-1");
            return 0;
        }else if(d==1){
            count++;
        }else{
            count += a[i];
        }
    }
    printf("%ld\n", count);
    return 0;
}



Measured memory_bytes: 1664
import java.util.Scanner;

// D - Brick Break
// https://atcoder.jp/contests/abc148/tasks/abc148_d
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());

        int breakCount = 0;
        int kIndex = 1;
        for (int i = 0; i < N; i++) {
            int num = Integer.parseInt(scanner.next());

            if (kIndex != num) {
                breakCount++;
            } else {
                kIndex++;
            }
        }
        scanner.close();

        if (breakCount == N) {
            System.out.println("-1");
        } else {
            System.out.println(breakCount);
        }
    }
}


Measured memory_bytes: 49304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<ll> A(N),B(N);
  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=0;i<N;i++) cin>>B[i];

  for(int i=0;i<N;i++){
    if(A[i]>B[i]){
      cout<<-1<<endl;
      return 0;
    }
  }

  vector<ll> C=B;
  priority_queue<pair<int,int>> PQ;
  for(int i=0;i<N;i++) if(A[i]!=B[i]) PQ.push(mkp(B[i],i));
  ll ans=0;
  while(!PQ.empty()){
    int val,now;
    tie(val,now)=PQ.top();
    PQ.pop();

    int l=C[(now-1+N)%N],r=C[(now+1)%N];
    if(l+r>=val){
      cout<<-1<<endl;
      return 0;
    }

    if((val-A[now])%(l+r)==0){
      ans+=(val-A[now])/(l+r);
      C[now]=A[now];
    }else{
      if((val)%(l+r)==0){
        ans+=(val/(l+r))-1;
        C[now]=l+r;
      }else{
        ans+=(val/(l+r));
        C[now]=val%(l+r);
      }
      
      if(C[now]<A[now]){
        cout<<-1<<endl;
        return 0;
      }
      PQ.push(mkp(C[now],now));
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 7156
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#define maxn 1005
using namespace std;
typedef long long  LL;
int cnt=0;
LL n;
void f(LL num,int flag1,int flag2,int flag3)
{
    if(num<=n)
    {
        if(flag1&&flag2&&flag3)
            cnt++;
        f(num*10+3,1,flag2,flag3);
        f(num*10+5,flag1,1,flag3);
        f(num*10+7,flag1,flag2,1);
    }
    return ;
}
int main()
{

    scanf("%lld",&n);
    f(0,0,0,0);
    cout<<cnt<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int cnt_4=0,cnt_2=0;
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            if(x%4==0)
                cnt_4++;
            else if(x%2==0)
                cnt_2++;
        }
        int len=2*cnt_4+1;
        if(len>=n)
        {
            printf("Yes\n");
            continue;
        }
        if(cnt_2>1)
            len=len-1+cnt_2;
        if(len>=n)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
N, M = [int(x) for x in input().strip().split(" ")]
from collections import deque
vs = set()
def bfs(v,d,t,N):
    queue=deque([v])
    dist = [0] * (N+1)
    while True:
        if len(queue) == 0:
            break
        v = queue.popleft()
        for u in d[v]:
            if u in vs:
                continue
            vs.add(u)
            dist[u] = dist[v] + 1
            if u == t:
                return dist[u]//3
            queue.append(u)
    return -1

d = [set() for _ in range(3*N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a].add(N+b)
    d[N+a].add(2*N+b)
    d[2*N+a].add(b)

s, t = [int(x) for x in input().strip().split(" ")]
print(bfs(s, d, t, 3*N+1))


Measured memory_bytes: 102100
#include<stdio.h>
int main(){
int a,b,c,d,e,f,g,h;
long  int A[101][101],B[101][101],C[101][101]={0};

scanf("%d %d %d",&a,&b,&c);
for(d=0;d<a;d++){
for(e=0;e<b;e++){
scanf("%d",&A[d][e]);
}
}
for(d=0;d<b;d++){
for(e=0;e<c;e++){
scanf("%d",&B[d][e]);
}
}
for(f=0;f<a;f++){
for(d=0;d<b;d++){
for(e=0;e<c;e++){
	C[f][e]+=A[f][d]*B[d][e];
}
}
}
for(d=0;d<a;d++){
for(e=0;e<c;e++){
printf("%ld",C[d][e]);
if(e!=c-1)
printf(" ");
else
printf("\n");
}
}
return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; ++i)
  {
    if (i % d == 0)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
char s[N],t[N];
int n,ans,rec[N],top,p;
vector<int> pla[30];
int main() {
  scanf("%d",&n);
  scanf("%s%s",s+1,t+1);
  for (int i = 0 ; i < 26 ; ++ i)
    pla[i].push_back(-1);
  for (int i = 1 ; i <= n ; ++ i)
    pla[s[i] - 'a'].push_back(i);
  int cur = n+1;
  top = 0;
  rec[0] = n + 1;
  for (int i = n ; i >= 1 ; -- i) {
    cur = min(cur,i);
    if (t[i] == s[cur]) continue;
    while (pla[t[i]-'a'].back() > cur)
      pla[t[i]-'a'].pop_back();
    cur = pla[t[i]-'a'].back();
    if (cur == -1) return puts("-1"), 0;
    rec[++top] = cur;
    while (rec[p+1] - (top - p - 1) >= i && p + 1 <= top)
      ++ p;
    ans = max(ans, top - p);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 11208
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

const int inf = 1e9;
const ll linf = 1e18;

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

    int h, n; cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        sum += a;
    }
    cout << ((sum >= h) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
6
9 1 4 4 6 7
---+/
/+---test
8
9 1 14 5 5 4 4 14
---+/
/+---test
14
99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1
---+/

void main(string[] args) {
  readln;
  const D = readln.split.map!(to!long).array.sort!"a > b".array;
  const N = D.length;

  auto x = N/2;
  if (x*2 != N) {
    0.writeln;
    return;
  }
  (D[x-1] - D[x]).writeln;
}


Measured memory_bytes: 4420
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.charAt(0) == s.charAt(1) || s.charAt(1) == s.charAt(2) || s.charAt(2) == s.charAt(3)) {
            System.out.println("Bad");
        } else {
            System.out.println("Good");
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 3e5 + 5;

int ans = 0x7fffffff;
int num_e[maxn], len;
int num_w[maxn];
bool hhw[maxn];
char input[maxn];

int main() {
  scanf("%d", &len);
  scanf("%s", input);
  for(int i = 0; i < len; i++) {
    if(input[i] == 'E') hhw[i + 1] = false;
    if(input[i] == 'W') hhw[i + 1] = true;
  }
  if(hhw[1]) num_w[1] = 1;
  if(!hhw[len]) num_e[len] = 1;
  for(int i = 2; i <= len; i++) {
    if(hhw[i]) num_w[i] = num_w[i - 1] + 1;
    else num_w[i] = num_w[i - 1];
  }
  for(int i = len - 1; i >= 1; i--) {
    if(!hhw[i]) num_e[i] = num_e[i + 1] + 1;
    else num_e[i] = num_e[i + 1];
  }
  for(int i = 1; i <= len; i++)
    ans = min(num_e[i + 1] + num_w[i - 1], ans);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3200
import sys
import math

def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0

    while True:
        prime = min(A)

        if prime > math.sqrt(limit):
            break

        P.append(prime)

        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1

    for a in A:
        P.append(a)

    return set(P)

max_n = 10**5

primes = eratosthenes(max_n)
# print(primes)

acum_like_n = [0] * (max_n+1)
for i in range(1, max_n + 1):
    if i in primes and (i+1)//2 in primes:
        acum_like_n[i] = acum_like_n[i-1] + 1
    else:
        acum_like_n[i] = acum_like_n[i-1]
# print(acum_like_n)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    l, r = map(int, sys.stdin.readline().strip().split())
    print(acum_like_n[r] - acum_like_n[l-1])

Measured memory_bytes: 8380
from collections import Counter
from sys import exit
def No():
    print('No')
    exit()
def Yes():
    print('Yes')
    exit()

N = int(input())
A = list(map(int, input().split()))
if max(A) - min(A) > 1:
    No()
if len(set(A)) == 1:
    if A == [N-1]*N:
        Yes()
    a = A[0]
    if a <= N//2:
        Yes()
    No()
mA = min(A)
S = max(A)
B = Counter(A)[mA]
if B + 1 <= S <= (N - B)//2 + B:
    Yes()
No()

Measured memory_bytes: 52804
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;

void mmg(vv32& adj, int m, v32& deg){
	int x,y;
	//cout << "bbb";
	forn(i,m){
		cin >> x >> y;
		adj[x-1].pb(y-1);
		deg[y-1]++;
		//dbg(i);
	}
	return;
}

void topo(v32& T, queue<int>& q, vv32& adj, v32& deg){
	int x;
	while(!q.empty()){
		x = q.front();
		q.pop();
		T.pb(x);
		for(v32::iterator it = adj[x].begin(); it!=adj[x].end(); ++it){
			deg[*it]--;
			if(deg[*it]==0) q.push(*it);
		}
	}
	return;
}

void maxpath(v32& T, vv32& adj, v32& dp, int n){
	forn(i,n){
		for(v32::iterator it=adj[(T[i])].begin(); it!= adj[T[i]].end(); ++it){
			dp[*it] = max(dp[T[i]]+1, dp[*it]);
		}
	}

	return;
}


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

//	cout << "maan";

	int n, m;
	cin >> n >> m;
	
	vv32 adj;
	adj.resize(n);
	v32 deg;
	forn(i,n) deg.pb(0);

	mmg(adj,m,deg);

	v32 T, dp;
	forn(i,n) dp.pb(-1);
	queue<int> q;
	forn(i,n) if(deg[i]==0){
		q.push(i);		
		dp[i]=0;
	}	

	topo(T,q,adj,deg);

//	forn(i,n) cout << T[i];

	maxpath(T,adj,dp,n);

	int maxx=0;

	forn(i,n) maxx = max(dp[i],maxx);

	cout << maxx;

}


Measured memory_bytes: 7288
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<map>
#define all(c) c.begin(),c.end()
#define uni(c) c.erase(unique(all(c)),c.end())
#define pb push_back
using namespace std;
typedef pair<int,int> P;
typedef pair<double,int> Pdi;
int w,h;
vector<string> s;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
bool infalpha(int y,int x){
	if(y>=0&&y<h&&x>=0&&x<w&&s[y][x]!='.')
		return true;
	return false;
}
Pdi ret(int y,int x,vector<vector<bool> > &c){
	double zyu=0;
	int cnt=0;
	vector<P> next;
	queue<P> que;
	que.push(P(y,x));
	char col=s[y][x];
	while(!que.empty()){
		P t=que.front();
		que.pop();
		if(c[t.first][t.second]){
			continue;
		}
		c[t.first][t.second]=true;
		cnt++;
		zyu+=(double)t.second+(double)0.5;
		for(int i=0;i<4;i++){
			int nx=t.second+dx[i];
			int ny=t.first+dy[i];
			if(!infalpha(ny,nx))
				continue;
			if(c[ny][nx]){
				continue;
			}
			if(i==1){
				if(s[ny][nx]==col){
					que.push(P(ny,nx));
				}else{
					next.pb(P(ny,nx));
				}
			}else{
				if(s[ny][nx]==col){
					que.push(P(ny,nx));
				}
			}
		}
		
	}
	sort(all(next));
	uni(next);
	for(int i=0;i<next.size();i++){
		P a=ret(next[i].first,next[i].second,c);
		zyu+=(double)a.first;
		cnt+=a.second;
	}
	return P(zyu,cnt);
}
P rl(int y,int x,vector<vector<bool> > &f){
	queue<P> que;
	que.push(P(y,x));
	char col=s[y][x];
	int l=100,r=0;
	while(!que.empty()){
		P t=que.front();
		que.pop();
		if(f[t.first][t.second]){
			continue;
		}
		f[t.first][t.second]=true;
		if(t.first==h-1){
			r=max(r,t.second);
			l=min(l,t.second);
		}
		for(int i=0;i<4;i++){
			int nx=t.second+dx[i];
			int ny=t.first+dy[i];
			if(!infalpha(ny,nx))
				continue;
			if((i==0&&s[ny][nx]!=col)){
				r=max(r,nx);
				l=min(l,nx);
			}
			if(f[ny][nx]||s[ny][nx]!=col){
				continue;
			}
			que.push(P(ny,nx));
		}
		
	}
	return P(r+1,l);
}
int main(){
	while(cin>>w>>h,w||h){
		s.resize(h);
		for(int i=0;i<h;i++){
			cin>>s[i];
		}
		bool flag=true;
		vector<vector<bool> > f(h,vector<bool>(w,false));
		for(int i=0;i<h;i++){//y
			for(int j=0;j<w;j++){//x
				if(s[i][j]!='.'&&!f[i][j]){
					vector<vector<bool> > c(h,vector<bool>(w,false));
					Pdi sum=ret(i,j,c);
					P side=rl(i,j,f);
					//cout<<"    "<<side.first<<"  "<<side.second<<endl;
					//cout<<"     lk:p    "<<sum.first<<"  "<<sum.second<<endl;
					double zyushin=(double)sum.first/(double)sum.second;
					//cout<<zyushin<<endl;
					//cout<<"    "<<side.second<<"  "<<side.first<<endl;
					if(!((double)side.second*(double)sum.second<(double)sum.first&&(double)side.first*(double)sum.second>(double)sum.first)){
						flag=false;
					}
					/*if(!(zyushin>side.second&&zyushin<side.first)){
						flag=false;
					}*/
				}
			}
		}
		if(flag)
		cout<<"STABLE"<<endl;
		else
		cout<<"UNSTABLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 956
#include <iostream>
#include <vector>
#include <set>

using namespace std;

vector<int> a;

//m????????????????´???°??????????????????
//m??\????????????????????°??§???????????????????????????????????????
set<int> f(int m) {
	set<int> ret; //??????????????????
	for (auto i : a) {
		if (m % i == 0) {
			int t = m / i;//?????£???????????°
			//?????£???????????????????????°??§????????????continue
			if (t % 7 != 1 && t % 7 != 6)continue;
			//i???m????????????????´???°
			ret.insert(i);
		}
	}
	return ret;
}

int main() {
	for (int i = 1; i <= 300000; i++) {
		if (i % 7 == 1 || i % 7 == 6) {
			a.push_back(i);
		}
	}
	int n;
	while (cin >> n && n != 1) {
		set<int> ans = f(n);

		cout << n << ":";
		for (auto i : ans) {
			if (i > 1 && f(i).size() == 2) {
				cout << " " << i;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
import java.util.*;

public class Main{
  
  public static void main(String[] args){
  
  Scanner sc = new Scanner(System.in);
  
  int n = sc.nextInt();
  int[] list = new int[n];
 
  for(int i = 0; i < n ; i++){
    list[i] = sc.nextInt();
  }
  
  int count = 0;
  for(int i = 0; i < n - 2; i++){
    if(list[i] < list[i+1] && list[i+1] < list[i+2]){
      count++;
    }else if(list[i] > list[i+1] && list[i+1] > list[i+2]){
      count++;
    }
   }
     System.out.println(count);
   }
}


Measured memory_bytes: 35872
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long

int main() {
    int a,cnt=0;
    for(int i=1; i<=3; i++){
        cin>>a;
        if(a==7)cnt++;
    }
    if(cnt==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=(ll)0;
    ll n,T;
    cin >> n >> T;
    ll t[n];
    cin >>t[0];
    for(int i=1;i<n;i++){
        cin >>t[i];
        ans += min(t[i]-t[i-1],T);
    }
    ans+=T;

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int N,K;
string s;
main()
{
	cin>>N>>K>>s;
	string t=s;
	reverse(t.begin(),t.end());
	s+=t;
	string m=s.substr(0,N);
	for(int i=1;i<=N;i++)m=min(m,s.substr(i,N));
	int l=1;
	while(l<m.size()&&m[0]==m[l])l++;
	long k=l;
	K--;
	if(K>17)k=N;
	else k<<=K;
	string ans="";
	while(ans.size()<N&&k>0)k--,ans+=m[0];
	ans+=m.substr(l,N-ans.size());
	cout<<ans<<endl;
}


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

int main() {
    int S; cin>>S;
    vector<ll> A(S+1,0);
    A[0] = 1;
    for(int i=3; i<=S; ++i) {
      A[i] = (A[i-1]+A[i-3])%MOD;
    }
    cout << A[S] << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<utility>


int main(){
    int h,w;
    char evenc,oddc;
    while(scanf("%d %d",&h,&w) && (h != 0 || w != 0)){
        evenc = '.',oddc = '#';
        for(int i=1;i <= h;i++){
            for(int j=1;j <= w;j++){
                if(j % 2 == 0){
                    printf("%c",evenc);
                } else{
                    printf("%c",oddc);
                }
            }
            printf("\n");
            std::swap(evenc,oddc);
        }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 2676
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let line = read_vector::<usize>();
    let (x, y, z, k) = (line[0], line[1], line[2], line[3]);
    let x_prices = read_vector::<u64>();
    let y_prices = read_vector::<u64>();
    let z_prices = read_vector::<u64>();

    let mut xy = vec![];
    for i in 0..x {
        for j in 0..y {
            xy.push(x_prices[i] + y_prices[j]);
        }
    }
    xy.sort();
    xy.reverse();
    let mut xyz = vec![];
    for i in 0..z {
        for j in 0..min(x * y, k) {
            xyz.push(z_prices[i] + xy[j]);
        }
    }
    xyz.sort();
    xyz.reverse();
    for i in 0..k {
        println!("{}", xyz[i]);
    }
}

#[allow(dead_code)]
fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf.trim().parse().unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::with_capacity(100);
    stdin().read_line(&mut buf).unwrap();
    return buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::io::prelude::*;
    let stdin = stdin();
    let mut reader = BufReader::with_capacity(100 * 1024, stdin);
    let mut line = String::with_capacity(100);
    let mut matrix: Vec<Vec<T>> = Vec::new();

    while reader.read_line(&mut line).unwrap() > 0 {
        matrix.push(
            line.trim()
                .split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect(),
        );
        line.clear();
    }

    return matrix;
}

#[allow(dead_code)]
fn read_chars() -> Vec<char> {
    let stdin = stdin();
    let mut buf = String::new();
    let _bytes = stdin.read_line(&mut buf).unwrap();
    return buf.trim().chars().collect();
}


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

typedef long long ll;

int main(void) {
	ll X, Y;
	cin >> X >> Y;

	ll k = 1;
	int a = 0;
	while (X * k <= Y) {
		k <<= 1;
		++a;
	}

	cout << a << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        String b = sc.next();
        int c = sc.nextInt();

        String[] s = new String[a];

        int i;


        for(i=0;i < a;i++)
            s[i]=b.substring(i,i+1);

        String d = s[c-1];

        for(int j=0;j+1 <= a;j++){
            if(s[j].equals(d)){
                s[j]=s[j];
            }else{
                s[j]="*";
            }

        }

        String e = Arrays.toString(s);
        String f = e.replace(",","");
        String g = f.replace("[","");
        String h = g.replace("]","");
        String l = h.replaceAll(" ","");

        System.out.println(l);
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w,n,a;cin>>h>>w>>n;
  lvector ans,ans_(w,0);
  rep(i,n) {
    cin>>a;
    rep(j,a) ans.emplace_back(i+1);
  }
  ll pos=0,cnt=0;
  rep(i,h) {
    rep(j,w) ans_[j]=ans[pos+j];
    if(cnt%2==1) reverse(ALL(ans_));
    rep(j,w-1) cout<<ans_[j]<<' ';cout<<ans_[w-1]<<endl;
    pos+=w,cnt++;
  }
  return 0;
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int[][] arr = new int[1000][1000];
            int[][] b = new int[1000][1000];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    arr[i][j] = in.nextInt();
                    b[i][j] = arr[i][j];
                }
            }
            for (int k = 0; k < n; k++) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        if (arr[i][k] + arr[k][j] < arr[i][j]) {
                            arr[i][j] = arr[i][k] + arr[k][j];
                        }
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (b[i][j] != arr[i][j]) {
                        out.println(-1);
                        return;
                    }
                }
            }
            long ans = 0;
            for (int i = 0; i < n; i++) {
                inner:
                for (int j = i + 1; j < n; j++) {
                    for (int k = 0; k < n; k++) {
                        if (k != i && k != j) {
                            if (arr[i][j] == arr[i][k] + arr[k][j]) continue inner;
                        }
                    }
                    ans += arr[i][j];
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 67496
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int s, w; cin >> s >> w;
    if (s<=w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}







Measured memory_bytes: 3640
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int a,b;
  string s;
  for(;;){
    s="";
    cin>>s;
    if(s.empty())
      break;
    cin>>a>>b;
    cout<<s<<" "<<a+b<<" "<<a*200+b*300<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
int n;
int a[100005], b[100005];
int c[100005], d[100005];
int asc1(const void* x, const void* y)
{
	if (a[*(int*)x] > a[*(int*)y])return 1;
	if (a[*(int*)x] < a[*(int*)y])return -1;
	if (b[*(int*)x] > b[*(int*)y])return 1;
	if (b[*(int*)x] < b[*(int*)y])return -1;
	return 0;
}
int asc2(const void* x, const void* y)
{
	if (b[*(int*)x] > b[*(int*)y])return 1;
	if (b[*(int*)x] < b[*(int*)y])return -1;
	if (a[*(int*)x] > a[*(int*)y])return 1;
	if (a[*(int*)x] < a[*(int*)y])return -1;
	return 0;
}
int p[100005];
void dfs(int x)
{
	int min, mid, max;
	min = 0;
	max = n - 1;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (a[c[mid]] < x)
			min = mid;
		else
			max = mid;
	}
	if (a[c[min]] != x)
		min++;
	if (min < n - 1)
	{
		while (a[c[min]] == x)
		{
			if (p[b[c[min]]] < 0)
			{
				p[b[c[min]]] = x;
				dfs(b[c[min]]);
			}
			min++;
			if (min == n - 1)
				break;
		}
	}
	min = 0;
	max = n - 1;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (b[d[mid]] < x)
			min = mid;
		else
			max = mid;
	}
	if (b[d[min]] != x)
		min++;
	if (min < n - 1)
	{
		while (b[d[min]] == x)
		{
			if (p[a[d[min]]] < 0)
			{
				p[a[d[min]]] = x;
				dfs(a[d[min]]);
			}
			min++;
			if (min == n - 1)
				break;
		}
	}
	return;
}
int root(int n)
{
	if (p[n] == n)
		return n;
	p[n] = root(p[n]);
	return p[n];
}
void f(int x, int y)
{
	if (root(x) == root(y))
		return;
	p[root(x)] = root(y);
	return;
}
int main()
{
	scanf("%d", &n);
	int i;
	for (i = 0; i < n - 1; i++)
	{
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
	}
	for (i = 0; i < n; i++)
		c[i] = d[i] = i;
	qsort(c, n - 1, sizeof(int), asc1);
	qsort(d, n - 1, sizeof(int), asc2);
	for (i = 0; i < n; i++)
		p[i] = -1;
	p[0] = 0;
	dfs(0);
	int count = 0;
	int now = n - 1;
	while (now != 0)
	{
		count++;
		now = p[now];
	}
	count--;
	now = n - 1;
	for (i = 0; i < count / 2; i++)
		now = p[now];
	for (i = 0; i < n - 1; i++)
	{
		if (a[i] == now && b[i] == p[now])
			a[i] = b[i];
		if (a[i] == p[now] && b[i] == now)
			a[i] = b[i];
	}
	for (i = 0; i < n; i++)
		p[i] = i;
	for (i = 0; i < n - 1; i++)
		f(a[i], b[i]);
	int fen, snu;
	fen = snu = 0;
	for (i = 0; i < n; i++)
	{
		if (root(i) == root(0))
			fen++;
		else
			snu++;
	}
	if (fen > snu)
		printf("Fennec\n");
	else
		printf("Snuke\n");
	return 0;
}

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

int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}
void solve(){
  int k;
  cin >> k;
  
  if(k % 7 == 0){
  	k /= 7;
  }
  if(gcd(10,k) != 1){
  	cout << -1;
    return;
  }
  
  long v = 1%k;
  int len = 1;
  while( v != 0){
  	v = (10*v + 1) % k;
    len++;
  }
  cout << len;
}
int main(){
  
	solve();
 }

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



int main() {
    int m,n;
    cin>>m>>n;
    vector<string> g;
    for(int i=0;i<m;i++){
        string s;
        cin>>s;
        g.push_back(s);
    }
    vector<vector<long long int>> dp(m,vector<long long int>(n,0));
    for(int i=0;i<n;i++){
        if(g[0][i]=='.')
            dp[0][i]=1;
        else
            break;
    }
    
    for(int i=0;i<m;i++){
        if(g[i][0]=='.')
            dp[i][0]=1;
        else
            break;
    }
    for(int i=1;i<m;i++){
        for(int j=1;j<n;j++){
            if(g[i][j]=='.')
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
        }
    }
    cout<<dp[m-1][n-1];
    return 0;
}

Measured memory_bytes: 12212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

int main() 
{
	ll n;
	cin >> n;
	ll a[n + 1], cnt = 0, sump = 0, sumn = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] > 0) {sump += a[i]; cnt++;}
		else sumn += a[i];
	}
	sort(a + 1, a + n + 1, greater<ll>());
	
	ll ptr1 = 2, ptr2 = n - 1;
	if (cnt == n)
	{
		cout << sump - 2*a[n] << endl;
		ll temp = a[n];
		while (ptr1 < n) 
		{
			cout << temp << " " << a[ptr1] << endl;
			temp = temp - a[ptr1];
			ptr1++;
		}
		cout << a[1] << " " << temp;
	}
	
	else if (cnt == 0)
	{
		cout << 2*a[1] - sumn << endl;
		ll temp = a[1];
		while (ptr2 > 1) 
		{
			cout << temp << " " << a[ptr2] << endl;
			temp = temp - a[ptr2];
			ptr2--;
		}
		cout << temp << " " << a[n];
	}
	
	else
	{
		cout << sump - sumn << endl;
		ll temp = a[1], tempn = a[n];
		while (a[ptr2] < 0 && ptr2 > 1) 
		{
			cout << temp << " " << a[ptr2] << endl;
			temp = temp - a[ptr2];
			ptr2--;
		}
		
		while (a[ptr1] >= 0 && ptr1 < n) 
		{
			cout << tempn << " " << a[ptr1] << endl;
			tempn = tempn - a[ptr1];
			ptr1++;
		}
		
		cout << temp << " " << tempn;
	}
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)%s
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1ll<<60)
using namespace std;
int n,Q;
char S[1000005];
int main(){
	scanf("%d%s",&n,S+1);
	scanf("%d",&Q);
	while (Q--){
		int k,laM=0,SD=0,SM=0;
		scanf("%d",&k);
		ll ans=0,sum=0;
		For(j,1,n){
			if (j>k){
				if (S[j-k]=='D') SD--,sum-=SM;
				if (S[j-k]=='M') SM--;
			}
			if (S[j]=='D') SD++;
			if (S[j]=='M') SM++,sum+=SD;
			if (S[j]=='C') ans+=sum; 
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[100000];
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  int ans=0;
  rep(i,n){
    if(a[a[i]]==i) ans++;
  }
  cout<<ans/2<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
		for(int i=9;i>=1;i--)
		{
			if(n%i==0 &&(n/i)<10)
			{
				cout<<"Yes";
				break;
			}
			if(i==1)
			{
				cout<<"No";
				break;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if(K < A) cout << K << endl;
    else if (K < A+B) cout << A << endl;
    else cout << A-(K-A-B) << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool flag = false;

    for(int i = a; i <= a * b; i += a){
        if(i % b == c){
            cout << "YES" << endl;
            flag = true;
            break;
        }
    }
    if(flag == 0) cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
long judge(long,long,long);
int main(){
  int n,luck[3][100000];
  long dp[3][100000],max;
  scanf("%d",&n);
  for (int i=0;i<n;i++){
    for (int j=0;j<3;j++) scanf("%d",&luck[j][i]);
  }
  dp[0][0]=(long)luck[0][0];
  dp[1][0]=(long)luck[1][0];
  dp[2][0]=(long)luck[2][0];
  for (int i=1;i<n;i++){
    if (dp[1][i-1]+luck[0][i]>dp[2][i-1]+luck[0][i]){
      dp[0][i]=dp[1][i-1]+luck[0][i];
    }
    else dp[0][i]=dp[2][i-1]+luck[0][i];
    
    if (dp[2][i-1]+luck[1][i]>dp[0][i-1]+luck[1][i]){
      dp[1][i]=dp[2][i-1]+luck[1][i];
    }
    else dp[1][i]=dp[0][i-1]+luck[1][i];
    
    if (dp[0][i-1]+luck[2][i]>dp[1][i-1]+luck[2][i]){
      dp[2][i]=dp[0][i-1]+luck[2][i];
    }
    else dp[2][i]=dp[1][i-1]+luck[2][i];
  }
  max=judge(dp[0][n-1],dp[1][n-1],dp[2][n-1]);
  printf("%ld\n",max);
  return 0;
}
long judge(long a,long b,long c){
  long max=a;
  if (b>max) max=b;
  if (c>max) max=c;
  return max;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll n, k; cin >> n >> k;
	string s; cin >> s;
	ll a{0};

	REP(i, n-1)
	{
		a += s[i] != s[i+1];
	}
	std::cout << n-1-max(a-2*k, 0ll)<< std::endl;
}


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

int main() {
  // 1桁ずつの配列にする. Nは桁数=Tの長さ
  long long S;cin >> S;
  int N=0;
  vector<int> T(0);
  while(S>0){
    T.push_back(S%10);
    S/=10;
    N++;
  }
  reverse(T.begin(),T.end());
  
  //ビット全探索
  long long ans=0;
  for (int tmp = 0; tmp < (1 << N-1); tmp++) {
    bitset<10> s(tmp);
    int k=0;
    vector<long long> U(1);
    U.at(0)=T.at(0);
    for (int i=1;i<N;i++){
      if (s.test(i-1)){
        U.push_back(T.at(i));
        k++;
      }else{
        U.at(k)=(long long)U.at(k)*10+T.at(i);
      }
    }
    for (int i=0;i<=k;i++){
      ans+=U.at(i);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX=100005;

long long int dp[MAX];
int main(){
    long long int N,W;
    cin >> N >> W;
    long long int i,j;
    long long int ans=0;
    long long int w,v;
    long long int sum=0;
    for(i=1;i<MAX;i++)dp[i]=1e9+7;
    dp[0]=0;
    for(i=0;i<N;i++){
        cin >> w >> v;
        sum+=v;
        for(j=sum-v;j>=0;j--){
            if(dp[j+v]>w+dp[j])dp[j+v]=w+dp[j];
        }
    }
    for(i=1;i<MAX;i++)if(dp[i]<=W)ans=i;
    cout << ans << endl;
}

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

int main() {
    int numItems;
    cin >> numItems;
    int maxWeight;
    cin >> maxWeight;

    int items[numItems][2];
    for(int i = 0; i < numItems; i++) {
        cin >> items[i][0]; //weight
        cin >> items[i][1]; //value
    }

    vector<unsigned long int> maxValue(maxWeight+1, 0);
    
    for(int weight = items[0][0]; weight <= maxWeight; weight++) {
        maxValue[weight] = items[0][1];
    }

    for(int item = 1; item < numItems; item++) {
        for(int weight = maxWeight; weight >= 0; weight--) {
            if(items[item][0] <= weight) {
                maxValue[weight] = max(maxValue[weight],  
                                       maxValue[weight - items[item][0]] + items[item][1]);
            }
        }
    }
    
    cout << maxValue[maxWeight];

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;



int main(){
    ll A, B, X;
    cin>>A>>B>>X;
    bool OK=false;
    for(ll i=A; i<=A+B; i++){
        if(i==X)OK=true;
    }
    YES(OK);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	llong a,b,c,k;
	cin>>a>>b>>c>>k;
	
	llong ans=0;
	if(a<k){
		ans+=a;
		k-=a;
	}else{
		ans+=k;
		k=0;
	}
	k-=b;
	if(k>0) ans-=k;
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#C
import numpy as np
x,n=map(int,input().split())
ans=0
b_list=[]
if n==0:
    ans=x
else:
    p_list=list(map(int,input().split()))
    
    s=x-int(n/2)-1
    g=x+int(n/2)+1
    ans_list=[]
    for i in range(s,g+1):
        if i not in p_list:
            b_list.append(i)
    #print(b_list)
    ans=b_list[0]
    for i in b_list[1:]:
        if abs(x-i)<abs(x-ans):
            ans=i
        else:  
            break

                
print(ans)    

Measured memory_bytes: 27172
S = input()
Q = int(input())
before_chr = []
after_chr = []
reverse_status = 1
for i in range(Q):
    query = list(input().split())
    if query[0] == "1":
        reverse_status *= -1
    elif reverse_status * (1.5-int(query[1])) == 0.5:
        before_chr += query[2]
    else:
        after_chr += query[2]
if reverse_status == 1:
    print("".join(before_chr[::-1])+S+"".join(after_chr))
else:
    print("".join(after_chr[::-1])+S[::-1]+"".join(before_chr))

Measured memory_bytes: 6256
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        int [] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        if(n[0] > n[1]){
            System.Console.WriteLine("a > b");
        }else if(n[0] == n[1]){
            System.Console.WriteLine( "a == b");
        }else{
            System.Console.WriteLine("a < b");
        }
    }
}



Measured memory_bytes: 18400