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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;

int main(){
  int N; cin >> N;
  reps(i,N) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while(x) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      }
    }
  }
  cout << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int mod=1e9+7;
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  return x;
}
const int N=100005;
string s;
int dp[N][13];
int fun(int ind,int m=0)
{
  if(ind==sz(s)) return (m==5);
  if(dp[ind][m]!=-1) return dp[ind][m];
  if(s[ind]!='?')
    {
      int d=s[ind]-'0';
      return dp[ind][m]=fun(ind+1,(m*10+d)%13);
    }
  int ans=0;
  rep(i,0,10)
    ans=add(ans,fun(ind+1,(m*10+i)%13));
  return dp[ind][m]=ans;
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  memset(dp,-1,sizeof(dp));
  cin>>s;
  cout<<fun(0)<<endl;
  return 0 ;
}


Measured memory_bytes: 13392
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<i64>().unwrap());
    let a = itr.next().unwrap();
    let v = itr.next().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<i64>().unwrap());
    let b = itr.next().unwrap();
    let w = itr.next().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let t: i64 = is.trim().parse().unwrap();
    let d = (a - b).abs();

    println!("{}", if v * t >= w * t + d { "YES" } else { "NO" });
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int INF = int(1e9);

int n;
char s[2005];
vector<int> g[2005];
int lo[2005], hi[2005], cnt[2005];

void solve(int v, int par) {
    int clo = 0;
    int chi = 0;
    int ccnt = s[v] - '0';
    for (int to : g[v]) if (to != par) {
        solve(to, v);
        int tolo = lo[to] + cnt[to];
        int tohi = hi[to] + cnt[to];
        int nhi = chi + tohi;
        int nlo;
        if (chi < tolo) {
            nlo = tolo - chi;
        } else if (tohi < clo) {
            nlo = clo - tohi;
        } else {
            nlo = (tolo + clo) % 2;
        }
        clo = nlo;
        chi = nhi;
        ccnt += cnt[to];
    }
    lo[v] = clo;
    hi[v] = chi;
    cnt[v] = ccnt;
}

int res;
void go(int v, int par, int h) {
    if (s[v] == '1') {
        res += h;
    }
    for (int to : g[v]) if (to != par) {
        go(to, v, h + 1);
    }
}

int calc(int v) {
    res = 0;
    go(v, -1, 0);
    assert(res % 2 == 0);
    return res / 2;
}

int main() {
//    freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    scanf("%s", s);
    forn(i, n - 1) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        g[from].pb(to);
        g[to].pb(from);
    }
    int ans = INF;
    forn(i, n) {
        solve(i, -1);
        if (lo[i] == 0) {
            ans = min(ans, calc(i));
        }
    }
    if (ans == INF) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}


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

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

int main() {
  vector<string> s(8);
  for (auto& e : s) {
    cin >> e;
  }
  string piece = "ox";
  for (int turn = false, passed = 0; passed < 2; turn ^= true) {
    vector<pair<int, int>> v{{-1, -1}};
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        if (s[i][j] == '.') {
          vector<pair<int, int>> u{{i, j}};
          for (int k = 0; k < 8; k++) {
            vector<pair<int, int>> line;
            for (int l = 1;; l++) {
              int y = i + l * dy[k], x = j + l * dx[k];
              if (0 <= y && y < 8 && 0 <= x && x < 8 && s[y][x] != '.') {
                line.push_back({y, x});
              } else {
                break;
              }
            }
            auto e = find_if(begin(line), end(line), [&](auto x) { return s[x.first][x.second] == piece[turn]; });
            if (e != end(line)) {
              for (auto it = begin(line); it != e; it++) {
                u.push_back(*it);
              }
            }
          }
          if (!turn && u.size() > v.size() || turn && u.size() >= v.size()) {
            v = u;
          }
        }
      }
    }
    if (v.size() > 1) {
      for (auto e : v) {
        s[e.first][e.second] = piece[turn];
      }
      passed = 0;
    } else {
      passed++;
    }
  }
  for (auto e : s) {
    cout << e << endl;
  }
  return 0;
}



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

#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int lli;
typedef pair<int, int> P;

int main() {
    int a, b;
    cin >> a >> b;
    if (a == b)
        cout << a * 2 << endl;
    else
        cout << max(a, b) * 2 - 1 << endl;
}


Measured memory_bytes: 256
import bisect

n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

zero = A.count(0)
inm = bisect.bisect_left(A,0)
inp = bisect.bisect_right(A,0)
mi = [-x for x in A[:inm]]
mi = mi[::-1]
pl = A[inp:]
numm = inm
nump = n-inp

def shaku(x,l):
    count = 0
    if len(l) <= 1:
        return 0
    ri = len(l)-1
    for i in range(len(l)):
        while ri >= 0 and l[ri]*l[i] > x:
            ri -= 1
        
        count += max(ri-i,0)
        
    return count 

def search(x):
    count = 0
    if x >= 0:
        count += zero*(n-zero)+numm*nump+(zero*(zero-1))//2
        count += shaku(x,pl)
        count += shaku(x,mi)
            
        return count
    else:
        ri = 0
        
        for i in pl[::-1]:
            while ri < numm and i*mi[ri] < -x:
                ri += 1
            count += numm-ri
        return count

left = -10**18-1
right = 10**18+1
while right > left+1:
    mid = (left+right)//2
    a = search(mid)
    
    if a >= k:
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 109188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define ull unsigned long long

long long gcd(long long x, long long y){
    return y == 0 ? x : gcd(y, x % y);
}

long long lcm(long long x,long long y){
    return x / gcd(x,y) * y;
}

int main(){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld",lcm(a, b));
    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    char s[10];
    int k=0;
        scanf("%s",s);
    for(int i=0;i<=3;i++){
        for(int o=i+1;o<=3;o++){
            if(s[i]==s[o]){
                k++;
            }
        }
    }
    if(k==2){
        printf("Yes");
    }else{
        printf("No");
    }
}

Measured memory_bytes: 128
#include <algorithm>
#include <atcoder/all>
#include <iostream>
#include <set>
#include <tuple>
#include <vector>

using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
using namespace std;

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

  // k * (k + 1) = x * (n * 2)
  // n*2の約数を列挙
  // n*2の約数をk, k + 1に分配していくイメージ(k, k + 1は互いに素なので)
  // n*2の約数を分配できないなら、左辺は条件を満たさない

  vector<ll> r(2), m(2);
  r[1] = -1;
  n <<= 1;
  ll ans = n;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      // k ≡ 0 mod i
      // k ≡ -1 mod n / i
      m[0] = i, m[1] = n / i;
      auto res1 = atcoder::crt(r, m);
      if (res1.first != 0) ans = min(ans, res1.first);
      m[0] = n / i, m[1] = i;
      auto res2 = atcoder::crt(r, m);
      if (res2.first != 0) ans = min(ans, res2.first);
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3660
package main

import (
	"fmt"
	"math"
)

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	xb := math.Abs(float64(x - b))
	xa := math.Abs(float64(x - a))
	if (xb > xa) {
		fmt.Printf("A\n")
		return
	}
	fmt.Printf("B\n")
	return
}

Measured memory_bytes: 512
# coding: utf-8
import time
import re
import math

def main():
    s=input()
    t=input()
    f=0
    for a in range(len(s)):
        if s==t:
            f=1
        s=s[-1]+s[0:-1]
    if(f==1):print("Yes")
    else:print("No")


main()

Measured memory_bytes: 3184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int N, K,s=0;
cin >> N >> K;
vector<int> h(N);
for(int i = 0; i < N; i++){
    cin >> h.at(i);
    if(h.at(i)>=K){
        s++;
    }
}
cout << s << endl;
}

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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const ll INF = 1e9;
const ll INFF = 1e18;
const ll MAXN = 510;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

ll tab[10000010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for (ll i = 1 ; i <= 10000000 ; i++)
    {
        for (ll j = i ; j <= 10000000 ; j += i)
            tab[j]++;
    }
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1 ; i <= n ; i++)
        ans += i * tab[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81768
class Dice:
    def __init__(self, array):
        self.top = array[0]
        self.south = array[1]
        self.east = array[2]
        self.west = array[3]
        self.north = array[4]
        self.bottom = array[5]

    def roll_n(self):
        self.top, self.south, self.north, self.bottom = self.south, self.bottom, self.top, self.north

    def roll_s(self):
        self.top, self.south, self.north, self.bottom = self.north, self.top, self.bottom, self.south

    def roll_e(self):
        self.top, self.east, self.west, self.bottom = self.west, self.top, self.bottom, self.east

    def roll_w(self):
        self.top, self.east, self.west, self.bottom = self.east, self.bottom, self.top, self.west

    def IsEqual(self, dice2):
        if (self.top, self.south, self.east, self.west, self.north, self.bottom) == (dice2.top, dice2.south, dice2.east, dice2.west, dice2.north, dice2.bottom):
            return True
        else:
            return False


n1 = list(map(int, input().split()))
n2 = list(map(int, input().split()))

dice_1 = Dice(n1)
dice_2 = Dice(n2)

flag = False

for i in range(4):
    dice_1.roll_n()
    for j in range(4):
        dice_1.roll_e()
        if dice_1.IsEqual(dice_2):
            flag = True

dice_1.roll_e()

for i in range(4):
    dice_1.roll_n()
    for i in range(4):
        dice_1.roll_e()
        if dice_1.IsEqual(dice_2):
            flag = True



if flag:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 5608
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>

using namespace std;
using ll = long long;

struct f_e{
  int y_min = 49, y_max = 0, z_min = 49, z_max = 0;
};

bool solve(int h, int w, vector<vector<char>>field, map<char, f_e>mp, vector<char>v){
  for(auto i:v){
    f_e item = mp[i];
    for(int y = item.y_min; y <= item.y_max; y++){
      for(int z = item.z_min; z <= item.z_max; z++){
        if(field[y][z] == '.') return false;
        if(field[y][z] == i) field[y][z] = '.';
      }
    }
  }
  return true;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  while(n--){
    int h, w; cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    map<char, f_e> mp;
    vector<char> v;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> field[i][j];
        if(field[i][j] == '.') continue;
        if(mp.find(field[i][j]) == mp.end()) v.push_back(field[i][j]);
        mp[field[i][j]].y_min = min(mp[field[i][j]].y_min, i);
        mp[field[i][j]].y_max = max(mp[field[i][j]].y_max, i);
        mp[field[i][j]].z_min = min(mp[field[i][j]].z_min, j);
        mp[field[i][j]].z_max = max(mp[field[i][j]].z_max, j);
      }
    }
    sort(v.begin(), v.end());
    bool f = false;
    do{
      if(solve(h, w, field, mp, v)) f = true;
    }while(next_permutation(v.begin(), v.end()));
    if(f) cout << "SAFE" << endl;
    else cout << "SUSPICIOUS" << endl;
  }
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



Measured memory_bytes: 3080
/*                    ___          |\    /|           ____   ____   ____  ____
   |     |    /\    /    \ |     | | \  / |    /\    |    \ |    \ |     |    \
   |_____|   /__\   \____  |_____| |  \/  |   /__\   |____/ |____/ |__   |____/
   |     |  /    \       \ |     | |      |  /    \  |      |      |     |   \
   |     | /      \ \____/ |     | |      | /      \ |      |      |____ |    \
*/
#include<bits/stdc++.h>
using namespace std;
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pi pair<int,int>
#define pl pair<long,long>
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define endl '\n'
#define loop(i,n) for(ll i=0;i<n;i++)
#define mod (ll)(1e9+7)
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define vl vector<ll>
#define vpll vector<pair<ll,ll>>
#define INF 0x3f3f3f3f
#define mp make_pair

ll dp[1005][1005];

int main()
{
    ll n,ans=0;
    in(n);
    string s;
    cin>>s;
    char last = ',';
    for(ll i=0;i<n;i++) {
        if(s[i]!=last) {ans++;last=s[i];}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
n, *a = map(int, open(0).read().split())
x = [0]*n
for i in a: x[i-1] += 1
c = sum([i*(i-1)//2 for i in x])

z = [c - x[i]*(x[i]-1)//2 + (x[i]-1)*(x[i]-2)//2 for i in range(n)]
for i in a: print(z[i-1])

Measured memory_bytes: 25116
#include<bits/stdc++.h> 
typedef long long ll;
using namespace std;
const ll mod =998244353; 
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m;
int a[105],sum,tot;
int main(){
	int i,j;
    //freopen("a.in","r",stdin);
    n=read(),m=read();
    for(i=1;i<=n;i++) a[i]=read(),sum+=a[i];
    sum=sum;
    for(i=1;i<=n;i++) if(a[i]*4*m>=sum) tot++;
    if(tot>=m) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#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.at(i);
  }
  int k = 0, b = 0;
  for (int j = 0; j < N; j++) {
    k++;
    if (a.at(b) == 2) {
      cout << k << endl;
      break;
    }
    else {
      b = a.at(b) - 1;
    }
  }
  if (k == N) {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;

#define ll long long
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define mkp make_pair
#define eb emplace_back

const int N = 2e5 + 69;
const int NN = 2e3 + 69;
const int INF = 2e9 + 69;
const ll INF_LONG = 1e18;
const int mod = 1e9 + 7;
const int BLOCK = 174;

#define int ll

int a[N], pref[N];

vector <pair <int, int> > v;

int ans = 0;
int t[N];

int get(int pos) {
	int ans = 0;
	for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
		ans += t[pos];
	return ans;
}

void upd(int pos, int x) {
	for (; pos <= N; pos = (pos | (pos + 1)))
		t[pos] += x;
}

int calc(int l, int r) {
	return get(r) - get(l - 1);
}

void solve() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++ i)
		cin >> a[i];
	for (int i = 1; i <= n; ++ i)
		pref[i] = pref[i - 1] + a[i - 1];
	for (int i = 0; i <= n; ++ i)
		pref[i] -= (i * k);
	for (int i = 0; i <= n; ++ i)
		v.eb(mkp(pref[i], i));
	sort(all(v));
	int cnt = 0;
	for (int i = 0; i < sz(v); ++ i) {
		if (v[i].first > v[i - 1].first and i > 0)
			++cnt;
		pref[v[i].second] = cnt;
	}
	int res = 0;
	for (int i = 0; i <= n; ++ i) {
		res += calc(0, pref[i]);
		upd(pref[i], 1);
	}
	cout << res << '\n';
}

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 9456
/**********************************************
 *Author*        :XzzF
 *Created Time*  : 2018/7/7 20:05:17
 *Ended  Time*  : 2018/7/7 20:07:53
*********************************************/

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 200000;

char s[MaxN + 5];
int w;

int main()
{
	while(scanf("%s", s + 1) != EOF)
	{
		scanf("%d", &w);
		int len = strlen(s + 1);
		for(int i = 1; i <= len; i += w)
			printf("%c", s[i]);
		printf("\n");
	}
    return 0;
}

Measured memory_bytes: 256
import math

n, m = map(int, input().split())
s = input()
t = input()

g = math.gcd(n, m)
n //= g
m //= g

for i in range(g):
    if s[n * i] != t[m * i]:
        print(-1)
        exit()
else:
    print(n * m * g)
    

Measured memory_bytes: 9244
def resolve():
  N, = list(map(int, input().split()))
  W = list(map(int, input().split()))
  sa = 0
  sb = sum(W)
  r = float("inf")
  for w in W[:-1]:
    sa += w
    sb -= w
    r = min(r, abs(sa-sb))
  print(r)

resolve()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define N 2000005
using namespace std;

typedef long long ll;
ll M = 1e9 + 7;
ll x, y, fac[N] = {1,1}, inv[N] = {1,1}, fiv[N] = {1,1};
int main()
{
	ll i, t;
	cin >> x >> y;
	for (i = 2; i < N; i++) {
		fac[i] = fac[i - 1] * i % M;
		inv[i] = inv[M % i] * (M - M / i) % M;
		fiv[i] = fiv[i - 1] * inv[i] % M;
	}
	if ((x + y) % 3) {puts("0"); return 0;}
	t = (x + y) / 3;
    x -= t; y -= t;
    if (x < 0 || y < 0) {puts("0"); return 0;}
    cout << fac[x + y] * fiv[x] % M * fiv[y] % M << endl;
    return 0;
}

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  rep(i, n) {
    if (p.at(i) >= x) {
      int l = p.at(i) - 1;
      int r = p.at(i) + 1;
      
      int index = i;
      for (int j = i - 1; j >= 0; j--) {
        if (p.at(j) + 1 == p.at(index)) {
          index = j;
          l = p.at(j) - 1;
        }
        else {
          break;
        }
      }

      index = i;
      for (int j = i + 1; j < n; j++) {
        if (p.at(j) - 1 == p.at(index)) {
          index = j;
          r = p.at(j) + 1;
        }
        else {
          break;
        }
      }
      
      if (x - l <= r - x) {
        cout << l << endl;
      }
      else {
        cout << r << endl;
      }
      return 0;
    }
  }
  cout << x << endl;
}

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

#define FOR(i,l,n) for(int i=(l);i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define MAX_JUDGE 100
using namespace std;

int main(){
  int n,score[MAX_JUDGE];
  while(cin>>n,n){
    REP(i,n)cin>>score[i];
    sort(score,score+n);
    int sum=0;
    FOR(i,1,n-1)sum+=score[i];
    cout << sum/(n-2) <<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
  A[i] -= 1
  A[i] %= K

hm = {}
hm[A[0]] = 1
out = 0
for i in range(1,N):
  A[i] += A[i-1]
  A[i] %= K

for i in range(min(K-1,N)):
  if A[i]==0 and K != 1:
    out+=1
    
for i in range(1,min(N,K)):
  if A[i] in hm:
    hm[A[i]]+=1
  else:
    hm[A[i]]=1
  out += hm[A[i]]-1
  
for i in range(min(K,N),N):
  if A[i] in hm:
    hm[A[i]]+=1
  else:
    hm[A[i]]=1
  hm[A[i-K]] -= 1
  out += hm[A[i]]-1

print(int(out))

Measured memory_bytes: 32804
a,b,c,d = map(int,input().split())

while a > 0 and d > 0:
  c -= b
  if c <=0:
    flg = 0
    break
  a -= d
  if a <= 0:
    flg = 1
    break
    
if flg == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <ctime>
#include <random>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N;
string A,B,C;
ll ans;
int main() {
  cin >> N >> A >> B >> C;
  rep(i,N){
    if (A[i] == B[i] && B[i] == C[i]) {
    }
    else if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) {
      ans++;
    }
    else ans += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func toDoubleList() -> [Double]{
        return self.split(separator: " ").map{Double($0)!}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }

    func counter() -> Dictionary<Character, Int>{
        var result:[Character:Int] = [:]
        
        for c in self{
            guard let _ = result.index(forKey: c) else {
                result[c] = 1
                continue
            }
            result[c]! += 1
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}


func codefes2016finalb(){
    let N = Int(readLine()!)!
    var sum = 0
    var num = 0
    for n in 1...N{
        sum += n
        if (sum >= N) {
            num = n
            break
        }
    }
    let exnum = sum - N
    for i in 1...num{
        if i == exnum{
            continue
        }
        print(i)
    }
}


codefes2016finalb()


Measured memory_bytes: 13136
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


const int mod = 1000000007;
int main(int argc, char *argv[]) {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> v1(h, vector<int> (w, 0)), v2(h, vector<int> (w, 0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int a;
			// cin >> a;
			scanf("%d", &a);
			v1[i][j] = a;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int b;
			scanf("%d", &b);
			v2[i][j] = b;
		}
	}
	unordered_map<int, unordered_map<int, bitset<512512 * 2>>> um;
	um[-1][0][512512] = true;
	um[0][-1][512512] = true;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			um[i][j] = um[i][j - 1] | um[i - 1][j];
			int diff = v1[i][j] - v2[i][j];
			if (diff < 0)
			diff = -diff;
			um[i][j] = (um[i][j] >> diff) | (um[i][j] << diff);
		}
	}
	int res;
	for (res = 0; 512512 - res >= 0 && !um[h - 1][w - 1][512512 + res] && !um[h - 1][w - 1][512512 - res]; res++);
	cout << res << endl;
}


Measured memory_bytes: 822016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int f(int x) {
	int res = 0;
	while (x) {
		int cnt = 0;
		for (int i = 0; i < 20; i++)if (x&(1 << i))cnt++;
		x = x % cnt;
		res++;
	}
	return res;
}

int n, x[200010];
string s;

signed main() {
	cin >> n >> s;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '0')x[i] = 0;
		else x[i] = 1, cnt++;
	}
	int p = 0, q = 0;
	for (int i = 0; i < n; i++) {
		p = p * 2 + x[i];
		p %= (cnt + 1);
		q = q * 2 + x[i];
		if (0 < cnt - 1)q %= (cnt - 1);
	}
	for (int i = 0; i < n; i++) {
		if (x[i]) {
			if (cnt == 1)cout << 0 << endl;
			else cout << 1 + f((q - mod_pow(2, n - i - 1, cnt - 1) + cnt - 1) % (cnt - 1)) << endl;
		}
		else {
			cout << 1 + f((p + mod_pow(2, n - i - 1, cnt + 1)) % (cnt + 1)) << endl;
		}
	}
}

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

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> s(m,0);
	for(int i=0;i<n;i++)
	{
		int k;
		cin >> k;
		for(int j=0;j<k;j++)
		{
			int a;
			cin >> a;
			s.at(a-1)++;
		}
	}
	int k = 0;
	for(int i=0;i<m;i++)
	{
		if(s.at(i) == n)
		{
			k++;
		}
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
using namespace std;
using LL = long long;

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double theta1 = PI / 6 * (h + m /60);
    double theta2 = PI / 30 * m;
    double x1 = a * cos(theta1), Y1 = a * sin(theta1);
    double x2 = b * cos(theta2), Y2 = b * sin(theta2);
    cout << setprecision(15) << fixed << sqrt(pow(x2 - x1, 2) + pow(Y2 - Y1, 2)) << endl;
    return 0;
}

Measured memory_bytes: 4168
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			String x = sc.next();
			char y = x.charAt(0);
			
			if(Character.isUpperCase(y)) {
				System.out.println("A");
			}else {
				System.out.println("a");
			}
			
		}
	}


Measured memory_bytes: 35668
def main():
    from itertools import cycle

    H, W = map(int, input().split())
    N = int(input())
    *a, = map(int, input().split())

    g = [[-1] * (W + 2) for _ in range(H + 2)]
    for r in range(H + 1):
        g[r][0] = g[r][W + 1] = 0
    for c in range(W + 1):
        g[0][c] = g[H + 1][c] = 0

    def next_pos():
        dir_ = cycle([(1, 0), (0, 1), (-1, 0), (0, -1)])
        r, c = 1, 1
        cnt = 0

        dr, dc = next(dir_)
        while cnt < H * W:
            g[r][c] = cnt
            cnt += 1
            yield r - 1, c - 1
            if ~g[r + dr][c + dc]:
                dr, dc = next(dir_)
            r += dr
            c += dc

    gen_np = next_pos()

    ans = [[-1] * W for _ in range(H)]
    for i, x in enumerate(a, start=1):
        for _ in range(x):
            r, c = next(gen_np)
            ans[r][c] = i

    for row in ans:
        print(*row)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4312
import java.util.*;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int A=0,W=0,T=0,R=0;
		for(int i=0;i<N;i++) {
			String s=sc.next();
			if(s.equals("AC")) A++;
			else if(s.equals("WA")) W++;
			else if(s.equals("TLE")) T++;
			else R++;
			
		}
		sc.close();
		System.out.println("AC x "+A);
		System.out.println("WA x "+W);
		System.out.println("TLE x "+T);
		System.out.println("RE x "+R);
	}

}

Measured memory_bytes: 59164
#include <stdio.h>

long cnt = 0;

void merge(int a[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[2000001];
  int R[2000001];
  for (int i = 0; i < n1; i++) {
    L[i] = a[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = a[mid + i];
  }
  L[n1] = 1000000001;
  R[n2] = 1000000001;

  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      a[k] = L[i++];
    } else {
      a[k] = R[j++];
      cnt += n1 - i;
    }
  }
}

void mergeSort(int a[], int left, int right) {
  int mid = 0;
  mid = (left + right) / 2;
  if (left + 1 < right) {
    mergeSort(a, left, mid);
    mergeSort(a, mid, right);
    merge(a, left, mid, right);
  }
}

int main() {
  int n;
  scanf("%d\n", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  mergeSort(a, 0, n);
  printf("%ld\n", cnt);

  return 0;
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MaxN = 53;
int n;
LL a[MaxN];

int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for (int i=1;i<=n;++i) cin >> a[i];
	sort(a+1,a+n+1);
	LL ans=0;
	while (a[n]>=n) {
		LL x=a[n]/n;
		ans+=x;
		a[n]%=n;
		for (int i=1;i<=n-1;++i) a[i]+=x;
		sort(a+1,a+n+1);
	} 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	string a, b;
	cin >> a >> b;
	for (int i = 0;i < a.length() + b.length();++i) {
		if (i % 2 == 0) {
			cout << a[i / 2];
		}
		else {
			cout << b[i / 2];
		}
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define MAX 110
typedef long long ll;

int N,M;
ll dp[MAX][1<<16],L[MAX];
int bit[MAX];

ll solve(int n,int S){
  if(n == N){ return 0LL; }
  if(dp[n][S] != -1){
    return dp[n][S];
  }
  ll res = 0LL;
  res = max(res,solve(n+1,S));
  bool ok = true;
  for(int i = 0 ; i < 16 ; i++){
    if((S >> i) & (bit[n] >> i)){
      ok = false;
      break;
    }
  }
  if(ok){
    res = max(res,solve(n+1,S|bit[n])+L[n]);
  }
  return dp[n][S] = res;
}

int main(){
  int S,E;
  while(cin >> N, N){
    memset(dp,-1,sizeof(dp));
    for(int i = 0 ; i < N ; i++){
      cin >> M >> L[i]; bit[i] = 0;
      for(int j = 0 ; j < M ; j++){
        cin >> S >> E;
        S -= 6; E -= 6;
        for(int k = S ; k < E ; k++){
          bit[i] |= (1<<k);
        }
      }
    }
    cout << solve(0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 57492
#include<iostream>
#include<algorithm>
using namespace std;
char t;
int f(char a)
{
	if(a>'0'&&a<='9')return a-'0';
	else
	{
		switch(a)
		{
			case'T':return 10;
			case'J':return 11;
			case'Q':return 12;
			case'K':return 13;
			case'A':return 14;
		}
	}
}
main()
{
	while(cin>>t,t!='#')
	{
		string s[4][13];
		for(int i=0;i<4;i++)for(int j=0;j<13;j++)cin>>s[i][j];
		int cnt[2]={};
		char u=t;
		for(int i=0;i<13;i++)
		{
			int mt=-1,mu=-1,mc=-1;
			char su;
			for(int j=0;j<4;j++)
			{
				if(s[j][i][1]==t)mt=max(mt,f(s[j][i][0]));
				else if(s[j][i][1]==u)mu=max(mu,f(s[j][i][0]));
				else mc=max(mc,f(s[j][i][0]));
			}
			if(mt>0)
			{
				for(int j=0;j<4;j++)if(s[j][i][1]==t&&f(s[j][i][0])==mt)
				{
					cnt[j%2]++;
					if(i<12)su=s[j][i+1][1];
				}
			}
			else if(mu>0)
			{
				for(int j=0;j<4;j++)if(s[j][i][1]==u&&f(s[j][i][0])==mu)
				{
					cnt[j%2]++;
					if(i<12)su=s[j][i+1][1];
				}
			}
			else
			{
				for(int j=0;j<4;j++)if(f(s[j][i][0])==mc)
				{
					cnt[j%2]++;
					if(i<12)su=s[j][i+1][1];
				}
			}
			u=su;
		}
		if(cnt[0]<cnt[1])cout<<"EW "<<cnt[1]-6<<endl;
		else cout<<"NS "<<cnt[0]-6<<endl;
	}
}



Measured memory_bytes: 3104
x,y = map(int, input().split())

ans = 0

if x == 1: 
    if y == 1:
        ans = 1000000
    elif y == 2:
        ans = 500000
    elif y == 3:
        ans = 400000
    else:
        ans = 300000
elif x == 2: 
    if y == 1:
        ans = 500000
    elif y == 2:
        ans = 400000
    elif y == 3:
        ans = 300000
    else:
        ans = 200000
elif x == 3: 
    if y == 1:
        ans = 400000
    elif y == 2:
        ans = 300000
    elif y == 3:
        ans = 200000
    else:
        ans = 100000
else: 
    if y == 1:
        ans = 300000
    elif y == 2:
        ans = 200000
    elif y == 3:
        ans = 100000
    else:
        ans = 0
print(ans)


Measured memory_bytes: 3064
require 'prime'
N, P = gets.chomp.split(' ').map(&:to_i)
answer = 1
prime_division = Prime.prime_division(P)
while prime_division.any? { |_, e| e >= N }
  candidate_list = prime_division.select { |n, e| e >= N }
  answer *= candidate_list.map { |n, _| n }.reduce(&:*)
  prime_division = candidate_list.map { |n, e| [n, e - N]}
end
puts answer


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	ll a,b,n;
	cin>>n>>a>>b;
	cout<<(n/(a+b))*a + min((n%(a+b)),a);

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int N;
    std::string S;
    std::cin >> N;
    std::cin >> S;

    int max_kind = 0;
    for (int i = 1; i < N; i ++) {
        std::vector<char> X, Y;
        std::copy(S.begin(), S.begin() + i, std::back_inserter(X));
        std::copy(S.begin() + i, S.end(), std::back_inserter(Y));
        std::set<char> X_set(X.begin(), X.end());
        std::set<char> Y_set(Y.begin(), Y.end());

        std::vector<char> XandY;
        std::set_intersection(X_set.begin(), X_set.end(), Y_set.begin(), Y_set.end(), std::back_inserter(XandY));

        max_kind = std::max(max_kind, (int)XandY.size());
    }
    std::cout << max_kind << std::endl;
}


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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int A, B;
  cin >> A >> B;

  REP(i, 101*100/8) {
    if (i*8/100 == A && i*10/100 == B) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 892
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

vector<int> G[100000];
bool vis[100000];
vector<int> ord;

void visit(int n){
	if(!vis[n]){
		vis[n] = true;
		for(int i = 0; i < G[n].size(); i++){
			visit(G[n][i]);
		}
		ord.push_back(n);
		//cout << n;
	}
}

int main(){
	
	int V, E;
	cin >> V >> E;
	
	for(int i = 0; i < E; i++){
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
	}
	
	for(int i = 0; i < V; i++){
		visit(i);
	}
	
	reverse(ord.begin(), ord.end());
	
	for(int i = 0; i < ord.size(); i++){
		cout << ord[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 5844
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int n, m;
    cin >> n >> m;
    vec s[m];
    rep(i, m){
        int k;
        cin >> k;
        rep(j, k){
            int s_;
            cin >> s_;
            s_--;
            s[i].push_back(s_);
        }
    }
    int p[m];
    rep(i, m) cin >> p[i];
    int ans = 0;
    for (int i = 0; i < (1 << n); i++){
        bool flag = true;
        rep(j, m){
            int num = 0;
            rep(k, s[j].size()){
                if(((i >> s[j][k]) & 1) == 1) num++;
            }
            // cout << num << endl;
            if(num % 2 != p[j]) flag = false;
        }
        if(flag) ans++;
        // cout << i << " " << flag << endl;
    }
    cout << ans << endl;    
}

Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var d int
	var n int
	var ans int

	fmt.Scan(&d, &n)

	
	if n == 100 {
		n++
	}

	switch d {
	case 0:
		ans = n
	case 1:
		ans = n * 100
	case 2:
		ans = n * 100 * 100
	}

	fmt.Println(ans)
}

Measured memory_bytes: 512
let count n =
  let rec aux n' two four odd =
    if n' = 0 then (two, four, odd)
    else
      match Scanf.scanf "%d " (fun x -> x) with
      | f when f mod 4 = 0 -> aux (pred n') two (succ four) odd
      | t when t mod 2 = 0 -> aux (pred n') (succ two) four odd
      | _ -> aux (pred n') two four (succ odd)
  in
  aux n 0 0 0


let () =
  ( match Scanf.scanf "%d\n" count with
  | 0, f, o -> if f >= o - 1 then "Yes" else "No"
  | _, f, o -> if f >= o then "Yes" else "No" )
  |> print_endline

Measured memory_bytes: 2688
let n, m = Scanf.scanf "%d %d\n" @@ fun a b -> a, b
let a = Array.init m @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d
let ans =
  let x = n - (Array.fold_left (+) 0 a) in
  if x >= 0 then x else -1
let () = print_int ans

Measured memory_bytes: 5996
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  VSORT(a);
  cout << a[2] * 10 + a[1] + a[0] << endl;
}

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

using namespace std;

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a % 3 == 0){
    printf("Possible\n");
  }else if(b % 3 == 0){
    printf("Possible\n");
  }else if ((a + b) % 3 == 0){
    printf("Possible\n");
  }else{
    printf("Impossible\n");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
       int x = sc.nextInt();
       int y = sc.nextInt();
       int z = sc.nextInt();
       System.out.println(z + " "+x+" " +y);
    }    
    
}







Measured memory_bytes: 23252
#include<stdio.h>
#include<stdlib.h>
#define INFTY 1000000000

int cnt = 0;

void merge(int A[], int left, int mid, int right){

  int n1,n2,i,j,k;
  int *L,*R;
  
  n1 = mid - left;
  n2 = right - mid;
  
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++){
    L[i] = A[left+i];
  }
  for(j=0;j<n2;j++){
    R[j] = A[mid+j];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  i = 0;
  j = 0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
      cnt++;
    }
    else{
      A[k] = R[j];
      j++;
      cnt++;
    }
  }
  free(L);
  free(R);
}


void mergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int A[500000];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1){
      printf(" ");
    }
  }
  printf("\n%d\n",cnt);
  return 0;
}

Measured memory_bytes: 4480
#include <stdio.h>
#include <stdlib.h>
long long int n,a[100000],mod=1000000007,sum=1;
int prime(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        if(x/i==0) return 0;
    }
    return 1;
}
void fun(int x)
{
    for(int i=2;x!=1;i++)
    {

        while(prime(i)==1&&x%i==0)
        {
            x/=i;
            a[i]++;
        }
    }
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        fun(i);
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=0)
        {
           sum=sum*(a[i]+1)%mod;
        }
    }
    printf("%lld",sum);
}

Measured memory_bytes: 128
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

arr = inputs[0].sort.reverse

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

puts arr[0]*10 + arr[1] + arr[2]


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

int dp[51][51][2501];

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

    dp[0][0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i + 1; j++) {
            for (int c = 0; c <= k; c++) {
                ll t = 0;

                if (j - 1 >= 0 && c - (j - 1) * 2 >= 0) {
                    t += dp[i][j - 1][c - (j - 1) * 2];
                }
                if (c - j * 2 >= 0) {
                    t += dp[i][j][c - j * 2] * (ll)(j * 2 + 1);
                }
                if (j + 1 <= i && c - (j + 1) * 2 >= 0) {
                    t += dp[i][j + 1][c - (j + 1) * 2] * (ll)(j + 1) * (j + 1);
                }

                dp[i + 1][j][c] = t % P;
            }
        }
    }

    cout << dp[n][0][k] << endl;

    return 0;
}

Measured memory_bytes: 23808
import java.util.*;

class Main {

    private static boolean startWith(char[] chars, String str, int offset) {
        char[] strChars = str.toCharArray();
        if (offset + str.length() > chars.length) {
            return false;
        }
        for (int i = 0; i < strChars.length; i++) {
            if (chars[i + offset] != strChars[i]) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] tmp = sc.next().toCharArray();
        char[] T = new char[tmp.length];
        for (int i = 0; i < tmp.length; i++) {
            T[i] = tmp[tmp.length - 1 - i];
        }

        String[] words = new String[] {
                "maerd",
                "remaerd",
                "esare",
                "resare",
        };

        int offset = 0;
        while (true) {
            boolean notFound = true;
            for (int i = 0; i < words.length; i++) {
                if (startWith(T, words[i], offset)) {
                    notFound = false;
                    for (int j = offset; j < offset + words[i].length(); j++) {
                        T[j] = '.';
                    }
                    offset += words[i].length();
                }
            }
            if (notFound) {
                break;
            }
        }

        for (int i = 0; i < T.length; i++) {
            if (T[i] != '.') {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 27348