akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

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

  ll ans = 0;
  ll bc = 0;
  char prev = ' ';
  rrep(i, S.size()){
    if(S[i] != 'B' && prev == 'C') bc = 0;
    if(S[i] == 'A') ans += bc;
    else if(S[i] == 'B' && prev == 'C') bc++;
    else if(S[i] != 'C') bc = 0;
    prev = S[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        WriteLine(N < 1000 ? "ABC" : "ABD");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int main(){
    int n;
    vector <int>a;
    cin >> n;
    for(int i=0;i<n;i++){
        int in;
        cin >> in;
        a.push_back(in);
    }
    while(a.size()!=1){
        sort(a.begin(),a.end());
        while(a[0]== 0){
            a.erase(a.begin());
        }
        for(int i=1;i<a.size();i++){
            a[i] = a[i]%a[0];
        }
    }
    cout << a[0] << endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k;
    string str;
          cin>>str;

            for(i=0;i<str.size();i++)
            {
                if(i==0)
                {
                    cout<<"2";
                }
                else if(i==1)
                {
                   cout<<"0";
                }
                else if(i==2)
                {
                    cout<<"1";
                }
                else if(i==3)
                {
                    cout<<"8";
                }
                else{
                    cout<<str[i];
                }
            }
            cout<<endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var A = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }

            var max1 = 0;
            var max2 = 0;
            var maxId1 = 0;
            var maxId2 = 0;
            if (A[0] > A[1])
            {
                max1 = A[0];
                maxId1 = 0;
                max2 = A[1];
                maxId2 = 1;
            }
            else
            {
                max1 = A[1];
                maxId1 = 1;
                max2 = A[0];
                maxId2 = 0;
            }

            for (int i = 2; i < A.Length; i++)
            {
                if (A[i] > max1)
                {
                    max2 = max1;
                    maxId2 = maxId1;
                    max1 = A[i];
                    maxId1 = i;
                }
                else if (A[i] > max2)
                {
                    max2 = A[i];
                    maxId2 = i;
                }
            }

            for (int i = 0; i < N; i++)
            {
                if (i == maxId1)
                {
                    Console.WriteLine(max2);
                }
                else
                {
                    Console.WriteLine(max1);
                }
            }
        }
    }
}

Measured memory_bytes: 18480
#include<bits/stdc++.h>
#define maxn 200005
#define mod 1000000007
using namespace std;
int deg[maxn],a[maxn],incy[maxn],vis[maxn],svis[maxn],n;
int chlen[maxn],cnt[maxn];
int ans=1;
int add(int a,int b){a+=b; return a>=mod?a-mod:a;}
void SolveCyc(int x)
{
	int t=x; x=a[x],svis[t]=svis[x]=1;
	int fi=0,fpos=0,la=0,len=1;
	while(1)
	{
		while(!chlen[x]&&x!=t) x=a[x],svis[x]=1,len++;
		if(chlen[x])
		{
			if(!fi) fi=x,la=len,fpos=len;
			else
			{
				int coef=(len-la>=chlen[x])+(len-la>chlen[x]);
				ans=1ll*ans*coef%mod,la=len;
			}
		}
		if(x==t) break;
		x=a[x],svis[x]=1,len++;
	}
	if(chlen[t])
	{
		if(!fi) fi=t;
		else la=len;
	}
	if(!fi) cnt[len]++;
	else
	{
		int coef=(len-la+fpos>=chlen[fi])+(len-la+fpos>chlen[fi]);
		ans=1ll*ans*coef%mod;
	}
}
int dp[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),deg[a[i]]++;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		int nw=i; while(!vis[nw]) vis[nw]=i,nw=a[nw];
		if(vis[nw]!=i) continue;
		int t=nw; incy[nw]=1,nw=a[nw];
		while(nw!=t) incy[nw]=1,nw=a[nw];
	}
	for(int i=1;i<=n;i++)
		if(((!incy[i])&&deg[i]>=2)||deg[i]>=3) return puts("0"),0;
	for(int i=1;i<=n;i++)
	{
		if(deg[i]) continue;
		int nw=i; while(!incy[nw]) chlen[a[nw]]=chlen[nw]+1,nw=a[nw];
	}
	for(int i=1;i<=n;i++)
		if(incy[i]&&!svis[i]) SolveCyc(i);
	for(int i=1;i<=n;i++)
	{
		if(!cnt[i]) continue;
		dp[0]=1;
		for(int j=1;j<=cnt[i];j++)
		{
			if(i>1&&(i&1)) dp[j]=add(dp[j-1],dp[j-1]);
			else dp[j]=dp[j-1];
			if(j>1) dp[j]=add(dp[j],1ll*dp[j-2]*(j-1)%mod*i%mod);
		}
		ans=1ll*ans*dp[cnt[i]]%mod;
	}
	printf("%d\n",ans);
	return 0;
}
 

Measured memory_bytes: 4736
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<int> tree[SIZE];
ll dp[SIZE][2];

void dfs(int now, int prev = -1){
  dp[now][0] = dp[now][1] = 1;

  for(int i=0;i<tree[now].size();i++){
    int to = tree[now][i];
    if (to == prev) continue;
    dfs(to, now);
    dp[now][0] = dp[now][0] * (dp[to][0] + dp[to][1]) % mod;
    dp[now][1] = dp[now][1] * dp[to][0] % mod;
  }
}

int main(){
  int n;

  scanf("%d", &n);

  for(int i=0;i<n-1;i++){
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  dfs(0);

  cout << (dp[0][0] + dp[0][1]) % mod << endl;

  return 0;
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<int> a(200010, 0);
  vector<int> flag(200010, 0);
  for(int i = 1; i <= n; i++) cin >> a[i];
  
  int pos = 1, cnt = 0;
  while(k) {
    pos = a[pos];
    k--;
    cnt++;
    if(flag[pos]) k %= (cnt-flag[pos]);
    else flag[pos] = cnt;
  }
  cout << pos << "\n";
}

Measured memory_bytes: 4844
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
bingo = [[0 for _ in range(3)] for _ in range(3)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                bingo[j][k] += 1

for i in range(3):
    if bingo[0][i] * bingo[1][i] * bingo[2][i] > 0:
        print('Yes')
        exit()
for i in range(3):
    if bingo[i][0] * bingo[i][1] * bingo[i][2] > 0:
        print('Yes')
        exit()
if bingo[0][0] * bingo[1][1] * bingo[2][2] > 0:
    print('Yes')
    exit()
if bingo[0][2] * bingo[1][1] * bingo[2][0] > 0:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3064
#include <stdio.h>
#define isNum(A) (A<='9' && A>='0')
#define SIZE 99
#define max(a,b) (a>b ? a : b)

int map[SIZE][SIZE];

int main(void)
{
     int i, j, n, t;
     char ch = getchar();

     /* init */
     for(i=0; i<SIZE; i++)
	  for(j=0; j<SIZE; j++)
	       map[i][j] = 0;
	  
     /* input */
     i = j = n = 0;
     while(ch!=EOF){
	  t = 0;
	  while(isNum(ch)) t = t*10+ch-'0', ch = getchar();
	  map[i][j] = t;
 
	  j++;
	  if(ch == '\n'){
	       if(j>n) n = j;
	       j = 0, i++;
	  }

	  ch = getchar();
     }

     /* calc */
     for(i=1; i<n; i++){
	  map[i][0] += map[i-1][0];

	  for(j=1; j<=i; j++)
	       map[i][j] += max(map[i-1][j], map[i-1][j-1]);
     }

     for(i=0; i<n-1; i++)
	  for(j=0; j<=n-i-1; j++)
	       map[n+i][j] += max(map[n+i-1][j], map[n+i-1][j+1]);

     printf("%d\n",map[n*2-2][0]);
     
     return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#define INF 20000000
#define MAX 100

int prim_method();

int n,color[MAX],M[MAX][MAX],d[MAX],p[MAX];

int main(){
int i,j;

scanf ("%d",&n);

for(i=0; i<n; i++) {
   for(j=0; j<n; j++) {
           scanf("%d",&M[i][j]);
           if(M[i][j]==-1) {
                   M[i][j]=INF;
           }
   }
}


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

return 0;
}

int prim_method(){
    int u,Minv,i,v,sum=0;

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

    d[0]=0;


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

        if(Minv==INF) {
            break;
        }

        color[u]=2;

        for(v=0; v<n; v++) {
            if(color[v]!=2 && M[u][v]!=INF) {
                if(M[u][v]<d[v]) {
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=1;
                }
            }
       }
}

    for(i=0; i<n; i++) {
        if(p[i]!=-1) {
                sum+=M[i][p[i]];
           }
}

return sum;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
		freopen("input.txt", "r", stdin),
		freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,a=0;
	cin >> n;
	string st[n];
	for(int i=0;i<n;i++)
		cin >> st[i];
	map <string,int> m;
	for(int i=0;i<n;i++){
		m[st[i]]++;
		a=max(m[st[i]],a);
	}
	for(auto i:m){
		if(i.s==a)
			cout << i.f << endl;
	}
}

Measured memory_bytes: 25472
n = int(input())
rlist = [[]]
alist = [[]]
for i in range (n):
    alist.append(input().split())
    rlist.append([0]*n)
alist.pop(0)
rlist.pop(0)
for i in range(n):
    for j in range(2,len(alist[i])):
        rlist[i][int(alist[i][j])-1] = 1
    print(*rlist[i])


Measured memory_bytes: 6380
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<random>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ll Mod=1000000007;
short gh[2][4] = { {0,0,-1,1},{-1,1,0,0} };
struct P {
ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
ll to, cost;
};
struct S {//辺の情報を入れる変数
int from, to, cost;
};
struct H {
int x, y;
};
bool operator<(H a, H b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
ll gcm(ll i, ll j) {//最大公約数
if (i > j) swap(i, j);
if (i == 0) return j;
return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
if (b <= c || d <= a) return 0;
return 1;
}//[a,b),[c,d)
ll mod_pow(ll x,ll n,ll p){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%p;
        x=x*x%p;
        n>>=1;
    }
    return res;
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
string a,b;
signed main() {
	cin>>a>>b;
	int s=stoi(a+b);
	for(int i=0;i<10000;i++){
		if(s==i*i){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
    getchar(); getchar();
}


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

int n;
string a[1000];
map<string, int> m;

int main(){
    cin >> n;
    cin >> a[1];
    m[a[1]]++;
    bool check = true;
    for (int i = 2; i <= n; i++){
        cin >> a[i];
        if (m[a[i]] > 0 || a[i][0] != a[i-1][a[i-1].size() - 1]){
            cout << "No";
            check = false;
            break;
        }
        else m[a[i]]++;
    }
    if (check) cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9 + 7;

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

  LL dp[100005][13];
  rep(i, n + 1) {
    rep(j, 13) dp[i][j] = 0;
  }
  dp[0][0] = 1;
  rep(i, n) {
    int t;
    if (s[i] == '?') t = -1;
    else t = s[i] - '0';

    rep(j, 10) {
      if (t != -1 && t != j) continue;
      rep(k, 13) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }
    rep(j, 13) dp[i + 1][j] %= mod;
  }

  cout << dp[n][5] << endl;
}

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

int main(){
    ll n;
    cin >> n;
    ll minans=1e14;

    for(ll i=1; i<=min(n,1000000ll); i++){
        if(n%i==0) minans=min(minans,i+n/i-2);
    }
    cout << minans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, a[MAXN], dp[MAXN], k;
ll infi = 1e9;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
    	cin >> a[i];
    }
    for(int i = n - 2; i >= 0; i--){
    	dp[i] = infi;
    	for(int j = 1; j <= k; j++){
    		if(i + j >= n) break;
    		dp[i] = min(dp[i], dp[i + j] + abs(a[i] - a[i + j]));
    	}
    }
    cout << dp[0];
}

Measured memory_bytes: 1024
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
struct UFS{
	int n,par[100005];
	void init(int _n){
		n=_n;
		for(int i=1;i<=n;i++)par[i]=i;
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		par[find(x)]=find(y);
	}
	bool same(){
		for(int i=1;i<=n;i++)if(find(i)!=find(1))return false;
		return true;
	}
}uf;
int n,m;
int pre[100005];
int main(){
	memset(pre,-1,sizeof pre);
	cin>>n>>m;uf.init(n);
	for(int i=1;i<=n;i++){
		int k;cin>>k;
		while(k--){
			int x;cin>>x;
			if(~pre[x])uf.unite(pre[x],i);
			pre[x]=i;
		}
	}
	cout<<(uf.same()?"YES":"NO");
	return 0;
}

Measured memory_bytes: 1920
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val map = mutableMapOf<Int, Int>()
    var ans = 0L
    for (i in 0 until n) {
        ans += map[i - a[i]] ?: 0
        map[a[i] + i] = (map[a[i] + i] ?: 0) + 1
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 68680
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x_sum = 0
for k, value in enumerate(x):
    x_sum += (2 * (k + 1) - n - 1) * value
    x_sum %= MOD

y_sum = 0
for k, value in enumerate(y):
    y_sum += (2 * (k + 1) - m - 1) * value
    y_sum %= MOD

print ((x_sum * y_sum) % MOD)





Measured memory_bytes: 18576
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
x = 1
for v in a:
    x = x * v
    if x > 1000000000000000000:
        x = 1000000000000000001
if x > 1000000000000000000:
    print(-1)
else:
    print(x)


Measured memory_bytes: 83592
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

struct UnionFind {
  std::vector<ll> data;

  UnionFind(ll n) { data.assign(n, -1); }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }

  int find(int k) {
    if (data[k] < 0) return k;
    return data[k] = find(data[k]);
  }

  ll size(int k) { return -data[find(k)]; }

  bool same(int x, int y) { return find(x) == find(y); }
};

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> m;
  rep(i, n) cin >> a[i], a[i]--;
  UnionFind uf(n + 10);
  rep(i, m) {
    cin >> x >> y;
    x--, y--;
    uf.unite(x, y);
  }
  rep(i, n) {
    if (uf.same(i, a[i])) ans++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 1792
N = gets.to_i
ary = gets.split.map(&:to_i)
cnt = 1
if N > 1
    plus_mode = 0 # -1: 減少中, 0: 未決定, 1: 増加中
    1.upto(ary.size-1) do |n|
        case plus_mode
        when -1
            if ary[n] > ary[n-1]
                cnt += 1
                plus_mode = 0
            end
        when 0
            if ary[n] > ary[n-1]
                plus_mode = 1
            elsif ary[n] < ary[n-1]
                plus_mode = -1
            end
        when 1
            if ary[n] < ary[n-1]
                cnt += 1
                plus_mode = 0
            end
        end
    end
end
puts cnt

Measured memory_bytes: 8460
m = int(input())
while m:
    m -= 1
    ax, ay, bx, by = map(int, input().split())
    n = int(input())
    dx, dy = bx - ax, by - ay
    intersections = set()
    while n:
        n -= 1
        sx, sy, tx, ty, o, l = map(int, input().split())
        tdx, tdy = tx - sx, ty - sy
        asx, asy = sx - ax, sy - ay
        denom = dx * tdy - dy * tdx
        if not denom:
            continue
        r = (tdy * asx - tdx * asy) / denom
        s = (dy * asx - dx * asy) / denom
        if not 0 < r < 1 or not 0 < s < 1:
            continue
        intersections.add((r, o == l))

    intersections = [l[1] for l in sorted(intersections)]
    print(sum(i != j for i, j in zip(intersections, intersections[1:])))

Measured memory_bytes: 7784
# coding: utf-8
# Your code here!

from collections import deque

N = int(input())
mon = deque(list(map(int, input().split())))
pla = deque(list(map(int, input().split())))
array = []
a, b, c = 0, 0, 0

for i in range(N):
    a = mon.popleft()
    b = pla.popleft()
    if a < b:
        array.append(a)
        array.append(min((b - a), mon[0]))
        mon[0] -= min((b - a), mon[0])
    else:
        array.append(b)

print(sum(array))

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

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

  int n, l;
  cin >> n >> l;
  int sum_val = 0, min_val = 1e9;
  rep(i, 1, n + 1) {
    int taste = l + i - 1;
    if (abs(min_val) > abs(taste))
      min_val = taste;
    sum_val += taste;
  }
  cout << sum_val - min_val << endl;
}


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

int main(void){
    ll n0,q0;
    cin>>n0>>q0;
    string s;
    cin>>s;
    ll l[n0],r[n0],c=0;
    rep(0,i,n0){
        l[i]=-1;
        r[i]=-1;
    }
    rep(0,i,n0){
        string s0=s.substr(i,2);
        if(s0=="AC"){
            l[i]=c;
            l[i+1]=c+1;
            r[i]=c;
            r[i+1]=c;
            ++c;
        }else{
            if(l[i]==-1)l[i]=c;
            if(r[i]==-1)r[i]=c;
        }
    }
    //rep(0,i,n0)cout<<"l["<<i<<"]="<<l[i]<<" r["<<i<<"]="<<r[i]<<endl;
    rep(0,i,q0){
        ll l0,r0;
        cin>>l0>>r0;
        --l0,--r0;
        //cout<<"l["<<l0<<"]="<<l[l0]<<" r["<<r0<<"]="<<r[r0]<<endl;
        //cout<<r[r0-1]<<" "<<l[l0-1]<<endl;
        cout<<l[r0]-l[l0]<<endl;
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
string s;cin>>s;
ll cnt=0;

for(int i=0;i<s.size();i++)
{if(s[i]=='1')cnt+=1;
if(s[i]=='2')cnt+=2;
if(s[i]=='3')cnt+=3;
if(s[i]=='4')cnt+=4;
if(s[i]=='5')cnt+=5;
if(s[i]=='6')cnt+=6;
if(s[i]=='7')cnt+=7;
if(s[i]=='8')cnt+=8;
if(s[i]=='9')cnt+=9;}

if(cnt%9==0)cout<<"Yes"<<endl;
if(cnt%9!=0)cout<<"No"<<endl;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
char x;
int a[105][105],n,m;
int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	{
		cin>>x;
		if (x=='#')
		{
			a[i][j]=-100;
			a[i-1][j]++;
			a[i+1][j]++;
			a[i-1][j+1]++;
			a[i-1][j-1]++;
			a[i+1][j+1]++;
			a[i+1][j-1]++;
			a[i][j+1]++;
			a[i][j-1]++;
		}
	}

	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			if (a[i][j]<0) cout<<"#";
			else cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String tmp = sc.nextLine();
		char[] c = tmp.toCharArray();
		for(int i = 0; i < c.length; i++){
			if(c[i] >= 'a' && c[i] <= 'z' ){
				c[i] -= 32;
			}else if(c[i] >= 'A' && c[i] <= 'Z'){
				c[i] += 32;
			}
		}
		System.out.println(String.valueOf(c));
	}
}

Measured memory_bytes: 26088
#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <assert.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<int,ull> piu;
typedef pair<ull,ull> puu;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<ll,pll> plP;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<29)
#define INFL (1LL<<61)
#define fi first
#define se second
#define EPS 1e-9
#define MOD 1000000007
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(__,x.size())printf("%d%c",x[__],__+1==x.size()?'\n':' ')

int N;
int A[100000];

int main()
{
	scanf("%d",&N);
	rep(i,N)scanf("%d",&A[i]);
	sort(A,A+N);
	vector<int> c2;
	ll res=0;
	rep(i,N-1)if(A[i]==A[i+1])c2.pb(A[i]);
	SORT(c2);ERASE(c2);
	if(c2.size()>=2)res=ll(c2[c2.size()-1])*c2[c2.size()-2];
	rep(i,N-3)if(A[i]==A[i+1]&&A[i+1]==A[i+2]&&A[i+2]==A[i+3])
		MAX(res,ll(A[i])*A[i]);
	printf("%lld\n",res);
}

Measured memory_bytes: 1276
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    s = input()
    ques_count = s.count('?')
    base_num = 1
    rem_list = []
    for _ in range(len(s)):
        rem_list.append(base_num % 13)
        base_num = base_num * 10 % 13
    rem_list = rem_list[::-1]

    rem1 = 0
    for index, si in enumerate(s):
        if si != '?':
            si_int = int(si)
            rem1 = rem1 + si_int * rem_list[index]
    rem1 = rem1 % 13

    dp = [[0] * 13 for _ in range(ques_count + 1)]
    dp[0][rem1] = 1
    dp_index = 1
    for index, si in enumerate(s):
        if si == '?':
            rem_cdd_list = [rem_list[index] * i % 13 for i in range(10)]
            for rem in rem_cdd_list:
                for i in range(13):
                    dp[dp_index][i] = (dp[dp_index][i] + dp[dp_index - 1][(i - rem) % 13]) % (10 ** 9 + 7)
            dp_index = dp_index + 1
    # print(dp)
    print(dp[ques_count][5])

# 各桁について13で割ったときの余りを求めておく
# 確定した桁に対する余りを求める

# 0,1,2  0,3,4  0,5,6 i番目の?までを使って余りをjにできる場合数
# (a-i) mod d = (a mod d - i mod d) mod d = (a mod d - i) mod d


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

using namespace std;
typedef long long ll;
#define all(v) (v).begine(), (v).end()
#define pb push_back
#define vector <int> vi
#define in(n) cin >> n
#define out(n) cout << n << '\n'
#define rep(i, n) for (ll i = 0; i < (n); i++)
const int inf = 1000000000;

void solve()
{
    int a, b;
    in(a);
    in(b);
    out(a * b);
}

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

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

bool dp[1000002], sosu[1000002];
int n, x;
int v[30];

void sosuu() {
  sosu[0]=false;
  sosu[1]=false;
  for(int i=2; i*i<=x; i++) {
    if (sosu[i]) {
      for (int j=2*i; j<=x; j+=i) {
        sosu[j] = false;
      }
    }
  }
}
  

int main() {
  while(cin >> n >> x, n) {
    rep(i, n)
      cin >> v[i];
    rep(i, x+1) {
      sosu[i] = true;
      dp[i] = false;
    }
    sosuu();
    rep(i, n) {
      dp[v[i]]=true;
      for(int j=1; j<=x; j++)
        if(dp[j] && j+v[i] <= x)
          dp[j+v[i]] = true;
    }
    while(x>0) {
      if(dp[x] && sosu[x])
        break;
      x--;
    }
    if(x==0)
      cout << "NA" << endl;
    else
      cout << x << endl;
  }

  return 0;
}

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

int main(){
    int n,t;
    cin >> n >> t;
    vector<int> a(n);
    map<int,int> mp;
    for(int i = 0;i < n;i ++){
        cin >> a[i];
        mp[a[i]] ++;
    }
    int max=0,smax=0,cnt=0;
    for(int i = 0;i < n;i ++){
        int sub=mp.rbegin()->first-a[i];
        if(sub==0){
            if(smax==max) cnt ++;
            if(smax>max) {cnt=1,max=smax;}
            smax=0;
        }else if(sub>smax) smax = sub;
        mp[a[i]] --;
        if(!mp[a[i]]) mp.erase(a[i]);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll a,b; cin >> a >> b;
  if((a+b)%2==0) cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}



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

void display(int array[], int length) {
	for (int i = 0; i < length-1; i++) {
		cout << array[i] << " ";
	}

	cout << array[length-1] << endl;
}

void insertion_sort(int A[], int length) {
	for (int j = 1; j < length; j++) {
		display(A, length);
		int key = A[j];
		int i = j -1;
		// Insert key into the sorted array A[1...j-1]
		while (i >= 0 && A[i] > key) {
			A[i+1] = A[i];
			i--;
		}
		A[i+1] = key;
	}
	display(A, length);
}

int main() {
	int length;
	cin >> length;
	int array[length];
	
	for (int i = 0; i < length; i++) {
		cin >> array[i];
	}

	insertion_sort(array, length);

	return 0;
}

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

void output(int A[], int n){
	int i;
	for (i = 0; i < n; i++)
	{
		if (i>0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void sort_(int A[],int n){
	int i, j, k;
	for (i = 1; i < n; i++)
	{
		k = A[i];
		j = i - 1;
		while (j >= 0 && A[j]>k){
			A[j+1] = A[j];
			j--;
		}
		A[j + 1] = k;
		output(A, n);
	}
}


int main(){
	int n, A[100];

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> A[i];
	}
	output(A, n);
	sort_(A, n);



	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define pb              push_back
#define pi              acos(-1.0)
#define loop(i,a,n)     for(int i=a;i<n;i++)
#define rloop(i,n,a)    for(int i=n;i>=a;i--)
#define ll              long long int
#define ff              first
#define ss              second
#define pii             pair<ll,ll>
#define sc1(a)          scanf("%d",&a)
#define sc2(a,b)        scanf("%d %d",&a,&b)
#define sc3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define all(v)          v.begin(),v.end()
#define ms(a,b)         memset(a,b,sizeof a)
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define fileout         freopen("output.txt","w",stdout)
#define filein          freopen("input.txt","r",stdin)
#define inf             2e9+5
#define Q               int q;cin>>q;while(q--)
#define check           cout<<"HI"<<endl;

//int x[]= {-1,0,0,1};
//int y[]= {0,-1,1,0};

using namespace std;

int main()
{
    int n;
    ll ans=0;
    cin >> n;
    ll a[n+5];
    ll b[100005]={0};
    loop(i,0,n)
    {
        cin >> a[i];
        b[a[i]]++;
        ans+=a[i];
    }
    ll q,x,y;
    cin >> q;
    loop(i,0,q)
    {
        cin >> x >> y;
        ans=ans-(b[x]*x+b[y]*y);
        b[y] += b[x];
        ans = ans+b[y]*y;
        b[x]=0;
        //loop(i,0,5)cout<<b[i]<<" ";
        //cout<<endl;
        cout<<ans<<endl;
    }


}












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

int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    int m = INF;
    int ans = 0;
    rep(i,n) {
        int p;
        cin >> p;
        if (p <= m) ans++;
        m = min(p, m);
    }
    cout << ans << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	set<int> edge[n];
	int u,v;
	for (int i = 0; i < m; ++i)
	{
		cin>>u>>v;--u;--v;
		edge[u].insert(v);
	}
	int s,t;
	cin>>s>>t;--s;--t;
	int memo[n][3];
	for (int i = 0; i < n; ++i)
	{
		memo[i][0]=-1;
		memo[i][1]=-1;
		memo[i][2]=-1;
	}
	memo[s][0]=0;
	queue<int> que;
	que.push(3*s);
	while(que.size()>0)
	{
		int now=que.front();
		que.pop();
		for (auto i = edge[now/3].begin(); i != edge[now/3].end(); ++i)
		{
			if (memo[*i][(now+1)%3]==-1)
			{
				memo[*i][(now+1)%3]=memo[now/3][now%3]+1;
				que.push((*i)*3+((now+1)%3));
			}
		}
	}
	if (memo[t][0]>0)
	{
		memo[t][0]/=3;
	}
	cout<<memo[t][0]<<endl;
	return 0;
}


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};


//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(int h, w; cin >> h >> w, h | w;){
		VVI table(h, VI(w));
		REP(i, h){
			string line;
			cin >> line;
			REP(j, w){
				char letter = line[j];
				int value = -1;
				if(letter == '@'){
					value = -1;
				}else if(letter == '#'){
					value = -2;
				}else if(letter == '*'){
					value = -3;
				}
				table[i][j] = value;
			}
		}

		int total = 0;
		REP(i, h){
			REP(j, w){
				if(table[i][j] >= 0) continue;
				total++;
				int fruit = table[i][j];
				table[i][j] = total;
				queue<PII> q;
				q.push(MP(i, j));
				int l = 0;
				while(!q.empty()){
					PII p = q.front();
					q.pop();
					int x = p.second, y = p.first;
					REP(k, 4){
						int dx = x + DX[k];
						int dy = y + DY[k];
						if(0 <= dx && dx < w &&
							0 <= dy && dy < h &&  (table[dy][dx] != total && table[dy][dx] == fruit)){
							table[dy][dx] = total;
							q.push(MP(dy, dx));
						}
					}
				}
			}
		}
		cout << total << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1280
n = int(input())
A = list(map(int,input().split()))

A.sort()
v = A[-1] - A[0]
if v >= 2:
    print('No')
elif v == 0:
    if A[0]*2 <= n or A[0] == n-1:
        print('Yes')
    else:
        print('No')
else:
    x = A.index(A[-1])
    y = A[0] - x + 1
    if y > 0 and y*2 <= n-x:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 14092
# -*- coding: utf-8 -*-
loop = 1
while(loop):
    l = input().strip().split()
    H = int(l[0])
    W = int(l[1])
    if(H == 0 and W == 0):
        break
    else:
        for y in (range(H)):
            for x in (range(W)):
                if(x == 0 or y == 0 or x == (W-1) or y == (H-1)):
                    print("#",end="")
                else:
                    print(".",end="")
            print()
        print()

Measured memory_bytes: 8948
#include <bits/stdc++.h> 
using namespace std;
const int N = 1e5+5; 
struct Node{
	int idx;
	int group;
	int time;
	int rank;
}node[N]; 
bool cmp1(Node a,Node b){
	if(a.group==b.group){
		return a.time<b.time;
	}
	return a.group<b.group;
}
bool cmp2(Node a,Node b){
	return a.idx<b.idx;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		Node t;
		t.group=a;
		t.idx=i;
		t.time=b;
		node[i]=t;
	}
	sort(node+1,node+k+1,cmp1);
	int a=1,rank=1;
	for(int i=1;i<=k;i++){
		if(node[i].group!=a){
			a=node[i].group;
			rank=1;
		}
		node[i].rank=rank++;
//		cout<<node[i].group <<" "<<node[i].time<<endl;
	}
	sort(node+1,node+k+1,cmp2);
	for(int i=1;i<=k;i++){
		printf("%06d%06d\n",node[i].group,node[i].rank);
	}
}

Measured memory_bytes: 3072
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();

		int[][] a = new int[x][y];
		int[][] b = new int[y][z];

		for(int i=0;i<x;i++) {
			for(int j=0;j<y;j++) {
				a[i][j] = sc.nextInt();
			}
		}

		for(int i=0;i<y;i++) {
			for(int j=0;j<z;j++) {
				b[i][j] = sc.nextInt();
			}
		}

		long tmp = 0;

		for(int i=0;i<x;i++) {
			for(int j=0;j<z;j++) {
				for(int k=0;k<y;k++) {
					tmp += a[i][k] * b[k][j];
				}
				System.out.print(tmp);
				if(j!=z-1) {
					System.out.print(" ");
				}
				tmp = 0;
			}
			System.out.println();
		}

		sc.close();
	}
}


Measured memory_bytes: 54724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 21 + 1, INF = 1e15, MOD = 1e9 + 7, max_mask = (1LL << 21) + 5;
bool compat[max_N][max_N];
ll DP[max_N][max_mask], N, done;

ll match_ways(ll pos, ll mask)
{
    if (pos == N)
        return (mask == done);
    ll &res = DP[pos][mask];
    if (res != -1)
        return res;
    res = 0;
    for (int i = 0; i < N; ++i)
    {
        if (mask & (1LL << i))
            continue;
        if (!compat[pos][i])
            continue;
        res += match_ways(pos + 1, mask | (1LL << i));
        if (res >= MOD)
            res -= MOD;
    }
    return res;
}

int main()
{
    cin >> N;
    done = (1LL << N) - 1;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            cin >> compat[i][j];
    memset(DP, -1, sizeof(DP));
    cout << match_ways(0, 0) << "\n";
    return 0;
}

Measured memory_bytes: 364080
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int n , k;
ii a[maxn];
ll res[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w  ",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].first;a[i].second = i;
    }
    sort(a + 1 , a + n + 1);
    int pre = n;
    for(int i = n ; i >= 1 ; --i){
        pre = min(pre , a[i].second);
        res[pre] += (a[i].first - a[i - 1].first) * (ll)(n - i + 1);
    }
    for(int i = 1 ; i <= n ; ++i)cout << res[i] << '\n';
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;
int main() {
  int n;
  vector<int> a;
  int tmp;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }

  int on = 1;
  for (int i = 0; i < n; i++) {
    on = a[on-1];
    if (on == 2) {
      cout << i+1 << endl;
      return 0;
    }
  }

  cout << "-1" << endl;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int a;
  cin >> a;
  cout << a / 500 * 1000 + (a - a / 500 * 500) / 5 * 5 << "\n";
  return 0;
}

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

constexpr int N = 200000;
int A[N];

int main() {
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    for (int i=0;i<n;++i) std::cin >> A[i];
    std::sort(A, A+n);
    bool result = false;
    for (int i=1;i<n;++i) {
        result |= A[i-1] == A[i];
    }
    std::cout << (result ? "NO" : "YES") << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  cout << (800 * n) - 200 * (n / 15) << endl;
  return 0;
}


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

bool isKaibun(int num) {
    vector<int> v(5);
    int i = 0;
    while(num) {
        v.at(i) = num % 10;
        num /= 10;
        ++i;
    }
    if (v.at(0) == v.at(4) && v.at(1) == v.at(3)) {
        return true;
    } else {
        return false;
    }
}

int main() {
    int a, b;
    cin >> a >> b;

    int res = 0;
    for (int i = a; i <= b ; ++i) {
        if (isKaibun(i)) {
            ++res;
        }        
    }

    cout << res << endl;
    return 0;

}


Measured memory_bytes: 3624