akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int N,D;
vector<vector<int>> v(10010);
int vis[10010] = {};

bool dfs(int n){
    vis[n] = -1;
    bool ok = true;
    for(auto x:v[n]){
        if(vis[x]==0) ok &= dfs(x);
        else if(vis[x]==-1) return false;
    }
    vis[n] = 1;
    return ok;
}

int main(){
    while(cin >> N >> D && N){
        vector<int> M(N);
        vector<vector<int>> C(N);
        for(int i=0;i<=10000;i++){
            v[i].clear();
            vis[i] = 0;
        }
        int id = 0;
        map<pair<int,int>,int> m;
        for(int i=0;i<N;i++){
            cin >> M[i];
            C[i].push_back(0);
            int c;
            m[{i,0}] = id;
            id++;
            for(int j=1;j<=M[i];j++){
                cin >> c;
                C[i].push_back(c+C[i].back());
                m[{i,j}] = id;
                id++;
            }
        }
        for(int a=0;a<N;a++) for(int b=0;b<N;b++){
            if(a==b) continue;
            for(int i=C[a].size()-1;i>=0;i--) for(int j=0;j<C[b].size();j++){
                if(C[a][i]+D<C[b][j]){
                    v[m[{b,j}]].push_back(m[{a,i+1}]);
                    break;
                }
            }
        }
/*        for(int i=0;i<N;i++){
            for(int j=0;j<C[i].size();j++) cerr << C[i][j] << " ";
            cerr << endl;
        }
        for(int i=0;i<id;i++){
            cerr << i << "  ";
            for(auto x:v[i]) cerr << x << " ";
            cerr << endl;
        }
*/        for(int a=0;a<N;a++) for(int i=0;i<C[a].size()-1;i++) v[m[{a,i+1}]].push_back(m[{a,i}]);
        bool yes = true;
        for(int a=0;a<N;a++) if(!vis[m[{a,C[a].size()-1}]]) yes &= dfs(m[{a,C[a].size()-1}]);
        cout << (yes? "Yes":"No") << endl;
    }
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
int main() {
  int n, m, r;
  cin >> n >> m >> r;
  ll g[n+1][n+1];
  //memset(g, INF, sizeof(g));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      g[i][j] = INF;
  for(int i=0;i<n;i++)
    g[i][i] = 0;
  vector<int> rs(r);
  for(int i=0;i<r;i++) {
    cin >> rs[i];
    rs[i]--;
  }
  sort(rs.begin(), rs.end());
  for(int i=0;i<m;i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a][b] = c;
    g[b][a] = c;
  }

  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<ll>(g[i][j], g[i][k]+g[k][j]);
      }
    }
  }

  ll ans = INF;

  do {
    ll res = 0;
    for(int i=0;i<rs.size()-1;i++) {
      res += g[rs[i]][rs[i+1]];
    }
    ans = min<ll>(ans, res);
  } while(next_permutation(rs.begin(), rs.end()));

  cout << ans << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int gcd(int x , int y , int z){
    int m = min({x , y , z});
    int ans = 0;
    for(int i = 1; i <= m; i++){
        if(x % i == 0 && y % i == 0 && z % i == 0){
            ans = i;
        }
    }
    return ans;
}
int main() {
    int K;
    cin >> K;
    int gcd_total = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int l = 1; l <= K; l++){
                gcd_total += gcd(i , j , l);
            }
        }
    }
    cout << gcd_total << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
#define double long double
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

string s;

signed main() {
	fastio;
	cin >> s;
	if (s[sz(s) - 1] == 's') s += "es";
	else s += "s";
	cout << s;
}

Measured memory_bytes: 3660
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var s = input[1].split('');

    var ww = 0;
    var we = 0;
    var ew = 0;
    var ee = 0;
    var rightCharCount = {};
    var leftCharCount = {};

    for (var i = 0; i < n; i++) {

        if (s[i] === 'W') {
            ew++;
        }
        else {
            ee++;
        }
    }

    var change = 0;
    var ans = Number.MAX_SAFE_INTEGER;

    for (var i = 0; i < n; i++) {

        if (s[i] === 'W') {
            ew--;
        }
        else {
            ee--;
        }

        change = ww + ee;
        ans = Math.min(ans, change);

        if (s[i] === 'W') {
            ww++;
        }
        else {
            we++;
        }
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define ff(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b) 
int main(){
    //FL;
    fin;
    ll a, b;
    cin >> a >> b;
    ll aux = a + b;
    aux = aux / 2;
    if(abs(a - aux) == abs(b - aux))
        cout << aux << '\n';
    else cout << "IMPOSSIBLE\n";
    time;
    return 0;
}   

Measured memory_bytes: 256
n = int(input())
l = list(input())
ans = 0
for i in range(n):
  l1 = l[i+1:]
  
  count = set()
  for j in range(i+1):
    if l[j] in l1:
      count.add(l[j])
  ans = max(ans,len(count))
  
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n; cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    
    ll ansp=0, ansn=0;
    vi b = a;
    //a[0]を正にする
    rep(i,n){
        
        if(i!=0) b[i] += b[i-1];
        
        if(i%2==0){
            ansp += max(0, 1-b[i]);
            b[i]  = max(1, b[i]);
        }else{
            ansp += max(0, b[i]+1);
            b[i]  = min(-1, b[i]);
        }
    }
    
    rep(i,n){
        
        if(i!=0) a[i] += a[i-1];
        
        if(i%2!=0){
            ansn += max(0, 1-a[i]);
            a[i]  = max(1, a[i]);
        }else{
            ansn += max(0, a[i]+1);
            a[i]  = min(-1, a[i]);
        }
    }
    
    cout << min(ansp, ansn) << endl;
    
    
    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int a[n],count = 0;
    for(int i = 0;i < n;i++)cin >> a[i];
    reverse(a,a+n);
    for(int i = 0;i < n;i++){
        int b = 0,c = 0;
        for(int j = i+1;j < n;j++){
            if(a[j-1] >= a[j])b++;
            else break;
        }
        for(int j = i+1;j < n;j++){
            if(a[j-1] <= a[j])c++;
            else break;
        }
        i += max(b,c);
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int H, W;
    
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                if( (i+j) % 2 ==0){
                    cout << "#";
                }
                else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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

  vector<vector<char>> a(h, vector<char>(w));

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a.at(i).at(j);
    }
  }

  vector<bool> vh(h, false);
  vector<int> vw(w, false);

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a.at(i).at(j) == '#') {
        vh.at(i) = true;
      }
    }
  }

  for (int j = 0; j < w; ++j) {
    for (int i = 0; i < h; ++i) {
      if (a.at(i).at(j) == '#') {
        vw.at(j) = true;
      }
    }
  }

  for (int i = 0; i < h; ++i) {
    bool flag = false;
    for (int j = 0; j < w; ++j) {
      if (vh.at(i) && vw.at(j)) {
        cout << a.at(i).at(j);
        flag = true;
      }
    }
    if (flag) {
      cout << endl;
    }
  }
}


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

int main(){
    int x,y;
    cin >> x>>y;
    vector<int> a(206);

    a.at(1)=300000;
    a.at(2)=200000;
    a.at(3)=100000;

    if((x==1)&&(y==1)){
        cout << 1000000 <<endl;
    }
    else{
        cout << a.at(x) + a.at(y) << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  int N, A, B;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  } else {
    cin >> A >> B;
    cout << (A + B) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int i,j,a[60],b[60],n,flag;

    scanf("%d",&n);

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

    for(i=0,j=1;i<n;i++,j++)
    {
        b[i] = j;
    }

    for(i=0,flag=0;i<n;i++)
    {
        if(a[i]!=b[i])
            flag++;
    }

    if(flag<=2)
        printf("YES");
    else
        printf("NO");

    return 0;
}

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

int main() {

	ll h, w;
	cin >> h >> w;

	if(h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}

	ll goodrow = (w % 2 == 0 ? (w/2) : ((w-1)/2)+1);
	ll badrow = w-goodrow;

	if(h%2 == 0) cout << goodrow*(h/2)+badrow*(h/2) << endl;
	else {
		ll ngoodrows = ((h-1)/2)+1;
		cout << goodrow*ngoodrows+badrow*(h-ngoodrows) << endl;	
	}

	return 0;
}


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

int aa[1010][1010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    int m=1;
    vector<int> a;
    while((m*(m+1))/2<=100000){
        a.push_back((m*(m+1))/2);
        m++;
    }
    bool f=false;
    int p;
    for(int i=0;i<a.size();i++){
        if(a[i]==n){
            f=true;
            p=i+1;
        }
    }
    int l=p+1;
    if(!f){
        cout<<"No"<<endl;
        return 0;
    }
    else{
        cout<<"Yes"<<endl<<p+1<<endl;
        for(int i=0;i<p;i++)aa[0][i]=i+1;
        for(int i=1;i<=p;i++){
            for(int j=0;j<i;j++)aa[i][j]=aa[j][i-1];
            for(int j=i;j<p;j++)aa[i][j]=l++;
        }
    }
    for(int i=0;i<=p;i++){
        cout<<p<<" ";
        for(int j=0;j<p;j++){
            cout<<aa[i][j]<<" ";
        }
        cout<<endl;
    }

}

Measured memory_bytes: 3200
H, W = map(int, input().split())
S = [input() for _ in range(H)]
T = ["" for _ in range(H)]
for h in range(H):
    for w in range(W):        
        T[h] += str(sum(S[i][j]=="#" for i in range(max(0,h-1),min(H,h+2)) for j in range(max(0,w-1),min(W,w+2)))) if S[h][w] == "." else "#"
print(*T, sep="\n")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    // 問題:
    class A_165_We_Love_Golf
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            // 整数配列の入力
            var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int a = inputintArray[0];
            int b = inputintArray[1];

            for (int i = 0; i < b - a + 1; i++)
            {
                if((a + i) % n == 0)
                {
                    Console.WriteLine("OK");
                    break;
                }
                else if((a + i) % n != 0 && i == b - a)
                {
                    Console.WriteLine("NG");
                }
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28212
import java.util.*;
import java.lang.Math;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int x[] = new int [n];
    int y[] = new int [n];
    double dis=0;
    for(int i=0; i<n; i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        if(i!=j){
          int sx = x[i] - x[j];
          int sy = y[i] - y[j];
          dis+=Math.sqrt(sx*sx+sy*sy);
        }
      }
    }
    System.out.println(dis/n);
  }
}


Measured memory_bytes: 23636
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,A,B = map(int,input().split())
V = list(map(int,input().split()))

# 価値の降順にソート
V.sort(reverse=True)

# 価値の高い方から A 個 選んだ場合が平均価値最大
sumV = 0
for i in range(A):
    sumV += V[i]
ans1 = sumV/A


# 価値最大の個数
cntV0 = 0
for i in range(N):
    if V[i]==V[0]:
        cntV0 += 1
ans2 = 1
# 価値最大の個数が A より大きいなら
if cntV0 > A:
    ans2 = 0
    for i in range(A,min(cntV0,B)+1):
        tmp = 1
        c = cntV0
        r = i
        # cntV0 より j個 選ぶ選び方
        for j in range(r):
            tmp *= c-j
            tmp //= j+1
        ans2 += tmp
else:
    cntV1,cntV2 = 0,0
    # A 番目の価値と同じ個数, それより価値が大きな個数を数える
    for i in range(N):
        if V[i]==V[A-1]:
            cntV1 += 1
        elif V[i]>V[A-1]:
            cntV2 += 1
    # 合わせて A より大きければ, 複数の組み合わせがありうる
    if cntV1+cntV2 > A:
        c = cntV1
        r = A-cntV2
        # A 番目の価値と同じものを, 適切な数選ぶ場合の数を計算する
        for i in range(r):
            ans2 *= c-i
            ans2 //= i+1


print(ans1, ans2)


Measured memory_bytes: 3064
N = int(input())

lst = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]
if N in lst:
  thousands = int(N / 1000)
else:
  thousands = int(N / 1000) + 1

print((1000 * thousands) - N)

Measured memory_bytes: 9164
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

int binary(int t, vector<int> s){
    int left = 0, right = s.size();
    while (left < right){
        int mid = (left + right)/2;
        if(s[mid] == t){
            return 1;
        }else if(s[mid] > t){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    return 0;
}


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

    int s,t,tmp;
    vector<int> ss;
    cin >> s;
    for(int i = 0; i < s;i++){
        cin >> tmp;
        ss.push_back(tmp);
    }
    cin >> t;
    int count = 0;
    for(int i = 0; i < t; i++){
        cin >> tmp;
        count += binary(tmp,ss);
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
const long long max=1000000007;

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2==1){
        cout << b-a << endl;
    }
    else{
        cout << a-b << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */
int testimony[15][15];
int main() {
    int N; cin >> N;
    int A[N];
    rep(i, N) {
        cin >> A[i];
        rep(j, A[i]) {
            int x, y;
            cin >> x >> y;
            testimony[i][--x] = y + 1;
            //0 -> non , 1 -> unonest, 2 -> honest
        }
    }
    int ans = 0;
    for(int bit = 0; bit < (1 << N); ++bit) {
        vector<bool> honest(N, false);
        rep(i, N) {
            if((1 << i) & bit) {
                honest[i] = true;
            }
        }
        bool ok = true;
        rep(i, N) {
            if(honest[i]) {
                rep(j, N) {
                    if(testimony[i][j] == 0) continue;
                    if(testimony[i][j] == 2 && honest[j] || testimony[i][j] == 1 && !honest[j]) {
                        continue;
                    }else {
                        ok = false;
                    }
                }
            }
        }

        if(ok) ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << endl;
}


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

int main(){
  int n,k;
  int sum=1;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    if(sum*2<sum+k){
      sum *= 2;
    }else{
      sum += k;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
N,M=map(int, raw_input().split())
a1=[]
a2=[]
a3=[]
a4=[]
a5=[]
a6=[]
a7=[]
a8=[]

c={}

for i in range(N):
	x,y,z=map(int, raw_input().split())
	a1.append(x+y+z)
	a2.append(x+y-z)
	a3.append(x-y+z)
	a4.append(x-y-z)
	a5.append(-x+y-z)
	a6.append(-x-y+z)
	a7.append(-x+y+z)
	a8.append(-x-y-z)


a1.sort(reverse=True)
a2.sort(reverse=True)
a3.sort(reverse=True)
a4.sort(reverse=True)
a5.sort(reverse=True)
a6.sort(reverse=True)
a7.sort(reverse=True)
a8.sort(reverse=True)


ans=float("-inf")
ans=max( ans, sum(a1[:M]) )
ans=max( ans, sum(a2[:M]) )
ans=max( ans, sum(a3[:M]) )
ans=max( ans, sum(a4[:M]) )
ans=max( ans, sum(a5[:M]) )
ans=max( ans, sum(a6[:M]) )
ans=max( ans, sum(a7[:M]) )
ans=max( ans, sum(a8[:M]) )

print ans



Measured memory_bytes: 32748
n,s,*a=map(int,open(0).read().split())
mod=998244353
d=[0]*(s+1)
d[0]=1
for x in a:
	p=[0]*(s+1)
	for i in range(s+1):
		p[i]+=d[i]*2
		if i+x<=s:
			p[i+x]+=d[i]
		p[i]%=mod
	d=p
print(d[-1])

Measured memory_bytes: 68680
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
//struct compare
//{
//  bool operator()(const int& l, const int& r)
//  {
//      return l>r;
//  }
//};

bool cmp(int a, int b)
{
    return a<b;
}
int on(int mask,int st)
{
    return mask|(1<<st);
}
int off(int mask,int st)
{
    return mask&(~(1<<st));
}
bool check(int mask,int st)
{
    return mask&(1<<st);
}
ll inf=1e18;
ll mod=1e9+7;
struct matrix{
    ll v[60][60];
    int row,col;
};

matrix multiply(matrix a, matrix b)
{
    ll sum=0;
    matrix ans;
    ans.row=a.row;
    ans.col=b.col;
    for(int i=0;i<ans.row;i++)
    {
        for(int j=0;j<ans.col;j++)
        {
            sum=0;
            for(int k=0;k<b.row;k++)
            {
                sum+=a.v[i][k]*b.v[k][j];
                sum%=mod;
            }
            ans.v[i][j]=sum;

        }
    }
    return ans;

}
matrix bigmod(matrix mat,ll p)
{
//    cout<<"yo "<<endl;
    if(p==1)
        return mat;
    if(p%2==0)
    {
        matrix a=bigmod(mat,p/2);
        return multiply(a,a);
    }
    else
    {
        matrix a=bigmod(mat,p-1);
        return multiply(mat,a);
    }
}
int main(void)
{
//    READ;
    ll n,k;
    sl2(n,k);
    matrix a;
    a.row=n;
    a.col=n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            sl(a.v[i][j]);
        }
    }
    a=bigmod(a,k);
    ll ans=0;
     for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            ans+=a.v[i][j];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
const int N=2005;
int n,m;
int g[N][N];
int dp[N],e[N],vis[N],x,y,f=0;
void dfs(int p,int t){
    if (vis[p]){
        if (vis[p]!=t+1)
            f=1;
        return;
    }
    vis[p]=t+1;
    if (t)
        x++;
    else
        y++;
    for (int i=1;i<=n;i++)
        if (i!=p&&!g[p][i])
            dfs(i,t^1);
}
int calc(int x){
    return x*(x-1)/2;
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1,a,b;i<=m;i++){
        scanf("%d%d",&a,&b);
        g[a][b]=g[b][a]=1;
    }
    memset(dp,0,sizeof dp);
    dp[0]=1;
    for (int i=1;i<=n;i++){
        if (vis[i])
            continue;
        x=0,y=0;
        dfs(i,0);
        memset(e,0,sizeof e);
        for (int j=n;j>=0;j--)
            e[j+x]|=dp[j],e[j+y]|=dp[j];
        for (int j=0;j<=n;j++)
            dp[j]=e[j];
    }
    if (f){
        puts("-1");
        return 0;
    }
    int ans=n*n*2;
    for (int i=0;i<=n;i++)
        if (dp[i])
            ans=min(ans,calc(i)+calc(n-i));
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 8552
#include<bits/stdc++.h>
using namespace std;
int a[25],b[25],c[25],n,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		cin>>b[i];
		ans+=b[i];
	}
	for(int i=1;i<n;i++)
		cin>>c[i];
	for(int i=1;i<n;i++){
		if(a[i]==a[i+1]-1)
		ans+=c[a[i]];
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B, T;
	
	cin>>A>>B>>T;
	
	cout<<(T/A)*B<<endl;
	
	return 0;
}

Measured memory_bytes: 384
def resolve():
    import numpy as np
    d = int(input())
    C = list(map(int, input().split()))
    S = []
    for _ in range(d):
        _S = list(map(int, input().split()))
        S.append(_S)
    S = np.array(S)

    T = []
    for _ in range(d):
        T.append(int(input()))

    last = [-1 for i in range(26)]
    score = 0
    for i in range(d):
        # max_idx = np.argmax(S[i])
        # print(max_idx + 1)
        score += S[i][T[i] - 1]
        last[T[i] - 1] = i
        for j in range(26):
            score -= C[j] * (i - last[j])

        print(score)

resolve()

Measured memory_bytes: 27248
#include<bits/stdc++.h>
using namespace std;
int n,w;
int arr[100][2];
int dp[100][101][300];
int w1;
int get(int cur,int num,int a){
if(cur==n)return 0;
if(dp[cur][num][a]>=0) return dp[cur][num][a];
int remain=w-w1*num-a;
int res=get(cur+1,num,a);
if(remain>=arr[cur][0])
    res=max(res,arr[cur][1]+get(cur+1,num+1,a+(arr[cur][0]-w1)));
return dp[cur][num][a]=res;
}
int main(void){
cin >> n >> w;
for(int i=0;i<n;i++)
    cin >> arr[i][0] >> arr[i][1];
memset(dp,-1,sizeof(dp));
w1=arr[0][0];
cout <<get(0,0,0);
}


Measured memory_bytes: 12032
# 10 1 8 

# 1, 8
# 1, 7
# 2, 6
# 3, 5
# 4, 4

# 1, 8
# 2, 9
# 3, 10
# 4, 10
# 5, 9
# 6, 8
# 7, 7

N, A, B = map(int, input().split())

def solve(n, a, b):
    m = b-a
    if m%2:
        return min(
            a     + solve(b-a, 1, b-a),
            n-b+1 + solve(n, a+(n-b+1), n),
        )
    else:
        return m//2

print(solve(N, A, B))

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
    int a,b,d,r;
    double f;
        scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f\n",d,r,f);
    

    return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;

    long long s = 0;
    map<long long, long long> m;
    for (int i = 0; i < n; i++) {
        long long a;
        cin >> a;

        s += a;
        m[a]++;
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        long long b, c;
        cin >> b >> c;

        s += c * m[b] - b * m[b];
        m[c] += m[b];
        m[b] = 0;

        cout << s << endl;
    }
}


Measured memory_bytes: 9364
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,k;
  string s;
  cin>>n;
  cin>>s;
  cin>>k;
  for(int i=0;i<n;i++){
    if(s[k-1]==s[i])cout<<s[k-1];
  	else cout<<"*";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  string S[N];
  ll M = 0;
  ll A = 0;
  ll R = 0;
  ll C = 0;
  ll H = 0;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    if (S[i][0] == 'M') {
      M++;
    } else if (S[i][0] == 'A') {
      A++;
    } else if (S[i][0] == 'R') {
      R++;
    } else if (S[i][0] == 'C') {
      C++;
    } else if (S[i][0] == 'H') {
      H++;
    }
  }
  ll ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n, k;
    long long int h[200010];
    long long int ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    sort(h, h + n);
    reverse(h, h+n);

    for (int i = 0; i < n; i++) {
        if (k) {
            k--;
        }
        else {
            ans += h[i];
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 1792
import java.util.*;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] c = new char[s.length()];
		for(int i=0; i<s.length(); i++) c[i] = s.charAt(i);
		for(int i=1; i<=s.length(); i++) System.out.print(c[s.length()-i]);
      		System.out.println();
	}

}

Measured memory_bytes: 12000
#include<cstdio>
#include<iostream>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if (a>0 && b>0) printf("Positive\n");
	else if (a<=0 && 0<=b) printf("Zero\n");
	else
	{
		if ((b-a)%2==0) printf("Negative\n");
		else printf("Positive\n");
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    s = input()
    for i,c in enumerate(s):
        if c == "A":
            a_pointer = i+1
            break

    for i,c in enumerate(s):
        if c == "Z":
            b_pointer = i+1
            continue
    print(b_pointer - a_pointer +1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3516
# n = int(input())
n, m = map(int,input().split())
# l = [[0 for _ in range(n)] for _ in range(n)]
l = []
f = 0

for i in range(m):
    l.append(list(map(int,input().split())))

# print(l)

for i in range(1000):
    si = str(i)
    if len(si) == n:
        for j in range(m):
            # print(si, l)
            if si[l[j][0]-1] == str(l[j][1]):
                # print('OK')
                f = 0
            else:
                f = 1
                break
    else:
        continue
    if f == 0:
        print(si)
        exit()

print(-1)

Measured memory_bytes: 3064
def main():
    a, b= map(int, input().split())
    if a == 1 or b == 1:
        print('1')
    else:
        if (a*b)%2 == 0:
            print(round((a*b)/2))
        else:
            print(round(((a//2)+(a%2))*b)-(b//2))

main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if (A1 + A2 + A3 < 22)
  {
    cout << "win" << endl;
  }
  else
  {
    cout << "bust" << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define INF 1000'000'000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int a[20][20];
int c[20];
int n, m, x;
int solve(int i = 0, vector < int > cur = vector <int > (m)){
	if(i == n){
		for(int j : cur)
			if(j < x)
				return INF;
		return 0;
	}
	int leave = solve(i+1, cur);
	// pick
	for(int j = 0; j < m; j++)
		cur[j] += a[i][j];
	int pick = solve(i+1, cur) + c[i];
	return min(leave, pick);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("in", "r", stdin);
	cin >> n >> m >> x;
	for(int i = 0; i < n; i++){
		cin >> c[i];
		for(int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	
	int ans = solve();
	cout << (ans >= INF ? -1 : ans) << endl;
	return 0;
}





Measured memory_bytes: 3620
import sys
readline = sys.stdin.readline

LR = "LR".index

def solve(A, L):
    K = len(A)
    if K == 0:
        return -1, -1, -1
    T = []
    v = -1; last = None
    left = 0
    for i in range(K):
        di, pi, ki = A[i]
        for j in range(i+1, K):
            dj, pj, kj = A[j]
            if di > dj:
                T.append(((pj - pi)//2, i, j))
        if di == 0:
            if v <= pi:
                v = pi
                last = i
                left = 1
        else:
            if v < L - pi:
                v = L - pi
                last = i
                left = 0
    T.sort()
    for _, i, j in T:
        A[i], A[j] = A[j], A[i]
    return v, A[last][2], left

ans = []
while 1:
    N, L = map(int, readline().split())
    if N == 0:
        break
    A = []; B = []
    for i in range(N):
        d, p = readline().split(); d = LR(d); p = int(p)
        if p % 2:
            A.append((d, p, i+1))
        else:
            B.append((d, p, i+1))
    v0, i0, l0 = solve(A, L)
    v1, i1, l1 = solve(B, L)
    if v0 > v1:
        ans.append("%d %d\n" % (v0, i0))
    elif v0 < v1:
        ans.append("%d %d\n" % (v1, i1))
    else:
        if l0:
            ans.append("%d %d\n" % (v0, i0))
        else:
            ans.append("%d %d\n" % (v1, i1))
sys.stdout.writelines(ans)


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

int aNum[101];

int main()
{
    int iNum = 0;
    
    cin >> iNum;
    
    for (int i = 0; i < iNum; i++)
    {
        cin >> aNum[i];
    }
    
    for (int i = iNum - 1; i >= 0; i--)
    {
        if (i != iNum - 1)
        {
            cout << " ";
        }
        
        cout << aNum[i];
    }
    
    cout << endl;
    
    return 0;
}



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

typedef vector<int> veci;
typedef pair<int,int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9+7)
#define fi first
#define se second
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST    
    int tcs;
    cin >> tcs;
    while (tcs-->0)
#endif        
{
    int n;
    cin >> n;

    veci v(n);
    for (int i=0; i<n; ++i)
        cin >> v[i];

    int cnt = 0;
    for (int i=0; i<n; ++i) {
        if (v[i]==i+1) {
            swap(v[i],v[i+1]);
            cnt++;
        }
    }

    cout << cnt << endl;
}}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut ans: usize = v.iter().sum();
    ans -= v.iter().max().unwrap() / 2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
input = raw_input

N,Q = map(int,input().split(" "))
s=list(input())
ju = []
for i in range(Q):
    ju.append(input().split(" "))

def isdeadleft(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            return True
        if xp > N-1:
            xp = N-1
    return False

def isdeadright(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            xp = 0
        if xp > N-1:
            return True
    return False

def mid(x1,x2):
    return int((x1+x2)/2)

if isdeadleft(N-1) or isdeadright(0):
    print(0)
    exit()

#left
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadleft(p2):
        p1,p2 = p2,mid(p2,p3)
    else:
        p2,p3 = mid(p1,p2),p2
if isdeadleft(p1):
    p = p3
else:
    p = p1
#right
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadright(p2):
        p2,p3 = mid(p1,p2),p2
    else:
        p1,p2 = p2,mid(p2,p3)
if isdeadright(p3):
    q = p1
else:
    q = p3

if p > q:
    print(0)
else:
    print(q-p+1)


Measured memory_bytes: 80192
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

    ll A, B;
    cin >> A >> B;

    ll ans = 0;
    reps(i, 1, 45) {
        ll bit = 1LL << i;

        ll cntA = A / bit * (bit / 2) + max(A % bit - (bit / 2), 0LL);
        ll cntB =
            (B + 1) / bit * (bit / 2) + max((B + 1) % bit - (bit / 2), 0LL);

        // cout << i << "-> A:" << cntA << ", B:" << cntB << endl;

        ll cnt = cntB - cntA;
        ans += (cnt % 2) * (bit / 2);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
  long long  n,m;
  cin >> n >> m;
  long long  res = 0;
  if(n == 1 && m == 1){
    res = 1;
  }
  else if (n >= 2 &&  m>= 2){
    res = (n-2)*(m-2);
  }
  else if (n == 1 && m > 1){
    res = m-2;
  }
  else{
    res = n-2;
  }
    

  cout << res << endl;
}

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

using namespace std;

typedef __int128 bll;
typedef long long lol;
typedef pair<bll,bool> pbb;
int _w;

lol A , B , C , D , N;
bll ans;

map<pbb,bll> mp;

void print( bll x ) {
  int S[64] , tp;
  tp = 0;
  while( x ) 
    S[++tp] = x % 10 , x /= 10;
  while( tp ) putchar( S[tp--] + '0' );
}

void dfs( bll now , bll cost , bool flag ) {
  if( cost >= ans ) return;
  ans = min( ans , cost + now * D );
  if( !mp.count( pbb( now , flag ) ) || mp[pbb( now , flag )] > cost ) mp[pbb( now , flag )] = cost;
  else return;
  if( now % 5 == 0 ) dfs( now / 5 , cost + C , 1 );
  if( now % 3 == 0 ) dfs( now / 3 , cost + B , 1 );
  if( !(now&1) ) dfs( now / 2 , cost + A , 1 );
  if( flag ) {
    dfs( now + 1 , cost + D , 0 );
    if( now > 0 ) dfs( now - 1 , cost + D , 0 );
    dfs( now + 2 , cost + 2 * D , 0 );
    if( now > 1 ) dfs( now - 2 , cost + 2 * D , 0 );
  }
}


int main( void ) {
  int T;
  _w = scanf("%d",&T);
  while( T-- ) {
    _w = scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);
    mp.clear();
    ans = (bll)D * N;
    dfs( N , 0 , 1 );
    print( ans );
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 9532
M,D = map(int,input().split())
cnt = 0
for i in range(1,M+1):
    for j in range(1,D+1):
        if j>=22:
            d1 = int(str(j)[-1])
            d10 = int(str(j)[-2])
            if d1>=2 and d10>=2 and i==d1*d10:
#                 print(i,d1,d10)
                cnt += 1
print(cnt)

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

using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        map<char,int>mp;
        pair<char,int>ans;
        int k=n;
        bool flag=0;
        for(int i=0;i<n;++i){
            char c;
            cin>>c;
            if(flag)continue;
            mp[c]++;
            k--;
            int f=0,s=0;
            for(auto x:mp){
                if(f<x.second){
                    s=f;
                    f=x.second;
                    ans=make_pair(x.first,i+1);
                }
                else s=max(s,x.second);
            }
            if(f>s+k)flag=1;
        }
        if(flag)cout<<ans.first<<" "<<ans.second<<endl;
        else cout<<"TIE"<<endl;
    }
}

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();
        int[] ball = new int[N];
        Arrays.fill(ball,1);
        ball[0] = -1;

        while(M-->0){
            int x = scan.nextInt() -1;
            int y = scan.nextInt() -1;
            if(ball[x] > 0){
                --ball[x];
                if(ball[y]>=0)++ball[y];
                else --ball[y];
            }else{
                ++ball[x];
                if(ball[y] >= 0)ball[y] *= -1;
                --ball[y];
            }
        }
        int ans = 0;
        for(int i=0;i<N;++i)if(ball[i] < 0)++ans;
        System.out.println(ans);

    }
}

Measured memory_bytes: 66300
#include <cstdio>
#include <cstring>
#include <algorithm>
#define P 998244353

using namespace std;

typedef long long ll;

ll powmod(ll x, ll y = P - 2, ll p = P) {
    ll ans = 1;
    while(y) {
        if(y & 1) ans = ans * x % p;
        x = x * x % p;
        y >>= 1;
    }
    return ans;
}

ll Fac[1000010], Rev[1000010], n, m;

ll C(ll x, ll y) {
    if(x < 0 || y < 0 || x < y) return 0;
    return Fac[x] * Rev[y] % P * Rev[x - y] % P;
}

int main() {
    for(int i = 0; i <= 1000001; i++) Fac[i] = !i ? 1 : Fac[i - 1] * i % P;
    for(int i = 1000001; i >= 0; i--) Rev[i] = i == 1000001 ? powmod(Fac[i]) : Rev[i + 1] * (i + 1) % P;
    scanf("%lld%lld", &n, &m);
    ll f = C(n + m, m), g = f, ans = f;
    for(int i = 1; i < n + m; i++) {
        g = (g + (i % 2 == 1 ? -2 : 1) * C(i - 1, (i / 2)) * (C(n + m - (i % 2 == 1) - i, m - i + (i / 2)))) % P;
        ans = (ans + (f = (f + g) % P) * Rev[i + 1] % P * Fac[i]) % P;
    }
    printf("%lld\n", ((ans * powmod(C(n + m, m))) % P + P) % P);
    return 0;
}


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

using namespace std;
map<string,int>mp;
int main()
{
    int n;
    cin>>n;
    char tmp[12];
    int ans=0;
    for(int i=0; i<n; i++)
    {
        scanf("%s", tmp);
        if(!mp[tmp])mp[tmp]=1,ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 19192
#include <stdio.h>

int main(void) {
    int P[3];
    for (int i = 0;i < 3;i++) {
        scanf("%d", &P[i]);
    }

    int n;
    if (P[0] == P[1] && P[1] == P[2] && P[0] == P[2]) {
        n = 1;
    } else if (P[0] == P[1] || P[1] == P[2] || P[0] == P[2]) {
        n = 2;
    } else {
        n = 3;
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a;
	bool flag = false;
	cin >> a;
	
	if(a < 10)
	{
		flag = true;
	}
	for(int i=2; i < 10; i++)
	{
		if(a % i == 0)
		{
			if((a / i) < 10)
			{
				flag = true;
			}
		}
	}

  	if(flag)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
<?php 
  fscanf(STDIN, "%d %d", $x, $n);
  $p = explode(' ', trim(fgets(STDIN)));
  $c = true;
  for ($i=0; $c == true ; $i++) {
    // code...
    $key = in_array($x + $i, $p);
    if (!$key) {
      // code...
      $c = false;
      $n = $x + $i;
    }
    $key = in_array($x - $i, $p);
    if (!$key) {
      // code...
      	echo $x - $i;
        $c = false;
        return;
    }
  }
  echo $n;

Measured memory_bytes: 16144
#include<iostream>
#include<cassert>
#include<ctime>
#include<climits>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include<list>
#include<stack>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define F first
#define S second
#define all(n) n.begin(),n.end()
#define pb push_back
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define INF (1<<27)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,int> PI;
typedef pair<P,P> PP;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
 
int main(){
  int h,n;
  while(true){
  cin >> n >> h;
  if(n+h == 0)break;
  long area = n*n*n;
 
   
  map<PI,bool> coor;
  while(h-- > 0){
    string coordinate;
    int a,b;
    cin >> coordinate >> a >> b;
    int x,y,z;
    
    if(coordinate == "xy"){
      REP(i,1,n+1){
    if(!coor[PI(P(a,b),i)]){
      coor[PI(P(a,b),i)] = true;
    }
      }
    }
    else if(coordinate == "xz"){
      REP(i,1,n+1){
    if(!coor[PI(P(a,i),b)])coor[PI(P(a,i),b)] = true;
      }
    }
    else if(coordinate == "yz"){
      REP(i,1,n+1){
    if(!coor[PI(P(i,a),b)])coor[PI(P(i,a),b)] = true;
      }
    }
    else assert(false);
     
  }
  cout << n*n*n - coor.size() << endl;
  }
return 0;
}

Measured memory_bytes: 4332
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
  a[i] = input()
  
row = [False] * h
col = [False] * w
for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      row[i] = True
      col[j] = True

for i in range(h):
  if row[i]:
    for j in range(w):
      if col[j]:
        print(a[i][j], end = '')
    print()

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

signed main() {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  for (int i = 0; i < k; i++) {
    int d, x;
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> x;
      a[x - 1] ++;
    }
  }

  int ans = 0;
  for (int x : a) ans += !x;
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <complex>

using namespace std;

int main()
{
	long long n,k;
	cin >> n >> k;

	long long ans = 0;

	long long amari = n % k;

	if (amari <= abs(amari - k))
	{
		ans = amari;
	}
	else
	{
		ans = abs(amari - k);
	}

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

	return 0;
}


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

int main(){
  int N,L;
  cin >> N >> L;
  int real_sum = 0;
  for(int i=0;i<N;i++){
   real_sum += L+i;
  }
  int sum = 0;
  if(L>=1){
      sum = real_sum - L;
    }else if(L<1 && N <= (-1)*L){
      sum = real_sum - (N+L-1);
    }else{
      sum = real_sum;
    }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256