akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


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

    int n, m;
    cin>>n>>m;

    vector<string> a(n);
    for (int i=0; i<n; i++) cin>>a[i];

    for (int i=0; i<n; i++) {
        string ans;
        for (int j=0; j<m; j++) {
            if (j==0)                   ans += '#';
            else if (j == m-1)          ans += '.';
            else if (a[i][j] == '#' || i%2)  ans += '#';
            else                        ans += '.';
        }
        cout<<ans<<endl;
    }
    cout<<endl;
    for (int i=0; i<n; i++) {
        string ans;
        for (int j=0; j<m; j++) {
            if (j==0)                  ans += '.';
            else if (j == m-1)          ans += '#';
            else if (a[i][j] == '#' || i%2==0)  ans += '#';
            else                        ans += '.';
        }
        cout<<ans<<endl;
    }
}


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

int main(){
  string s;
  int K,count=0;
  cin>>s>>K;
  int N = s.size();  
  set<string> S;

  for(int i=0;i<N;i++){
    for(int j=0;j<N-i;j++){
      if(j+1>K)
        break;
      count++;
      string t = s.substr(i,j+1);
      S.insert(t);
    }
  }
  auto ite = S.begin();
  for(int i=1;i<K;i++)
    ite++;
  cout<<*ite<<endl;
}


Measured memory_bytes: 1664
import kotlin.math.*

fun main() {
    println(solve())
}

val solve: () -> Any = {
    val (X, K, D) = readLongList()
    val n = X.absoluteValue / D
    (X.absoluteValue - when {
        n > K -> K * D
        (K - n) % 2 == 0L -> n * D
        else -> (n+1) * D
    }).absoluteValue
}

val mod: Int = 1_000_000_007


fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

fun <E> List<E>.toPair() = this[0] to this[1]

fun <T> readPair(t: (String) -> T) = readPair(t, t)
fun <S, T> readPair(s: (String) -> S, t: (String) -> T) =
    readLine()!!.split(" ").let { Pair(s(it[0]), t(it[1])) }

fun Int.pow(n: Int) = this.toDouble().pow(n).toInt()

fun minAndMax(a: Int, b: Int) = if (a < b) a to b else b to a

fun <T> T.ifOrThis(bool: (T) -> Boolean, trans: (T) -> T) = if (bool(this)) trans(this) else this
fun <T> T.ifOrThis(bool: Boolean, trans: (T) -> T) = if (bool) trans(this) else this

Measured memory_bytes: 36508
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int a, b;
int day[] = {0, 31, 28, 21, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>a>>b;
    int ans = 0;
    for(int i = 1;i <= a; i++){
        for(int j = 1;j <= day[i]; j++) {
            if(i == j){
                ans++;
            }
            if(i == a && j == b) break;
        }
    }


    cout<<ans<<endl;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; ++i) cin >> A[i];
    
    map<int,ll> mp,cself,celse,ans;
    ll sumelse = 0;

    //数別カウント
    for(int i = 0; i < N; ++i) mp[A[i]] = mp[A[i]] + 1;

    //組み合わせ
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        if(itr->second > 2) cself[itr->first] = (itr->second - 1)*(itr->second - 2)/2;
        if(itr->second > 1) celse[itr->first] = (itr->second)*(itr->second - 1)/2;
        sumelse += (itr->second)*(itr->second - 1)/2;
    }

    //ans = sumelse - celse + cself
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans[itr->first] = sumelse - celse[itr->first] + cself[itr->first];
    }

    for(int i = 0; i < N; ++i) cout << ans[A[i]] << endl;
}

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

int main(){
    #ifdef LOCAL_DEFINE
        freopen("./a.in","r",stdin);
        freopen("./a.out", "w",stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    float r;
    cin >> r;
    cout << 2*M_PI*r << endl;

    return 0;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    string s;
    cin >> s;
    vector<int> ans(s.length(),0);
    rep(i,s.length()-1){
        if(s[i] == 'R' && s[i+1] == 'L'){
            ans[i]++;ans[i+1]++;
        }
    }
    int l1 = 0,l2 = 0,r1 = 0,r2 = 0;
    int l = 0,r = 0;
    rep(i,s.length()){
        if(ans[i] == 0){
            if(s[i] == 'L'){
                if(l1 == 0) l = i-1;
                if(l1 == l2) l1++;
                else l2++;
            }else {
                if(r1 == 0) r = i-2;
                if(r1 == r2) r1++;
                else r2++;
            }
        }else {
            if(l1 != 0){
                ans[l-1] += l1;
                ans[l] += l2;
                l1 = 0;
                l2 = 0;
                l = 0;
            }
            if(r1 != 0){
                if(r1 > r2) {
                    ans[i+1] += r1;
                    ans[i] += r2;
                    r1 = 0;
                    r2 = 0;
                    r = 0;
                }else{
                    ans[i] += r1;
                    ans[i+1] += r2;
                    r1 = 0;
                    r2 = 0;
                    r = 0;
                } 
            }
        }
        if(i == s.length()-1) {
            if(l1 != 0){
                ans[l-1] += l1;
                ans[l] += l2;
                l1 = 0;
                l2 = 0;
                l = 0;
            }
        }
    }
    rep(i,s.length()){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1104
N = int(input())
H = list(int(i) for i in input().split())

ans = 0
left = 0
right = 0

while left < N:
  count = 0
  while right+1 < N:
    if H[right] >= H[right + 1]:
      count += 1
      right += 1
    else:
      right += 1
      break
  ans = max(ans,count)
  left = right + 1

print(ans)


Measured memory_bytes: 15020
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;

const int maxn = 4e5 + 5;
int pre[maxn],other[maxn],last[maxn];
LL cost[maxn];
LL pos[maxn];
int vis[maxn];
int all = -1;

void build(int x, int y, int w)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

bool dfs(int x)
{
	int dt = last[x];
	while(dt != -1)
	{
		int y = other[dt];
		if(vis[y] == 0 && vis[x] == 1)
		{
			vis[y] = 1;
			pos[y] = pos[x] + cost[dt];
			if(!dfs(y)) return false;
		}
		else if(vis[y] == 1 && vis[x] == 1)
		{
			if(pos[y] != pos[x] + cost[dt])
				return false;
		}
		dt = pre[dt];
	}
	return true;
}
int main()
{
	int n, m;
	memset(last,-1,sizeof(last));
	cin >> n >> m;
	for(int i = 1;i <= m;i++)
	{
		int l,r;
		LL d;
		cin >> l >> r >> d;
		build(l,r,d);
		build(r,l,-d);
	}
	for(int i = 1;i <= n;i++)
	{
		if(vis[i] == 0)
		{
			vis[i] = 1;
			if(!dfs(i))
			{
				pos[i] = 0;
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
    int n; double k;
    cin >> n >> k;
    vector<double> p(n);
    rep(i,n) cin >> p[i];
    vector<double> ev(n);
    rep(i,n) ev[i] = (p[i]+1) / 2;
    ev.push_back(0);
    double ans = 0.0;
    double now = 0.0;
    rep(i,k) now += ev[i];
    for (int i = 0; i+k <= n; ++i) {
        ans = max(ans,now);
        now -= ev[i];
        now += ev[i+k];
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 6400
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] p = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
        bool isLastSame = false;
        int same = 0;
        int samePair = 0;
        for (int i = 0; i < p.Length; i++)
        {
            if (isLastSame)
            {
                if (i == p[i])
                {
                    same--;
                    samePair++;
                }
                isLastSame = false;
            }
            else
            {
                if (i == p[i])
                {
                    same++;
                    isLastSame = true;
                }
            }
        }
        Console.WriteLine(same + samePair);
    }
}

Measured memory_bytes: 20064
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int M = 120000;
typedef long long ll;
ll n,a,b;
int main(){
    cin>>n>>a>>b;
    if(a+b==0){
        cout<<0<<endl;
        return 0;
    }
    ll c=n/(a+b);
    ll ex=n%(a+b);
    cout<<min(ex,a)+c*a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

#define ll long long

int main()
{
    ll N, K;
    scanf("%lld %lld", &N, &K);

    ll ans = 0;
    for (ll i = K; i <= N + 1; i++)
    {
        ll minS = i * (i - 1) / 2;
        ll maxS = i * (N + N - i + 1) / 2;
        ans += maxS - minS + 1;
    }

    printf("%lld", ans % 1000000007);
}


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

typedef long long ll;
ll H, W;

int main() {
    scanf("%lld %lld", &H, &W);
    ll ans = 1e18;
    for (ll i = 1; i < H; i++) {
        ll a = i * W;
        ll b = (H - i) / 2 * W;
        ll c = (H - i - (H - i) / 2) * W;
        if (i < H - 1) ans = min(ans, max({a, b, c}) - min({a, b, c}));
        b = (H - i) * (W / 2);
        c = (H - i) * (W - W / 2);
        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }
    swap(H, W);
    for (ll i = 1; i < H; i++) {
        ll a = i * W;
        ll b = (H - i) / 2 * W;
        ll c = (H - i - (H - i) / 2) * W;
        if (i < H - 1) ans = min(ans, max({a, b, c}) - min({a, b, c}));
        b = (H - i) * (W / 2);
        c = (H - i) * (W - W / 2);
        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
constexpr long INF = 1LL << 60;
constexpr int MOD = 1e9 + 7;

long N, M, L, A, B, C, Q, s, t;

void warshall_floyd(long n, vector<vector<long> > &g) {
  for(int k = 0; k < n; ++k)
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M >> L;
  vector<vector<long>> dist(N, vector<long>(N, INF));
  REP(i,M) {
    cin >> A >> B >> C;
    --A, --B;
    dist[A][B] = C;
    dist[B][A] = C;
  }
  REP(i,N) dist[i][i] = 0;
  warshall_floyd(N, dist);

  vector<vector<long>> repl(N, vector<long>(N, INF));
  REP(i,N) {
    REP(j,N) {
      if(dist[i][j] <= L) repl[i][j] = 1, repl[j][i] = 1;
    }
    repl[i][i] = 0;
  }
  warshall_floyd(N, repl);

  cin >> Q;
  REP(i, Q) {
    cin >> s >> t;
    --s, --t;
    if(repl[s][t] == INF) cout << -1 << '\n';
    else cout << repl[s][t]-1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
#define INF 10000
int **adj;//2D array of cost between each adj
int *cost;
int *status;
int n;//the number of vertices
void init(void);
void prim(void);
int sumCost(void);
int main(void)
{
  int i,j;//counter
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      scanf("%d",&adj[i][j]);
  prim();
  printf("%d\n",sumCost());
  return 0;
}
void init(void)
{
  int i;//counter
  adj=(int**)malloc(sizeof(int*)*n);
  cost=(int*)malloc(sizeof(int)*n);
  status=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) adj[i]=(int*)malloc(sizeof(int)*n);
}
void prim(void)
{
  int i;//counter
  int minCost;
  int current=0;
  int next;
  for(i=0;i<n;i++)
    {
      cost[i]=INF;
      status[i]=0;
    }
  cost[0]=0;
  status[0]=1;
  for(;;)
    {
      minCost=INF;
      for(i=0;i<n;i++)
        {
          if(status[i]==0)
            {
              if(current!=i&&adj[current][i]!=-1&&adj[current][i]<cost[i])
                {
                  //printf("%d <-> %d: cost=%d\n",current,i,adj[current][i]);
                  cost[i]=adj[current][i];
                }
              if(cost[i]!=-1&&cost[i]<minCost)
                {
                  minCost=cost[i];
                  next=i;
                }
            }
        }
      //printf("minCost=%d\n",minCost);
      if(minCost==INF) break;
      status[current]=1;
      current=next;
      //printf("next->%d\n",current);
    }
}
int sumCost(void)
{
  int i;//counter
  int sum=0;
  for(i=0;i<n;i++)
    {
      //printf("[%d] %d\n",i,cost[i]);
      sum+=cost[i];
    }
  return sum;
}


Measured memory_bytes: 2104
n = int(input())
s = 0
minb = float("inf")
for _ in range(n):
  a, b = map(int, input().split())
  if a > b:
    minb = min(b, minb)
  s += a
if minb == float("inf"):
  print(0)
else:
  print(s - minb)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define F(n) for (int i = 0; i < n; i++)
int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    F(dy) cout << 'U';
    F(dx) cout << 'R';
    F(dy) cout << 'D';
    F(dx) cout << 'L';
    cout << 'L';
    F(dy+1) cout << 'U';
    F(dx+1) cout << 'R';
    cout << "DR";
    F(dy+1) cout << 'D';
    F(dx+1) cout << 'L';
    cout << 'U' << endl;
}

Measured memory_bytes: 256
S = input()
ans = [0] * len(S)
cnt = 0
for i in range(len(S) - 1):
    if S[i] + S[i + 1] == "RL":
        ans[i] += cnt // 2 + 1
        ans[i + 1] += cnt - (cnt // 2) + 1
        cnt = 0
    elif S[i] == "R":
        cnt += 1
#print(ans)
for i in range(1, len(S)):
    if S[-i] + S[-(i + 1)] == "LR":
        ans[-i] += cnt // 2
        ans[-(i + 1)] += cnt - (cnt // 2)
        cnt = 0
    elif S[-i] == "L":
        cnt += 1
for _ans in ans:
    print(_ans, end = " ")

Measured memory_bytes: 81536
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) : 
    for j in range(S + 1) : 
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod 
        if j + A[i] <= S : 
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= mod
print(dp[N][S])

Measured memory_bytes: 147764
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
static const int Inf = 1 << 30;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<set<int>> clist(26, set<int>({Inf}));
    for (int i = 0; i < N; ++i)
    {
        clist[S[i] - 'a'].insert(i); // アルファベットがが何番目に現れるかを記録
    }

    for (int q = 0; q < Q; ++q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int ind;
            char c;
            cin >> ind >> c;
            --ind;
            char temp = S[ind];
            S[ind] = c;
            clist[temp - 'a'].erase(ind);
            clist[c - 'a'].insert(ind);
        }
        else
        {
            int left, right;
            cin >> left >> right;
            --left;
            int num = 0;
            for (int i = 0; i < 26; ++i)
            {
                if (clist.empty()) continue;
                int lid = *clist[i].lower_bound(left);
                int rid = *clist[i].lower_bound(right);
                if (lid < rid) ++num;
            }
            cout << num << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 24196
#include <cstdio>
#include <algorithm>

using namespace std;

int h, w, x, y;
char s[100][101];
int sum[101][101];
int p[100][100];
int dp[5050][5050];

int get(int x1, int y1, int x2, int y2) {
    return sum[x2 + 1][y2 + 1] - sum[x1][y2 + 1] - sum[x2 + 1][y1] + sum[x1][y1];
}

int dfs(int x1, int y1, int x2, int y2) {
    int ans = 0;
    
    if (x1 > x2 || y1 > y2) return 0;
    
    if (dp[p[x1][x2]][p[y1][y2]] >= 0) return dp[p[x1][x2]][p[y1][y2]];
    
    if (x + x2 - x1 < h && x - x2 + x1 >= 0 && y + y2 - y1 < w && y - y2 + y1 >= 0) return dp[p[x1][x2]][p[y1][y2]] = get(x1, y1, x2, y2);
    
    if (x + x2 - x1 < h) {
        int yl, yr;
        
        yl = max(y1, y2 - w + y + 1);
        yr = min(y2, y1 + y);
        
        ans = max(ans, dfs(x1 + 1, y1, x2, y2) + get(x1, yl, x1, yr));
    } else {
        ans = max(ans, dfs(x1 + 1, y1, x2, y2));
    }
    
    if (x - x2 + x1 >= 0) {
        int yl, yr;
        
        yl = max(y1, y2 - w + y + 1);
        yr = min(y2, y1 + y);
        
        ans = max(ans, dfs(x1, y1, x2 - 1, y2) + get(x2, yl, x2, yr));
    } else {
        ans = max(ans, dfs(x1, y1, x2 - 1, y2));
    }
    
    if (y + y2 - y1 < w) {
        int xl, xr;
        
        xl = max(x1, x2 - h + x + 1);
        xr = min(x2, x1 + x);
        
        ans = max(ans, dfs(x1, y1 + 1, x2, y2) + get(xl, y1, xr, y1));
    } else {
        ans = max(ans, dfs(x1, y1 + 1, x2, y2));
    }
    
    if (y - y2 + y1 >= 0) {
        int xl, xr;
        
        xl = max(x1, x2 - h + x + 1);
        xr = min(x2, x1 + x);
        
        ans = max(ans, dfs(x1, y1, x2, y2 - 1) + get(xl, y2, xr, y2));
    } else {
        ans = max(ans, dfs(x1, y1, x2, y2 - 1));
    }
    
    return dp[p[x1][x2]][p[y1][y2]] = ans;
}

int main() {
    int c = 0, i, j;
    
    scanf("%d %d", &h, &w);
    
    for (i = 0; i < h; i++) scanf("%s", s[i]);
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
            if (s[i][j] == 'o') sum[i + 1][j + 1]++;
            
            if (s[i][j] == 'E') {
                x = i;
                y = j;
            }
        }
    }
    
    for (i = 0; i < 100; i++) {
        for (j = i; j < 100; j++) {
            p[i][j] = c++;
        }
    }
    
    for (i = 0; i < c; i++) {
        for (j = 0; j < c; j++) {
            dp[i][j] = -1;
        }
    }
    
    printf("%d\n", dfs(0, 0, h - 1, w - 1));
    
    return 0;
}


Measured memory_bytes: 99968
#include<stdio.h>
#include<string.h>
#define Max(x,y)((x>y)?x:y)
char m[22][22];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
typedef struct p{
	int x,y;
}P;
P q[405],sq[405];
int main(){
	int i,j,w,h,qn,sqn,ans,nx,ny;
	char s[22];
	while(1){
		scanf("%d%d",&w,&h);
		if(w==0)break;
		memset(m,0,sizeof(m));
		for(i=0;i<=w+1;i++)m[0][i]=m[h+1][i]='#';
		for(i=1;i<=h;i++){
			scanf("%s",s);
			strcpy(m[i]+1,s);
			m[i][0]=m[i][w+1]='#';
			for(j=1;j<=w;j++)if(m[i][j]=='@')q[0].x=j,q[0].y=i,m[i][j]='#';
		}
		ans=1;qn=1;
		while(qn!=0){
			sqn=0;
			for(i=0;i<qn;i++){
				for(j=0;j<4;j++){
					nx=q[i].x+dx[j];
					ny=q[i].y+dy[j];
					if(m[ny][nx]=='.'){
						sq[sqn].x=nx;
						sq[sqn].y=ny;
						ans++;sqn++;
						m[ny][nx]='#';
					}
				}
			}
			memcpy(q,sq,sizeof(P)*sqn);
			qn=sqn;
		}
		//for(i=0;i<=h+1;i++)printf("%s\n",m[i]);
		printf("%d\n",ans);
	}
	return 0;
}

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

int main()
{
    long long r, D, x[2100];
    cin >> r >> D >> x[2000];
    for (int i = 2000; i < 2015; i++)
    {
        x[i + 1] = r * x[i] - D;
    }
    for(int i=2001; i<=2010; i++){
        cout<<x[i]<<endl;
    }

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  vl A;
  string s;
  cin >> s;
  if (s[0] == s[1] && s[0] == s[2] && s[1] == s[2])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
m = int(input())
cost = []
for i in range(n):
    t = [float('inf')]*n
    t[i] = 0
    cost.append(t)
for i in range(m):
    s = input()
    s += ','
    L = []
    z = ''
    for j in range(len(s)):
        if s[j] != ',':
            z += s[j]
        else:
            L.append(int(z))
            z = ''
    a,b,c,d = L[0],L[1],L[2],L[3]
    cost[a-1][b-1] = c
    cost[b-1][a-1] = d
for k in range(n):
    for i in range(n):
        for j in range(n):
            if cost[i][j] > cost[i][k]+cost[k][j]:
                cost[i][j] = cost[i][k]+cost[k][j]
s = input()
s += ','
L = []
z = ''
for j in range(len(s)):
    if s[j] != ',':
        z += s[j]
    else:
        L.append(int(z))
        z = ''
s,g,v,p = L[0],L[1],L[2],L[3]
print(v-p-cost[s-1][g-1]-cost[g-1][s-1])


Measured memory_bytes: 5620
S=str(input())
M=len(S)
list=[]
i=0
for i in range(M-2):
  list.append(S[i:i+3])
  i+=1
N=len(list)
new_list=[]
j=0
for j in range(N):
  new_list.append(abs(int(list[j])-753))
print(min(new_list))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  int ans;
  cin >> A >> B;

  if(B == 1){
      cout << "0" << endl;
      return 0;
  }
  
  ans = ((B-A) + (A-2))/(A-1) + 1;
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
using namespace std;
int n,a[200005];
long long ans;
int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		cin>>a[i];
		if (i==1 && a[i]) return (int)puts("-1")*0;
		else if (a[i]==a[i-1]+1) ans++;
		else if (a[i]<a[i-1]+1) ans+=a[i];
		else if (a[i]>a[i-1]+1) return (int)puts("-1")*0;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	run()
}

type pair struct {
	a byte
	b byte
}

func f(x int) pair {
	xs := strconv.Itoa(x)
	a, b := xs[0], xs[len(xs)-1]
	return pair{a: a, b: b}
}

func run() {
	setSpace()
	n := readN()
	freq := map[pair]int{}
	for i := 1; i <= n; i++ {
		n, ok := freq[f(i)]
		if !ok {
			n = 0
		}
		n++
		freq[f(i)] = n
	}
	ans := 0
	for i := 1; i <= n; i++ {
		p := f(i)
		q := pair{a: p.b, b: p.a}
		ans += freq[q]
	}
	fmt.Println(ans)
}

// ------以下、ユーティリティ------

var sc = bufio.NewScanner(os.Stdin)

func setSpace() {
	sc.Split(bufio.ScanWords)
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readN() int {
	n, err := strconv.Atoi(read())
	if err != nil {
		panic(err)
	}
	return n
}


Measured memory_bytes: 4736
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


/*
dp[i][j][k] = { j = 0 ならば，先頭からi桁がK未満で，あまりがjとなる数の総数
            　　 j = 1 ならば，先頭からi桁がKと等しくで，あまりがjとなる数の総数 
              }
dp[0][1][0] = 1 //未満ではない，K[-1] = 0と考える．
dp[i+1][0][k] = for l = 0..10 { dp[i][0][ (k-l) mod D] } + for l = 0..K[i] { dp[i][1][(k - l) mod D] }
dp[i+1][1][k] = dp[i][1][(k - K[i]) mod D]
*/
const MOD: usize = 1_000_000_000 + 7;
fn main() {
    let K: Vec<usize> = read::<String>().chars().map(|e| e as usize - '0' as usize).collect();
    let D: usize = read();
    let n = K.len();
    let mut dp = vec![vec![vec![0; D]; 2]; n+1];
    
    // 
    dp[0][1][0] = 1;

    for i in 0..n {   
        for k in 0..D {
            for l in 0..10 {
                // 未満の場合の更新式
                dp[i+1][0][(k + l) % D] += dp[i][0][k];
                dp[i+1][0][(k + l) % D] %= MOD;

                if l < K[i] {
                    dp[i+1][0][(k + l) % D] += dp[i][1][k];
                    dp[i+1][0][k] %= MOD;
                }
            }
            // 一致している場合の更新式
            dp[i+1][1][(k + K[i]) % D] += dp[i][1][k];
            dp[i+1][1][(k + K[i]) % D] %= MOD;
        }
    }

    // for i in 0..n+1 {
    //     println!("{:?}", dp[i][0]);
    //     println!("{:?}", dp[i][1]);
    // }

    let ans: usize = (dp[n][0][0] % MOD + dp[n][1][0] % MOD + MOD - 1) % MOD;
    println!("{}", ans); // 0000...0000の場合を除く
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    vector<int> c(n);
    for (int i = 0; i < n; i++) c[i] = a[i] - b[i];
    sort(c.begin(), c.end());
    int cnt = 0;
    long long negative_sum = 0;
    for (int i = 0; i < n; i++){
        if (c[i] < 0) cnt++, negative_sum += abs(c[i]);
    }
    int now = n - 1;
    while (negative_sum > 0){
        if (c[now] <= 0) break;
        negative_sum -= c[now];
        cnt++; now--;
        if (now < 0) break;
    }
    if (negative_sum <= 0) cout << cnt << endl;
    else cout << - 1 << endl;
}

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

bool keysort(pair<int,pair<int,int>> &a,pair<int,pair<int,int>> &b){
    if(a.first!=b.first){
        return a.first<b.first;
    }
    else return a.second.first<b.second.first;
}

bool keysort2(pair<int,pair<int,int>> &a,pair<int,pair<int,int>> &b){
    return a.second.second<b.second.second;
}

int main(){

  int N,K;
    cin>>N>>K;
    vector<pair<int,pair<int,int>>> S(K);
    
    for(int i=0;i<K;i++){
        cin>>S[i].first>>S[i].second.first;
        S[i].second.second=i+1;
    }

    sort(S.begin(),S.end(),keysort);
    
    for(int i=0;i<K;i++){
        if(i==0) S[i].second.first=1;
        else if(S[i].first==S[i-1].first) S[i].second.first=S[i-1].second.first+1;
        else S[i].second.first=1;
    }
    sort(S.begin(),S.end(),keysort2);
    
    for(int i=0;i<K;i++){
        printf("%06d%06d\n",S[i].first,S[i].second.first);
    }
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        long K=sc.nextLong();
        long arr[]=new long[N+1];
        long brr[]=new long[M+1];
        for(int i=0;i<N;++i) {
            int ele=sc.nextInt();
            arr[i+1]=arr[i]+ele;
        }
        for(int i=0;i<M;++i) {
            int eleb=sc.nextInt();
            brr[i+1]=brr[i]+eleb;
        }
        int count=0;
//        int i=0,j=0;
//        while(i<arr.length&&j<brr.length) {
//            if(arr[i]+brr[j]<=K) {
//                count=Math.max(count,i+j);
//            }
//            if(arr[i]<=brr[j]) {
//                i++;
//            } else
//                j++;
//        }
//        while(i<arr.length) {
//
//        }
        int j=M;
        int  max=0;
        for(int i=0;i<arr.length;++i) {
            if(arr[i]>K)
                break;
            while(j>0&&brr[j]>K-arr[i]) {
                j--;
            }
            max=Math.max(i+j,max);

        }
        System.out.println(max);

    }
}

Measured memory_bytes: 62844
#include<stdio.h>
void main()
{
    int arr[5],i,ans;
    for(i=0;i<5;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<5;i++)
    {
        if(arr[i]==0)
        {
            ans=i+1;
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 1680
/* B */

#include <iostream>
using namespace std;

int main(){
	int r, g, b, n;

	cin >> r >> g >> b >> n;
	int cnt = 0;
	for(int i = 0; i <= n/r; i++){
		int R = r*i;
		for (int j = 0; j <= (n-R)/g; j++){
			int G = g*j;
			if((n-R-G) % b == 0) cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int h,w;cin>>h>>w;
    char hw[55][55];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>hw[i][j];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++){
            
            if(hw[i][j]=='#'){
                int abc=0;
                for(int z=0;z<4;z++){
                    int nx=i;int ny=j;
                    nx+=dx[z];
                    ny+=dy[z];
                    if(nx<h&&nx>=0&&ny<w&&ny>=0){
                        if(hw[nx][ny]=='#'){
                        abc=1;
                        }
                    }
                }
                if(abc==0){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    cout<<"Yes"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
while (num = gets.to_i) != 0
  result = []
  num.times do
    tmp_ary = gets.split.map(&:to_i)
    result << tmp_ary.slice!(0)
    minutes = 0
    seconds = 0
    tmp_ary.each_with_index do |value, index|
        minutes += value if index.even?
        seconds += value if index.odd?
    end
    result << minutes * 60 + seconds
  end
  team_hash = Hash[Hash[*result].sort_by {|k, v| v}]
  team_ary = team_hash.keys
  puts team_ary[0], team_ary[1], team_ary[team_ary.size - 2]
end

Measured memory_bytes: 9960
#include <stdio.h>

int main(void)
{
	int n,m;
	int i,x,y;
	int array[51]={};
	
	scanf("%d%d",&n,&m);
	
	for(i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		array[x]++;
		array[y]++;
	}
	
	for(i=0;i<n;i++){
		printf("%d\n",array[i+1]);
	}
	return 0;
}

Measured memory_bytes: 128
#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>;
using Graph = vector<vector<int>>;

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

int main(){
    int h, w, kuro=0;
    cin >> h >> w;
    int s[h][w];
    int dist[h][w];
    rep(i,h){
        rep(j,w){
            char x;
            cin >> x;
            if(x=='#'){
                s[i][j]=1;
                ++kuro;
            }else if(x=='.'){
                s[i][j]=2;
            }
            dist[i][j]=-1;
        }
    }
    queue<pair<int,int>> que;
    dist[0][0]=1;
    que.push({0,0});
    while(!que.empty()) {
        int u=que.front().first, v=que.front().second;
        que.pop();
        rep(i,4) {
            if(u+dy[i]<0 || v+dx[i]<0 || u+dy[i]>=h || v+dx[i]>=w) continue;
            if(dist[u+dy[i]][v+dx[i]]==-1 && s[u+dy[i]][v+dx[i]]==2) {
                dist[u+dy[i]][v+dx[i]] = dist[u][v] + 1;
                que.push({u+dy[i],v+dx[i]});
            }
        }
    }
    if(dist[h-1][w-1]==-1){
        cout << -1 << "\n";
        return 0;
    }
    cout << h*w-dist[h-1][w-1]-kuro << "\n";
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a int
	count := 0
	result := 1
	fmt.Scan(&a)

	for i := 1; i <= a; i++ {
		countInternal := 0
		numberStore := i
		for numberStore%2 == 0 {
			countInternal++
			numberStore /= 2
		}
		if countInternal > count {
			count = countInternal
			result = i
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;

#define MAX_N 100000+10
#define MAX_E 4*(100000+10)
int par[MAX_N];
int union_rank[MAX_N];

void init_union_find(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    union_rank[i] = 0;
  }
}

int find_union_find(int x){
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find_union_find(par[x]);
  }
}

void unite_union_find(int x, int y) {
  x = find_union_find(x);
  y = find_union_find(y);
  if ( x == y) return;

  if (union_rank[x] < union_rank[y] ) {
    par[x] = y;
  } else {
    par[y] = x;
    if (union_rank[x] == union_rank[y]) {
      union_rank[x]++;
    }
  }

}

bool same_union_find(int x, int y) {
  return find_union_find(x) == find_union_find(y);
}

struct edge{int u,v, cost;};

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}


edge es[MAX_E];
int V,E;

int kruskal() {
  sort(es, es+E, comp);
  init_union_find(V);
  int res=0;
  for(int i=0;i<E;++i) {
    edge e =es[i];
    if(!same_union_find(e.u,e.v)){
      unite_union_find(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}


typedef pair<int,int> city_data;

city_data x[MAX_N];
city_data y[MAX_N];

int main() {
  int N;
  scanf("%d", &N);
  for(int i=0;i<N;++i){
    scanf("%d%d", &x[i].first, &y[i].first);
    x[i].second = i;
    y[i].second = i;
  }

  V=N;

  sort(x, x+N);
  sort(y, y+N);

  int it=0;
  for(int i=0;i<N-1;++i){
    {
      int cost=abs(x[i].first - x[i+1].first);
      es[it].u=x[i].second;
      es[it].v=x[i+1].second;
      es[it].cost=cost;
      it++;
    }
    {
      int cost=abs(y[i].first - y[i+1].first);
      es[it].u=y[i].second;
      es[it].v=y[i+1].second;
      es[it].cost=cost;
      it++;
    }
  }
  E=it;


  printf("%d",kruskal());
 
  
  return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
inline int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int n,m,s[1000][1000],len[maxn];
int main(){
	n=read();m=2*n;int k=1;
	for(;k*(k-1)<m;k++);
	if(k*(k-1)==m){
		printf("Yes\n");int tmp=0;
		for(int i=1;i<=k;i++)
			for(int j=i+1;j<=k;j++)tmp++,s[i][++len[i]]=tmp,s[j][++len[j]]=tmp;
		printf("%d\n",k);
		for(int i=1;i<=k;i++){
			printf("%d ",len[i]);
			for(int j=1;j<=len[i];j++){
				printf("%d",s[i][j]);
				if(j==len[i])printf("\n");else printf(" ");
			}
		}
	}else printf("No\n");
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    int n, m, x;
    cin>>n>>m>>x;
    int book[n][m+1];
    loop(n){
        for(int j = 0; j<=m; j++) cin>>book[i][j];
    }

    int total = 1<<n;
    ll cost = INT64_MAX;
    for(int mask = 1; mask<total; mask++){
        ll temp = 0;
        vector<ll> skill(m);

        for(int p = 0; p<n; p++){
            int f = 1<<p;
            if((f&mask) != 0){
                temp += book[p][0];
                for(int i = 0; i<m; i++) skill[i] += book[p][i+1];
            }
        }

        bool ok = 1;
        for(int y : skill){
            if(y<x){
                ok = 0;
                break;
            }
        }
        if(ok) cost = min(cost, temp);
    }

    if(cost==INT64_MAX) return cout<<"-1", 0;
    cout<<cost;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=8e2;
int us[M][M],cnt;
int main(){
    ios::sync_with_stdio(false);
    int n;cin>>n;
    if(n==1)printf("Yes\n2\n1 1\n1 1\n"),exit(0);
    if(n==2)printf("No\n"),exit(0);
    for(int i=1;i*(i-1)/2<=n;++i){
        if(i*(i-1)/2==n){
            printf("Yes\n%d\n",i);
            for(int j=1;j<=i;++j){
                for(int k=1;k<j;++k){
                    us[j][k]=us[k][j-1];
                }for(int k=j;k<i;++k)us[j][k]=++cnt;
            }
            for(int j=1;j<=i;++j){
                printf("%d ",i-1);
                for(int k=1;k<i;++k)printf("%d ",us[j][k]);
                printf("\n");
            }exit(0);
        }
    }printf("No\n");return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        
        int ans=-1,cnt=0;
        
        vector<vector<int>> A(N);
        
        for(int i=0;i<N;i++){
            int M;cin>>M;
            A[i].assign(M,0);
            for(int j=0;j<M;j++){
                cin>>A[i][j];
            }
            sort(all(A[i]));
        }
        int K;cin>>K;
        vector<int> B(K);
        for(int i=0;i<K;i++) cin>>B[i];
        
        sort(all(B));
        
        for(int i=0;i<N;i++){
            bool ok=true;
            for(int j=0;j<K;j++){
                if(!binary_search(all(A[i]),B[j])) ok=false;
            }
            if(ok){
                ans=i+1;
                cnt++;
            }
        }
        
        if(cnt>=2) ans=-1;
        
        cout<<ans<<endl;
        
    }
    
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S; cin>>S;
    bool can1= false,can2= false;
    if(S[0]=='0'||(S[0]=='1'&&(S[1]=='2'||S[1]=='1'||S[1]=='0'))){
        can1=true;
        if(S[0]=='0'&&S[1]=='0'){
            can1=false;
        }
    }
    if(S[2]=='0'||(S[2]=='1'&&(S[3]=='2'||S[3]=='1'||S[3]=='0'))){
        can2=true;
        if(S[2]=='0'&&S[3]=='0'){
            can2=false;
        }
    }


    if(can1&&can2){
        cout<<"AMBIGUOUS";
    }
    else if(!can1&&!can2){
        cout<<"NA";
    }
    else if(can1&&!can2){
        cout<<"MMYY";
    }
    else if(!can1&&can2){
        cout<<"YYMM";
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

s = input()

ans = 0
tmp = 0
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0

print(ans)


Measured memory_bytes: 8968
#include <iostream>
using namespace std;
int main(void) {
  while(true){
    int x,y;
    cin >> x >> y;

    //end
    if(x == 0){
      if(y == 0){
        break;
      }
    }
    if (x > y){
      int temp = x;
      x = y;
      y = temp;
    }
    cout << x << " " << y << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
results = []
while True:
    n, x = map(int, input().split())
    count = 0
    if n == x == 0:
        break
    else:
        for i in range(1, n + 1):
            for j in range(i + 1, n + 1):
                for k in range(j + 1, n + 1):
                    count += 1 if i + j + k == x else 0
    results.append(count)

for result in results:
    print(result)



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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

void solve(){
	//code
	int x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;
	if(x1==0) cout<<1;
	else if (x2==0) cout<<2;
	else if (x3==0) cout<<3;
	else if (x4==0) cout<<4;
	else if (x5==0) cout<<5;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
 	return 0;
}


Measured memory_bytes: 3632
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	long n = rlong;
	
	long ans = n * (n - 1) / 2;
	ans.writeln;
}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        string str; getline(cin, str);
        _foreach(e, str) { if(isalpha(e)) { e = (isupper(e) ? tolower(e) : toupper(e)); } }
        cout << str << endl;
    }
    return 0;
}


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

int cnt[4];
int main(){
	rep(i,3){
		int a,b;cin>>a>>b;a--;b--;
		cnt[a]++;cnt[b]++;
	}
	int a=0,b=0;
	rep(i,4){
		if(cnt[i]==1)a++;
		if(cnt[i]==2)b++;
	}
	if(a==2&&b==2){
		puts("YES");
	}
	else puts("NO");
}

Measured memory_bytes: 256
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

data class Query(val v: Int, val d: Int, val c: Int)

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val graph = Array(n, { mutableListOf<Int>() })
  repeat(m) {
    val (rawV1, rawV2) = fastReadInts(2)
    val v1 = rawV1 - 1
    val v2 = rawV2 - 1
    graph[v1].add(v2)
    graph[v2].add(v1)
  }
  val q = readLine()!!.toInt()
  val queries = Array(q, {
    val (vRaw, d, c) = fastReadInts(3)
    val v = vRaw - 1
    Query(v, d, c)
  })
  queries.reverse()

  val dp = Array(n, { IntArray(11) })

  fun dfs(v: Int, d: Int, c: Int) {
    if (dp[v][d] > 0) return
    for (k in d downTo 0) {
      if (dp[v][k] > 0) break
      dp[v][k] = c
    }

    if (d == 0) return

    for (u in graph[v]) {
      dfs(u, d - 1, c)
    }
  }

  for (query in queries) {
    dfs(query.v, query.d, query.c)
  }

  for (v in 0 until n) {
    println(dp[v][0])
  }
}


Measured memory_bytes: 86100