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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x; return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(vec.empty()){
        ostr << "";
    }
    else{
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
        ostr << " " << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main(){
    int n;
    cin >> n;
    vi a(n), m(n);
    cin >> a;

    // B(1/2)*m=a -> m=B\a : O(n^2)?
    /* rep(i,n){
        m[i] = 0;
        rep(j,n){
            if(i<=j){
                if((j-i)%2 == 0) m[i] += a[j];
                else m[i] -= a[j];
            }
            else{
                if((i-j)%2 == 0) m[i] -= a[j];
                else m[i] += a[j];
            }
        }
        cout << m[i] << " ";
    } */

   // m[0] = a[0] - a[1] + a[2] - ... +a[n-1]
   // m[i+1] = 2*a[i] - m[i] : O(n)?
    m[0] = 0;
    rep(i, n){
        if(i % 2) m[0] -= a[i];
        else m[0] += a[i];
    }
    // cout << m[0] << endl;
    rep(i, n-1){
        m[i+1] = 2*a[i] - m[i];
        // cout << m[i+1] << endl;
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 2048
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    private static Map<String, List<Integer>> cardsPerMark = new HashMap<>();
    static {
        cardsPerMark.put("S", createCardsList());
        cardsPerMark.put("H", createCardsList());
        cardsPerMark.put("C", createCardsList());
        cardsPerMark.put("D", createCardsList());
    }

    public static void main(String[] args) {
        Map<String, List<Integer>> inputCardsPerMark = new HashMap<>();
        inputCardsPerMark.put("S", new ArrayList<>());
        inputCardsPerMark.put("H", new ArrayList<>());
        inputCardsPerMark.put("C", new ArrayList<>());
        inputCardsPerMark.put("D", new ArrayList<>());

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String mark = sc.next();
            int number = sc.nextInt();

            List<Integer> numbers = inputCardsPerMark.get(mark);
            numbers.add(number);
            inputCardsPerMark.put(mark, numbers);
        }

        for (String mark : Stream.of("S", "H", "C", "D").collect(Collectors.toList())) {
            List<Integer> numbers = cardsPerMark.get(mark);
            List<Integer> inputNumbers = inputCardsPerMark.get(mark);
            numbers.removeAll(inputNumbers);
            for (Integer number : numbers) {
                System.out.printf("%s %d\n", mark, number);
            }
        }
        sc.close();
    }

    private static List<Integer> createCardsList() {
        List<Integer> cardsList = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            cardsList.add(i);
        }
        return cardsList;
    }
}


Measured memory_bytes: 32760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007;
ll arr[10000005],ans[10000005];
int main ()
{
    ll n, k;
    cin>>n>>k;
    
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    //ans[0]=0;
    for (int i=0;i<n;i++)
    {
        ans[i]=INF;
    }
    ans[0]=0;
    for (int i=0;i<n;i++)
    {
        for (int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            {
            ans[j]=min(ans[j],ans[i]+abs(arr[j]-arr[i]));
            }
        }
    }
    cout<<ans[n-1]<<'\n';

}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long po(long long a, long long b) {
  if (b == 0) {
	  return 1LL;
	}
  if (b % 2 == 1) {
	  return (a * po(a, b - 1)) % mod;
	}
  long long c = po(a, b / 2);
  return (c * c) % mod;
}

long long inv(long long a) {
  return po(a, mod - 2);
}

long long fact[3000] = { };
long long conb(long long a, long long b) {
  if (a < b) {
	  return 0;
	}
  long long ans = fact[a];
  ans = (ans * inv(fact[b])) % mod;
  ans = (ans * inv(fact[a - b])) % mod;
  return ans;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i <= 2000; i++) {
	  fact[i] = (i * fact[i - 1]) % mod;
	}
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
	  cout << conb(k - 1, i - 1) * conb(n - k + 1, i) % mod << endl;
	}
  return 0;
}


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

void Select_Sort(int A[], int N) {
  int count = 0;

  for (int i = 0; i < N; i++) {
    int minj = i;

    for (int j = i; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }

    if (A[i] != A[minj]) {
      swap(A[i], A[minj]);
      count++;
    }
  }

  for (int k = 0; k < N; k++) {
    cout << A[k];
    if (k != N - 1) cout << " ";
  }

  cout << endl << count << endl;

}

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

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

  Select_Sort(A, n);

  return 0;
}



Measured memory_bytes: 3056
#include <iostream>
using namespace std;
int main(){
string s1,s2,s3;
int n1,n2;
cin>>s1>>s2;
cin>>n1>>n2;
cin>>s3;
if(s1==s3)
    n1--;
if(s2==s3)
    n2--;
cout<<n1<<" "<<n2;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7


n, q = map(int, input().split())
g = [[] for _ in range(n)]
val = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    val[p - 1] += x

seen = [False] * n
def dfs(v):
    seen[v] = True
    for nv in g[v]:
        if seen[nv]:
            continue
        val[nv] += val[v]
        dfs(nv)

dfs(0)
print(*val)


Measured memory_bytes: 223428
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c,cnt=0;
  cin>>a;
  for(int i=1;i<=a;i++){
  cin>>b>>c;
    b==c?cnt++:cnt=0;
    if(cnt==3){
    cout<<"Yes";
    return 0;
    }
  }
  cout<<"No";
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <queue>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

void solve_E(){
    int n;
    cin >> n;
    int a[n];
    int all = 0;
    REP(i,n){
        cin >> a[i];
        all ^= a[i];
    }

    REP(i,n){
        cout << (a[i] ^ all) << endl;
    }


}

int main(void){
    solve_E();
    
    return 0;
}

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

using namespace std;
typedef long long int ll;

const ll mod = 1e9 + 7;


void solve()
{
	int x;
	cin >> x;
	if(x) cout << 0;
	else cout << 1;
}

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
}


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


const int INF = 1e9+5;

int main(){
    int n,k;
    cin>>n;
    vector<int> dp(3,0);

    for(int i=0; i<n; i++){
        vector<int> dpn(3,-1);
        vector<int> p(3);
        for(int j=0; j<3; j++) cin>>p[j];
        //for(int j=0; j<3; ++j) cout<<p[j]<<" ";
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(j!=k)
                    dpn[k]=max(dpn[k],dp[j]+p[k]);
            }
        }

        dp=dpn;
        //for(int j=0; j<3; ++j) cout<<dp[j]<<" ";
        //cout<<"\n";
    }

    cout<<max(dp[0],max(dp[1],dp[2]))<<"\n";
}

Measured memory_bytes: 3576
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int>vi;
typedef vector<ll>vii;
typedef set<int>si;
typedef set<ll>sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const ll MOD =(ll)1e9+1147483647;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int k;
    cin>>k;
    ll cnt=0;
    for(int i=1;i<=k+100;i++)
    {
        cnt*=10;
        cnt+=7;
        cnt%=k;
        if(cnt==0)
        {
            cout<<i<<nl;
            return 0;
        }
    }cout<<-1<<nl;
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double x1 = scan.nextDouble();
		double y1 = scan.nextDouble();
		double x2 = scan.nextDouble();
		double y2 = scan.nextDouble();
		double X = Math.pow(x2 - x1, 2);
		double Y = Math.pow(y2 - y1, 2);
		double len = Math.sqrt(X + Y);
		System.out.println(len);
	}
}

Measured memory_bytes: 27904
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll ans = 0;
    rep(i,n){
        int x = (a[n-1-i] + ans)%b[n-1-i];
        if(x){
            ans += b[n-1-i] - x;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] l = new int[n + 1];
		for(int i = 1; i <= n; i++) {
			l[i] = sc.nextInt();
		}
		int d = 0;
		int count = 1;
		for(int i = 1; i <= n; i++) {
			if(d + l[i] <= x) {
				d += l[i];
				count++;
			} else {
				break;
			}
		}
		System.out.println(count);
		
		sc.close();
	}

}


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

long n, k, a[1<<18];
double b[1<<18], sum[1<<18];

int main(){
  cin >> n >> k;
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= n; i++) b[i] = b[i-1] + (double)log10(a[i]);
  for(int i = k; i <= n; i++) sum[i] = b[i] - b[i-k];
  for(int i = k+1; i <= n; i++) cout << (sum[i-1] + 1e-12 < sum[i] ? "Yes" : "No") << endl;
  return 0;
}

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

int n;

int main()
{
    scanf("%d", &n);
    int pw = 0;
    while (1 << pw < n) pw++;
    if (1 << pw == n) printf("No\n");
    else {
        printf("Yes\n");
        printf("1 2\n");
        printf("2 3\n");
        printf("3 %d\n", n + 1);
        printf("%d %d\n", n + 1, n + 2);
        printf("%d %d\n", n + 2, n + 3);
        int sav = n % 2 == 0? n: -1;
        int lim = n % 2 == 0? n - 1: n;
        while (lim > 3) {
            int tk = (lim ^ (lim - 1));
            printf("%d %d\n", lim, lim - 1);
            printf("%d %d\n", lim - 1, tk);
            printf("%d %d\n", n + tk, n + lim);
            printf("%d %d\n", n + lim, n + lim - 1);
            lim -= 2;
        }
        if (sav != -1) {
            int tk = (sav ^ (sav - 1));
            printf("%d %d\n", sav, n + sav - 1);
            if (tk == 3) printf("%d %d\n", n + sav, n + 2);
            else printf("%d %d\n", n + sav, tk - 1);
        }
    }
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int n;
        while(scanf("%d", &n) && n){
                int w, h;
                scanf("%d%d", &w, &h);
                int grid[w+1][h+1];
                rep(i, w+1)rep(j, h+1) grid[i][j]=0;
                rep(i, n){
                        int x, y;
                        scanf("%d%d", &x, &y);
                        ++grid[x][y];
                }
                rep(i, w+1)rep(j, h) grid[i][j+1]+=grid[i][j];
                rep(j, h+1)rep(i, w) grid[i+1][j]+=grid[i][j];
                int s, t;
                scanf("%d%d", &s, &t);
                int ans=0;
                for(int i=0; i+s<=w; ++i)for(int j=0; j+t<=h; ++j){
                        int tmp=grid[i+s][j+t]-grid[i+s][j]-grid[i][j+t]+grid[i][j];
                        chmax(ans, tmp);
                }
                printf("%d\n", ans);
        }
}


Measured memory_bytes: 3204
#include<stdio.h>
#define MAX 100005
#define NIL -1
  
struct Node{
int p, l, r;
};
struct Node T[MAX];
int n;

main(){
  int i, j, d, v, c, l;
  int first;
    scanf("%d", &n);
      
    for ( i = 0; i < n; i++ ) {
        T[i].p = T[i].l = T[i].r = NIL;
    }

    for (i = 0; i <n ; i++){
      scanf("%d %d %d", &v, &d, &c);
      if(i==0) first=v;
           T[d].p=v;
         	 T[c].p=v;
           T[v].l=d;
           T[v].r=c;
    }

    for(i=0;i<n;i++){
      if(T[i].p == NIL){
      first=i;
      break;
      }
    }

    printf("Preorder\n");
    Preorder(first);
     
    printf("\n");
    printf("Inorder\n");
    Inorder(first);
  
    printf("\n");
    printf("Postorder\n");
    Postorder(first);
  
    printf("\n");
    return 0;
} 

void Preorder(int u){
  if(u != NIL){
  printf(" %d",u);  
  Preorder(T[u].l); 
  Preorder(T[u].r);
  }
}
 
void  Inorder(int u){
  if(u != NIL){
   Inorder(T[u].l); 
  printf(" %d",u);
 Inorder(T[u].r);
  }
}
 
void  Postorder(int u){
 if(u != NIL){
Postorder(T[u].l); 
Postorder(T[u].r); 
 printf(" %d",u);
}
 
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ps(n);
    for (int& p : ps) {
        cin >> p;
    }
    int sum = 0;
    for (int i = 1; i < n-1; ++i) {
        sum += (ps[i-1] < ps[i] && ps[i] < ps[i+1]) || (ps[i-1] > ps[i] && ps[i] > ps[i+1]);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, a[100010], b[100010], c[100010], dp[100010][3];

signed main() {
	cin >> n;
	rep(i, n)cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
	}
	cout << max({ dp[n - 1][0],dp[n - 1][1],dp[n - 1][2] }) << endl;
	ggr
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    String S = sc.next();

    sc.close();

    char[] s = S.toCharArray();

    int[] fArr = new int[26];
    int[] bArr = new int[26];

    int max = 0;

    for (int i = 0; i <= N; i++) {
      
      int count = 0;
      Arrays.fill(fArr, 0);
      Arrays.fill(bArr, 0);

      for (int j = 0; j < N; j++){
        if (j < i) {
          fArr[(int)s[j] - 97]++;
        } else {
          bArr[(int)s[j] - 97]++;
        }
      }

      for (int j = 0; j < 26; j++) {

        if (fArr[j] != 0 && bArr[j] != 0) {
          count++;
        }

      }

      max = Math.max(max, count);

    }
    
    System.out.println(max);
    
  }

}

Measured memory_bytes: 23252
s = input()
for i in range(2 ** 3):
    res = int(s[0])
    ans = s[0]
    for j in range(3):
        if ((i >> j) & 1):
            res += int(s[j + 1])
            ans += "+" + s[j + 1]
        else:
            res -= int(s[j + 1])
            ans += "-" + s[j + 1]
    if res == 7:
        # print(res)
        print(ans + "=7")
        exit()

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

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int tmp;
    vector<int> a(n+1,0);
    for(int i = 1; i <= m; i++){
        cin >> tmp;
        a[tmp] += 1;
    }
    int ans1 = 0, ans2 = 0;
    for(int i = x; i > 0; i--){
        if(a[i-1] == 1){
            ans1++;
        }
    }
    for(int i = x; i < n; i++){
        if(a[i+1] == 1){
            ans2++;
        }
    }
    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 256
def func(x,y):
    return min(x,y)

class SegmentTree:
    def __init__(self, n): #a1, a2, ..., an
        n_ = 1
        while n_ < n:
            n_ *= 2

        self.n = n_
        self.arr = [10**18] * (2*self.n-1)

    def update(self, k, a): #0_indexed
        k += self.n - 1
        self.arr[k] = a

        while k > 0:
            k = (k-1) // 2
            self.arr[k] = min(self.arr[2*k+1], self.arr[2*k+2])

    def query(self, l, r):
        L, R = l+self.n, r+self.n
        ide_ele = float("inf")
        #単位元(ide_ele)は、区間外の値などに設定する値です。
         #ex) 最小値のセグ木 → +inf
         #　和のセグ木 → 0
         #　積のセグ木 → 1
         #  gcdのセグ木 → 0
        res = ide_ele
        while L < R:
            if R & 1:
                R -= 1
                res = func(res, self.arr[R-1]) #

            if L & 1:
                res = func(res, self.arr[L-1])
                L += 1

            L >>= 1
            R >>= 1

        return res

n,m=map(int,input().split())
lrc=[tuple(map(int,input().split())) for _ in range(m)]
dp=SegmentTree(n+1)
dp.update(1,0)

rl=[[] for _ in range(n+1)]
rc=[[] for _ in range(n+1)]
for l,r,c in lrc:
    rl[r].append(l)
    rc[r].append(c)

for r in range(2,n+1):
    x=float("inf")
    for l,c in zip(rl[r],rc[r]):
        y=dp.query(l,r)+c
        if x>y:
            x=y
    dp.update(r,x)
    if r==n:
        ans=x

if ans==float("inf"):
    ans=-1
print(ans)


Measured memory_bytes: 134232
#include <stdio.h>
int p[92][92],ans;
void step(int x,int y,int n){
    p[x][y]=0;
    if (n>ans) {
        ans=n;
    }
    if (p[x+1][y]==1) {
        step(x+1, y,n+1);
    }
    if (p[x-1][y]==1) {
        step(x-1, y,n+1);
    }
    if (p[x][y+1]==1) {
        step(x, y+1,n+1);
    }
    if (p[x][y-1]==1) {
        step(x, y-1,n+1);
    }
    p[x][y]=1;
}
int main(){
    while (1) {
        int m,n;
        scanf("%d%d",&m,&n);
        if (m==0&&n==0) {
            return 0;
        }
        int i,j;
        ans=0;
        for (i=0; i<n+2; i++) {
            for (j=0; j<m+2; j++) {
                if (i==0||j==0||i==n+1||j==m+1) {
                    p[j][i]=0;
                }else{
                    scanf("%d",&p[j][i]);
                }
            }
        }
        for (i=1; i<=n; i++) {
            for (j=1; j<=m; j++) {
                if (p[j][i]==1) {
                    step(j,i,1);
                }
            }
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 2056
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,x,y;
bool sp[SZ];
namespace T2
{
Edg
int fa[SZ],dep[SZ];
int sd(int a,int b)
{
	if(a==b) return 0;
	if(a==fa[b]||b==fa[a]) return 1;
	if(fa[fa[a]]==b||a==fa[fa[b]]||fa[a]==fa[b])
		return 2;
	return 3;
}
void dfs(int x,int f=0,int d=0)
{
	fa[x]=f; dep[x]=d;
	for esb(x,e,b) if(b!=f) dfs(b,x,d+1);
}
}
namespace T1
{
Edg
int mx;
void dfs(int x,int f=0,int d=0)
{
	if(d>=T2::dep[x]) return;
	mx=max(mx,T2::dep[x]-1); if(sp[x]) {mx=1e9; return;}
	for esb(x,e,b) if(b!=f) dfs(b,x,d+1);
}
}
int A[SZ],B[SZ];
int main()
{
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<n;++i)
		scanf("%d%d",A+i,B+i),T1::adde(A[i],B[i]);
	for(int i=1;i<n;++i)
	{
		int p,q;
		scanf("%d%d",&p,&q);
		T2::adde(p,q);
	}
	T2::dfs(y);
	for(int i=1;i<n;++i)
		if(T2::sd(A[i],B[i])==3)
			sp[A[i]]=sp[B[i]]=1;
	T1::dfs(x);
	if(T1::mx>1e8)
		puts("-1");
	else printf("%d\n",T1::mx*2+2);
}


Measured memory_bytes: 34048
#include <stdio.h>

int main(void){
  int N, ac=0, wa=0, tle=0, re=0;
  char ans[4];
  scanf("%d",&N);
  
  while(N--){
    scanf("%s",ans);
    if('A' == ans[0]) ac++;
    if('W' == ans[0]) wa++;
    if('T' == ans[0]) tle++;
    if('R' == ans[0]) re++;
  }
  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);
}

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

// DP テーブル
long long dp[3100][3100];

int main() {
    // 入力受け取り
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // 初期条件
    for (int i = 0; i < N; ++i) dp[i][i] = 0;

    // DP
    for (int len = 1; len <= N; ++len) {
        for (int i = 0; i + len <= N; ++i) {
            int j = i + len;

            // 先手番
            if ((N - len) % 2 == 0)
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);

            // 後手番
            else
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
        }
    }

    // 答え
    cout << dp[0][N] << endl;
}

Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int A , B;
    cin >> A >> B;
    if(A + B == 3){
        cout << 3 << endl;
    }
    else if(A + B == 4){
        cout << 2 << endl;
    }
    else{
        cout << 1 << endl;
    }
}

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

int main() {
  int t;
  cin >> t;
  int sum = 0;
  int a = 0;
  if(t > 0) {
    for(a = 0;t - (30 * a) >= 30; ++a) {
    }
    sum = (t - 30 * a) * 2;
  }
  cout << a << " " << sum << endl;
  return 0;
}

Measured memory_bytes: 3112
# coding: utf-8
# Your code here!
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
lst=[a1,a2,a3,b1,b2,b3]
for i in range(1,5):
#    print(i)
    if lst.count(i) > 2:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

lint N, M;


int main()
{
    cin >> N >> M;

    vector<lint> yakusu;
    for (lint i = 1; i * i <= M; i++)
    {
        if (M % i == 0)
        {
            yakusu.push_back(i);
            if (i != M / i) yakusu.push_back(M / i);
        }
    }
    sort(yakusu.begin(), yakusu.end());
    dbg(yakusu);

    cout << *(upper_bound(yakusu.begin(), yakusu.end(), M / N) - 1);
}


Measured memory_bytes: 256
#include <cstdio>

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

    int min_shift = 0;
    for (int i = 0; i < N; ++i)
    {
        int shift = 0;
        while ((A[i] & 1) == 0)
        {
            A[i] >>= 1;
            ++shift;
        }
        if (shift == 0)
        {
            break;
        }
        else if (min_shift > shift || min_shift == 0)
        {
            min_shift = shift;
        }
 
    }
    // Output
    printf("%d\n", min_shift);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
int K;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> s >> K;
}

int solve(){
    set<string> A;
    for (int i = 0; i < s.length(); i++)
    {
        string a="";
        for (int k = 0; k < K; k++)
        {
            if(i+k>=s.length()) continue;
            a+=s[i+k];
            A.insert(a);
        }
    }
    // for(auto itr=A.begin();itr!=A.end();++itr){
    //     cout << *itr << endl;
    // }
    auto itr=A.begin();
    for (int k = 0; k < K-1; k++) ++itr;
    cout << *itr << endl;
    

    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 1664
program main
 implicit none
 integer N,i
 integer,allocatable::A(:),B(:)
 
 read(*,*) N
 allocate(A(N),B(N))
 
 read(*,*) A
 do i=1,N
  B(A(i)) = i
 end do
 
 write(*,*) B
end program main

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cmath>
#define eps 0.0000001
using namespace std;
struct po{int x,y,z,r; long long l;};
struct popo{int x,y,z;};

double mk_dis(popo a,popo b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

int main(){
  int n,q;
  cin >>n>>q;
  po ball[51];
  for(int i=0;i<n;i++)cin>>ball[i].x>>ball[i].y>>ball[i].z>>ball[i].r>>ball[i].l;
  
  for(int i=0;i<q;i++){
    int a1,a2,b1,b2,c1,c2;
    double dis[3];
    cin >>a1>>b1>>c1>>a2>>b2>>c2;
    dis[0] = mk_dis((popo){a1,b1,c1},(popo){a2,b2,c2});
    long long ans=0;
    for(int j=0;j<n;j++){
      dis[1] = mk_dis((popo){a1,b1,c1},(popo){ball[j].x,ball[j].y,ball[j].z});
      dis[2] = mk_dis((popo){a2,b2,c2},(popo){ball[j].x,ball[j].y,ball[j].z});
      double s = (dis[0]+dis[1]+dis[2])/2.0;
      double S = sqrt(s*(s-dis[0])*(s-dis[1])*(s-dis[2]));
      double h = (2*S)/dis[0];
      
      /*      if(dis[1]-ball[j].r<=eps ||dis[2]-ball[j].r<=eps) {
	ans+=ball[j].l;
	continue;
	}*/

      if(fabs(sqrt(dis[1]*dis[1]-h*h)+sqrt(dis[2]*dis[2]-h*h)-dis[0]) > eps)continue;
      if(h-ball[j].r<=eps) ans+=ball[j].l;
    }
    cout << ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
s=list(input())
a=0
b=0
c=0
for i in range(len(s)):
    if s[i]=='a':
        a+=1
    elif s[i]=='b':
        b+=1
    else:
        c+=1
if(a<(int(len(s)/3)) or b<(int(len(s)/3)) or c<(int(len(s)/3))):
    print('NO')
else:
    if len(s)%3!=2:
        print('YES')
    else:
        if max(a,b,c)==(int(len(s)/3)+2):
            print('NO')
        else:
            print('YES')


Measured memory_bytes: 9896
#include <algorithm>
#include <iostream>
 
using namespace std;
 
int main() {
	long long a; cin >> a;
	string b; cin >> b;
	cout << a * ((b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0')) / 100 << '\n';
	return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;

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

        if (N < 0 || N > 81) {
            System.out.println("No");
            return;
        }

        for (int i = 1; i <= 9; i++) {
            float value = N / (float) i;
            if (value < 1f) {
                break;
            }

            if (value <= 9 && (int) Math.floor(value) == (int) Math.ceil(value)) {
                System.out.println("Yes");
                return;
            }
        }

        System.out.println("No");
    }
}

Measured memory_bytes: 22100
# 入力
[N,X] = list(map(int, input().split()))
m = [int(input()) for i in range(N)]

# 処理
s = 0      # お菓子の素の総和
mn = 1001  # お菓子の素の最小値

for i in range(N):
  s += m[i]
  if m[i] < mn:
    mn = m[i]  # 最小値を更新
    
# 出力
print(N+(X-s)//mn)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int a,b;
    cin >> a >> b;
    //処理
  	int ans=1;
  	if(a%b==0) ans = 0;
    //出力
    cout << ans << ENT;
    return 0;
}

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


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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="776755";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int inc(int st,string s)
{
    int n=s.length();
      while(st<n&&s[st]!='W') st++;
      return st;

}
int dec(int en,string s)
{
     int n=s.length();
    while(en>0&&s[en]!='R') en--;
    return en;
}
int main()
{
    int n;
    cin>>n;

    string s;
    cin>>s;
    int st=0;
    int en=n-1;
    while(st<n&&s[st]!='W') st++;

    while(en>0&&s[en]!='R') en--;
     int ans=0;
     while(en>st)
     {
        // cout<<en<<" "<<st<<endl;
         ans++;
         st++;
         en--;
         st=inc(st,s);
         en=dec(en,s);
         // cout<<en<<" "<<st<<endl;
     }
     cout<<ans<<endl;


}


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

int main() {
  ll n,ans=0;
  cin >> n;
  ans=(n+1)/2-1;
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans =1 ;
  char s;
  cin >>s;
  char t = s;
  for(int i = 0;i<3;i++){
    cin >> s;
    if( t == s){
      ans++;
    }
    else {
      ans =1;
    }
    if(ans == 3){
      cout << "Yes";
      return 0;
    }
     t =s;
  }
  cout << "No";
    
}

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

vector <int> g[323456]; 
int cnt[323456];
int ans;
int d[323456];
vector <int> ord;
bool used[323456];

void dfs(int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ord.push_back (v);
}

void bfs() {
	queue <int> q;

	for(int i = 0; i < ord.size(); i++) q.push(ord[i]);
	while(q.size()) {
		int x = q.front();
		q.pop();
		for(int i = 0; i < g[x].size(); i++) {
			int y = g[x][i];
			if(d[x] + 1 > d[y]) d[y] = d[x] + 1, q.push(y), ans = max(ans, d[y]);
		}
	}
	cout << ans;
	exit(0);
}
long double p[5000];
long double dp[5000][5000];
int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++) {
	dp[i][0] = (1 - p[i]) * dp[i - 1][0];
	
	long double sum = 0;
	for(int j = 1; j <= i; j++)
		dp[i][j] = dp[i - 1][j] * (1 - p[i])+ dp[i - 1][j -1] * p[i];
	if(i == n) for(int j = n / 2 + 1; j <= n; j++) sum += dp[i][j];
	if(i == n)cout << fixed << setprecision(10)  << sum;
	}

}


Measured memory_bytes: 243840
#include<stdio.h>

int main(){
  int A[100], tmp, N, i, j;
  int cnt = 0;
  
  scanf("%d", &N);
  for (i=0; i<N; i++) {
    scanf("%d", &A[i]);
  }

  for (i=0; i<N-1; i++) {    
    for (j=0; j<N-i-1; j++) {
      if (A[j] > A[j+1]) {
        tmp = A[j];
        A[j] = A[j+1];
        A[j+1] = tmp;
        cnt++;
      }
    }
  }

  for (j=0; j<N-1; j++) {
    printf("%d ", A[j]);
  }
  printf("%d\n%d\n", A[N-1], cnt);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int a,b;cin>>a>>b;
    if(a<=5)co(0);
    else if(a>=6&&a<=12)co(b/2);
    else co(b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int k[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
cin>>n;
cout<<k[n-1];
    return 0;
}







Measured memory_bytes: 3644
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Ca=dict(Counter(A))
Dk=Ca.keys()
a=0
for i in Dk:
    if i>Ca[i]:
        a+=Ca[i]
    elif i<Ca[i]:
        a+=Ca[i]-i
print(a)

Measured memory_bytes: 21740
import math

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] -= i+1
a = sorted(a)
b1 = math.floor(sum(a)/n)
b2 = math.ceil(sum(a)/n)
b3 = b1-1
b4 = b2+1
b5 = a[n//2]
b6 = a[n//2-1]

ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
ans5 = 0
ans6 = 0
for i in range(n):
  ans1 += abs(a[i]-b1)
  ans2 += abs(a[i]-b2)
  ans3 += abs(a[i]-b3)
  ans4 += abs(a[i]-b4)
  ans5 += abs(a[i]-b5)
  ans6 += abs(a[i]-b6)
print(min(ans5, ans6))


Measured memory_bytes: 26608
using System;

namespace ABC170B
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = Console.ReadLine().Trim().Split(' ');
            int X = int.Parse(t[0]);
            int Y = int.Parse(t[1]);
            bool f = false;
            for(int i=0;i<101;i++){
                if(i*2+(X-i)*4 == Y && X-i >=0 ) {f = true; break;}
            }
            if(f) Console.WriteLine("Yes"); else  Console.WriteLine("No"); 
        }
    }
}


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

int main() {

  int N, P;
  cin >> N >> P;

  string S;
  cin >> S;

  // Pが2か5の場合
  if (P == 2 || P == 5) {
    long long answer = 0;
    for (int i = 0; i < N; i++) {
      if ((S[i] - '0') % P == 0) {
        answer += i + 1;
      }
    }
    cout << answer << endl;
    return 0;
  }

  // Pが2か5以外の場合
  vector<int> d(N+1);
  int count = 1;
  for (int i = N-1; 0 <= i; i--) {
    int a = (S[i] - '0') * count % P;
    d[i] = (d[i+1] + a) % P;
    count *= 10;
    count %= P;
  }

  vector<int> sum(P);
  long long answer = 0;
  for (int i = 0; i < N+1; i++) {
    answer += sum[d[i]];
    sum[d[i]]++;
  }

  cout << answer << endl;

  return 0;

}


Measured memory_bytes: 1412
#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 reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  string x;
  cin >> n >> x;
  int origin_pc = 0;
  rep(i, n) if (x[i] == '1') origin_pc++;

  int one_pc = origin_pc - 1;
  int zero_pc = origin_pc + 1;
  int one_mod = 0;
  int zero_mod = 0;
  
  rep(i, n) {
    if (one_pc > 0) {
      one_mod = (one_mod * 2 + (x[i] - '0')) % one_pc;  
    }
    zero_mod = (zero_mod * 2 + (x[i] - '0')) % zero_pc;
  }
  int mx = 2e5;
  vector<int> pcs(mx+1, 0);
  vector<int> f(mx+1, 0);
  f[1] = 1;
  reps(i, 1, mx+1) {
    pcs[i] = pcs[i/2] + i % 2;
    f[i] = f[i%pcs[i]] + 1;
  }
  vector<int> one_pow2_mod(mx+1, 1);
  vector<int> zero_pow2_mod(mx+1, 1);
  reps(i, 1, mx+1) {
    if (one_pc > 0) {
      one_pow2_mod[i] = one_pow2_mod[i-1]*2%one_pc;
    }
    zero_pow2_mod[i] = zero_pow2_mod[i-1]*2%zero_pc;
  }  
  rep(i, n) {
    if (x[i] == '1') {
      if (one_pc > 0) {
        int v;
        v = one_mod;
        // todo
        v -= one_pow2_mod[n-1-i];
        v += one_pc;
        v %= one_pc;
        cout << f[v] + 1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      int v;
      v = zero_mod;
      v += zero_pow2_mod[n-1-i];
      v %= zero_pc;
      cout << f[v] + 1 << endl;
    }
  }
  
  
  return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define rep1(i, n)    for(ll i = 1; i <= (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define bpc(a) __builtin_popcount(a)
#define ff first 
#define ss second  
#define mk0(a) memset(a,0,sizeof(a))
#define mk_1(a) memset(a,-1,sizeof(a))

const ll MAX=1e5+2;
const ll MAX1=1e2+5;
const ll INF=1e15+2;
const ll MOD=1e9+7;

#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi pair<ll,ll>
#define map1 unordered_map

inline ll nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}

inline ll read(){ll ret=0;bool f=0;char ch=nc();while(ch>'9'|| ch<'0') f^=ch=='-',ch=nc();
while(ch<='9'&& ch>='0') ret=ret*10+ch-'0',ch=nc();return f?-ret:ret;}

ll power(ll base,ll ind,ll mod){ll res=1;while(ind){if(ind&1)res=(res*base)%mod;base=(base*base)%mod;ind>>=1;}return res;}

ll inv(ll den,ll mod){return power(den,mod-2,mod);}

ll dp[405][405];
ll a[405];

ll cost(ll l,ll r)
{
    ll sum=0;
    for(int i=l;i<=r;i++)
        sum+=a[i];
    return sum;    
}

int main()
{
    faster;
    ll n;
    cin>>n;
    
    rep(i,n)
        cin>>a[i];
    
    for(ll L=n-1;L>=0;L--)
    {
        for(ll R=L;R<n;R++)
        {
            if(L==R)
            {
                dp[L][R]=0;
                continue;
            }    
            dp[L][R]=INF;
            for(ll i=L;i<=R-1;i++)
            {
                dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+cost(L,R));
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    
}

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

int main() {
    int n, S;
    while (cin >> n >> S) {
        if (n == 0 && S == 0) break;
        vector<int> m(n);
        for (int i = 0; i < n; i++) {
            cin >> m[i];
        }

        sort(m.begin(), m.end());

        int cnt = 0;
        for (vector<int>::iterator it = m.begin(); it != m.end(); it++) {
            vector<int>::iterator partner = upper_bound(it+1, m.end(), S - *it);
           if (partner == m.end()) continue;
            cnt += m.end() - partner;
        }

        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 944
N=int(input())
import math
 
# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False
 
    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False
 
    # 素数
    return True
 
# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)
 
    # 素数配列を返す
    return numbers
 
# 関数の呼び出し
 
P=callIsPrime(int(math.sqrt(N))+1)
#print(P)
ans=0
#ans+=isPrime(N)
for i in P:
  count=1
  #print(i)
  while(N%(i**count)==0):
    ans+=1
    N=N//(i**count)
    #print(i**count)
    count+=1
  while(N%i==0):
    N=N//i
ans+=isPrime(N)
    
 
#print(make_divisors(N))
#print(N)
print(ans)  

Measured memory_bytes: 78400
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

vector<string> key;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	string q;
	getline(cin,q);
	string s;
	rep(i,sz(q)+1){
		if(i==sz(q) || q[i]=='.'){
			if(i)key.pb(s);
			s="";
		}else s+=q[i];
	}
	int cur=0,indent=0;
	int wait=0;
	while(getline(cin,s)){
		int space=0;
		while(space<sz(s) && s[space]==' ')space++;
		if(wait==1){
			indent=space;
			wait=0;
		}
		if(space < indent){
			break;
		}
		if(space > indent){
			continue;
		}
		int colon=s.find(":");
		string t=s.substr(indent,colon-indent);
		if(t!=key[cur]){
			continue;
		}
		if(colon==sz(s)-1){
			if(cur==sz(key)-1){
				cout<<"object"<<endl;
				return 0;
			}
			else cur++,wait=1;
		}
		else{
			if(cur==sz(key)-1){
				cout<<"string \""<<s.substr(colon+2)<<"\""<<endl;
				return 0;
			}
			else break;
		}
	}
	cout<<"no such property"<<endl;
}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a != b && b != c && a != c){
		cout << 3 << endl;
	}
	else if (a == b && b == c){
		cout << 1 << endl;
	}
	else {
		cout << 2 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int INF = 1e6;
  vector<int> dp(N+1, INF);
  dp[0] = 0;
  for(int i = 1; i <= N; i++){
    int six = 6, nine = 9;
    dp[i] = min(dp[i], dp[i-1] + 1);
    while(i >= six){
      dp[i] = min(dp[i], dp[i-six] + 1);
      six *= 6;
    }
    while(i >= nine){
      dp[i] = min(dp[i], dp[i-nine] + 1);
      nine *= 9;
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map(String::toInt)

    var health = 0
    for (i in 0 until n - 1) {
        for (j in i + 1 until n) {
            health += d[i] * d[j]
        }
    }
    println(health)
}

Measured memory_bytes: 37940
import java.util.*;
import static java.lang.System.out;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        out.print(a.charAt(0));
        out.print(b.charAt(1));
        out.print(c.charAt(2));

    }
}

Measured memory_bytes: 21584