akhauriyash/Code-Regression huggingface dataset:
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<i32>();
    let m=read::<i32>();
    let a=(0..2*m).map(|_|read::<i32>()).collect::<Vec<i32>>();
    for i in 1..n+1{
        let mut c=0;
        for j in a.iter(){
            if i==*j{c+=1}
        }
        println!("{}",c);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n; string s;
  cin>>n>>s;
  int k=n/2;
  if(n%2==0 && s.substr(0,k)==s.substr(k,k)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N, M = map(int, input().split())
X = np.array([int(i) for i in input().split()])

X.sort()
dX = np.array([X[i+1] - X[i] for i in range(len(X) - 1)])

argsrt = np.argsort(dX)[::-1][:N-1]
idxes = sorted(argsrt)

def calc(l):
    if len(l) == 1:
        return 0

    return l[len(l) - 1] - l[0]

s = 0
last_idx = 0
for i in idxes:
    s += calc(X[last_idx:i+1])
    last_idx = i + 1

s += calc(X[last_idx:])

print(s)


Measured memory_bytes: 23024
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); itr++)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); itr++)
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200001
const string alpha = "abcdefghijklmnopqrstuvwxyz";

signed main() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	fast
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	loop(i, n)	cin >> a[i];
	vector<ll> dp(n, 0);
	FOR(i, 1, n - 1)
	{
		dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
		for (ll j = i - 2; j >= max(i - k, ll(0)); j--)
		{
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1] << END;
//#ifndef ONLINE_JUDGE
//	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
//#endif
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <math.h>
#include <algorithm>
#define pii pair<int, int>

using namespace std;

int niz[100010], dp[100010];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> niz[i];
	for (int i = 1; i <= n; i++)
		dp[i] = 1000000000;
	dp[1] = abs(niz[1] - niz[0]);
	for (int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i], dp[i - 1] + abs(niz[i] - niz[i - 1]));
		dp[i] = min(dp[i], dp[i - 2] + abs(niz[i] - niz[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

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

int main( void )
{
    char b;
    cin >> b;
    if ( b == 'A' )
    {
        cout << 'T' << endl;
    }
    else if ( b == 'T' )
    {
        cout << 'A' << endl;
    }
    else if ( b == 'C' )
    {
        cout << 'G' << endl;
    }
    else
    {
        cout << 'C' << endl;
    }

    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    set<int> mochis;
    rep(i, n) {
        int d;
        cin >> d;
        mochis.insert(d);
    }

    cout << mochis.size() << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
import java.awt.geom.Line2D.Double;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			double[] x = new double[2*n];
			double[] y = new double[2*n];
			Line2D.Double[] cross = new Line2D.Double[n];
			Line2D.Double p = new Line2D.Double();
			double[][] cost = new double[2*n][2*n];
			for(int i=0;i<2*n;i++) Arrays.fill(cost[i], Integer.MAX_VALUE);
			
			int cnt = 1;
			
			double xa = sc.nextDouble();
			double ya = sc.nextDouble();
			double ra = sc.nextDouble();
			double xb = 0;
			double yb = 0;
			double rb = 0;
			double x1 = 0;
			double x2 = 0;
			double y1 = 0;
			double y2 = 0;
			double a, b, c, A, B, C;
			
			x[0] = xa;
			y[0] = ya;
			for(int i=1;i<n;i++){
				xb = sc.nextDouble();
				yb = sc.nextDouble();
				rb = sc.nextDouble();
				
				A = xa-xb;
				B = ya-yb;
				C = (A*xa+A*xb+B*ya+B*yb+rb*rb-ra*ra)/2;
				if(A==0){
					c = (C/B-ya)*(C/B-ya)+xa*xa-ra*ra;
					x1 = xa+Math.sqrt(xa*xa-c);
					x2 = xa-Math.sqrt(xa*xa-c);
					y1 = C/B;
					y2 = C/B;
				}else if(B==0){
					c = (C/A-xa)*(C/A-xa)+ya*ya-ra*ra;
					y1 = ya+Math.sqrt(ya*ya-c);
					y2 = ya-Math.sqrt(ya*ya-c);
					x1 = C/A;
					x2 = C/A;
				}else{
					a = 1+(A*A)/(B*B);
					b = (2*A*ya*B-2*A*C-2*xa*B*B)/(B*B);
					c = (C/B-ya)*(C/B-ya)+xa*xa-ra*ra;
					x1 = (-b+Math.sqrt(b*b-4*a*c))/(2*a);
					x2 = (-b-Math.sqrt(b*b-4*a*c))/(2*a);
					y1 = (C-A*x1)/B;
					y2 = (C-A*x2)/B;
				}
				
				x[cnt] = x1;
				y[cnt] = y1;
				cnt++;
				x[cnt] = x2;
				y[cnt] = y2;
				cnt++;
				cross[i] = new Line2D.Double(x1,y1,x2,y2);
				
				xa = xb;
				ya = yb;
				ra = rb;
			}
			x[cnt] = xb;
			y[cnt] = yb;
			
			boolean flag;
			for(int i=0;i<2*n;i++){
				for(int j=i+1;j<2*n;j++){
					flag = false;
					p.setLine(x[i], y[i], x[j], y[j]);
					for(int k=(i+1)/2;k<(j+1)/2;k++){
						if(k!=0 && p.intersectsLine(cross[k])==false){
							flag = true;
							break;
						}
					}
					if(flag==false){
						cost[i][j] = Math.sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
					}
				}
			}
			
			for(int i=0;i<2*n;i++) cost[i][i] = 0;
			for(int i=0;i<2*n;i++){
				for(int j=0;j<2*n;j++){
					for(int k=0;k<2*n;k++){
						if(cost[j][i]!=Integer.MAX_VALUE && cost[i][k]!=Integer.MAX_VALUE){
							cost[j][k] = Math.min(cost[j][k], cost[j][i]+cost[i][k]);
						}
					}
				}
			}
			System.out.println(cost[0][2*n-1]);
		}	
	}	
}

Measured memory_bytes: 52704
c = [0]*3
for i in range(3):
    c[i] = list(map(int,input().split(" ")))

for i in range(2):
    if not(c[0][i+1] - c[0][i] == c[1][i+1] - c[1][i] == c[2][i+1] - c[2][i]):
        print("No")
        exit()
    if not(c[i+1][0] - c[i][0] == c[i+1][1] - c[i][1] == c[i+1][2] - c[i][2]):
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

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 (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll dp[2][1 << 21];
bool A[21][21];
int main() {
    init();
    ll N;
    cin >> N;
    rep(i, N) rep(j, N) cin >> A[i][j];
    dp[0][0] = 1;
    bool now = 0, to = 1;
    rep(i,N){
        rep(bit,1<<N){
            if(dp[now][bit])rep(j,N){
                if (!(bit & 1 << j) and A[i][j]) dp[to][bit | 1 << j] += dp[now][bit];
            }
        }
        rep(bit, 1 << N) dp[to][bit] %= MOD, dp[now][bit] = 0;
        swap(now, to);
    }
    // rep(i,2) verr(dp[i], 1 << N);
    cout << dp[N % 2][(1 << N) - 1] << endl;
}

Measured memory_bytes: 33024
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)

int main(){
  int n;cin>>n;
  vs s(n);
  fr(i,n) cin >> s[i];
  map<string, ll> cnt;
  ll ans = 0;
  for(auto x:s){
    sort(x);
    ans += cnt[x];
    cnt[x]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 18176
import math
N = int(input())
if N < 357:
    print(0)
else:
    k = 1
    ans = 0
    while(10**k < N):
        k += 1
    
    nums=set()
    for i in range(1,4**k):
      num=0
      flag=[False,False,False,False]
      for j in range(k):
        tmp= (i // (4**j))%4
       
        if flag[3] and tmp<3:
          flag[tmp-1]=False
            
          break
        else:
          flag[tmp-1]=True
          
        if tmp==1:
          num+=3*(10**j)
        elif tmp==2:
          num+=5*(10**j)
        elif tmp==3:
          num+=7*(10**j)
        else:
          if j<3:
            break    
      
      #print(num,flag)
      for i in range(3):
        if flag[i]:
          if i == 2 and num<=N:
            nums.add(num)
        else:
          break
    forbidden=set()
    for x in nums:
      x=str(x)
      if "0" in x:
        forbidden.add(x)
    print(len(nums)-len(forbidden))


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
// #define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
    ll n; 
    cin >> n;
    cout << (1000 - (n % 1000))%1000 << endl;
	return 0;
} 
// 1 2 3 4 6 12
// 0	1	2	3	4	5	6	7	8	9	10
// -	(	(	(	)	)	)	)	)	)	-
// 0	1	1	1	1	1	1	0	0	0	0
// 0	1	2	3	3	3	3	3	3	3	3
// 0	0	0	0	1	2	3	3	3	3	3
// 0	0	1	2	3	3	3	3	3	3	3



// 6 - 
// 5 - a
// 0 - ababba
// 2 - abba
// 4 - ba
// 1 - babba
// 3 - bba


// -$a
// -aa
// -aa
// -aa
// -a$

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

long long N, a[202020], b[202020], A = 9223372036854775707, P[4];

int main(){
  scanf("%lld", &N);
  for(int i = 0; i < N; ++i)scanf("%lld", a + i);
  partial_sum(a, a + N, b);
  P[0] = a[0];
  P[1] = a[1];
  P[2] = a[2];
  P[3] = b[N - 1] - b[2];
  for(int i = 0, j = 1, k = 2; j < N - 1; ++j, P[1] += a[j], P[2] -= a[j]){
    while(i < j - 1 && P[0] + a[i + 1] < P[1]){
      ++i;
      P[0] += a[i];
      P[1] -= a[i];
    }
    if(j == k){
      ++k;
      P[2] += a[k];
      P[3] -= a[k];
    }
    while(k < N - 1 && P[2] + a[k + 1] < P[3]){
      ++k;
      P[2] += a[k];
      P[3] -= a[k];
    }
    A = min(A, *max_element(P, P + 4) - *min_element(P, P + 4));
  }
  cout << A << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll  A, B ;
    cin >> A >> B;
    cout << (A-1) * (B-1) << endl ;
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int k;

ll qpow(ll a, ll b, ll modd) {
    ll ans = 1, base = a;
    while (b) {
        if (b & 1) ans = ans * base % modd;
        b >>= 1, base = base * base % modd;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> k;
    if (k % 2 == 0 || k % 5 == 0) cout << -1, exit(0);
    for (int i = 1; i <= 1e8; i++) {
        if (7 * (qpow(10, i, 9 * k) - 1) % (9 * k) == 0) {
            cout << i;
            exit(0);
        }
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 3652
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct StronglyConnectedComponents
{
  int n;
  vector<vector<int>> oG, rG;
  vector<int> comp, order, used;
  vector<pair<int, int>> edges;

  StronglyConnectedComponents (int n) : n(n), oG(n), rG(n), comp(n, -1), used(n, 0) {}

  int operator[] (int k)
  {
    return comp[k];
  }

  void add_edge(int u, int v)
  {
    oG[u].push_back(v);
    rG[v].push_back(u);
    edges.emplace_back(u, v);
  }

  void dfs(int v)
  {
    if (used[v]) return;
    used[v] = true;
    for (int to : oG[v]) dfs(to);
    order.push_back(v);
  }

  void rdfs(int v, int k)
  {
    if (~comp[v]) return;
    comp[v] = k;
    for (int to : rG[v]) rdfs(to, k);
  }

  void build(vector<vector<int>> &t)
  {
    for (int i = 0; i < n; ++i) dfs(i);

    reverse(order.begin(), order.end());
    int k = 0;
    for (int i : order) if (comp[i] == -1) rdfs(i, k++);

    t.resize(k);
    set<pair<int, int>> connect;
    for (auto &e : edges) {
      int u = comp[e.first], v = comp[e.second];
      if (u == v || connect.count({u, v})) continue;
      t[u].push_back(v);
      connect.emplace(u, v);
    }
  }
};

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

  StronglyConnectedComponents scc(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    scc.add_edge(u, v);
  }

  vector<vector<int>> G;
  scc.build(G);

  int q;
  cin >> q;
  while (q--) {
    int s, t;
    cin >> s >> t;
    cout << (scc[s] == scc[t]) << endl;
  }
}

Measured memory_bytes: 4652
#include <stdio.h>
#include <vector>
using namespace std;

int main(void) {
  int i, j, k, n, m, l;
  scanf("%d%d", &n, &m);
  int uf[n];
  vector<int> vec[m];
  for(i = 0; i < n; ++i) {
    uf[i] = i;
    scanf("%d", &k);
    for(j = 0; j < k; ++j) scanf("%d", &l), vec[--l].push_back(i);
  }
  for(i = 0; i < m; ++i) {
    for(j = 1; j < vec[i].size(); ++j) {
      int ra = 0, rb = 0, na = vec[i][0], nb = vec[i][j];
      while(uf[na] != na) ra++, na = uf[na];
      while(uf[nb] != nb) rb++, nb = uf[nb];
      if(ra > rb) uf[nb] = na;
      else uf[na] = nb;
    }
  }
  for(i = 0; i < n; ++i) {
    int na = i;
    while(uf[na] != na) na = uf[na];
    uf[i] = na;
  }
  for(i = 1; i < n; ++i) if(uf[i] != uf[0]) {
    printf("NO");
    return 0;
  }
  printf("YES");
  return 0;
}

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

using namespace std;

int main(){

	long long n,tot;
   cin>>n>>tot;
   long long val[n];
   long long w[n];
   long long i,j;
   for(i=0;i<n;i++){
    cin>>w[i];
    cin>>val[i];
   }
   long long ans=0;
   long long dp[tot+1][2];
   memset(dp,0,sizeof(dp));
   if(w[0]<=tot) {dp[w[0]][0]=val[0];ans=val[0];}
   for(i=1;i<n;i++){
    for(j=1;j<=tot;j++){
        int l=i%2;
        long long a=0,b=0;
        a=dp[j][abs(1-l)];
        if(w[i]<=j) b=dp[j-w[i]][abs(1-l)]+val[i];
        dp[j][l]=max(a,b);
        ans=max(ans,dp[j][l]);
    }
   }
   cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
package main

import (
  "fmt"
)

func main() {
  var n, a int
  fmt.Scan(&n, &a)
  for x := 0; x <= n; x++ {
    for y := 0; y <= n-x; y++ {
      z := n - (x + y)
      if x*10000+y*5000+z*1000 == a {
        fmt.Println(x, y, z)
        return
      }
    }
  }
  fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
/*  ex4_3
    L40S38  */
#include<stdio.h>
int snow(int a, int b);
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    //a:西側の塔の雪に埋もれていない部分の高さ　
    //b:東側の塔の雪に埋もれていない部分の高さ
    printf("%d",snow(a,b));
}

int snow(int a, int b){
    int d=b-a;
    int h=d*(d+1)/2;
    //h:東側の塔の本当の高さ
    return(h-b);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;cin >> n;
	vector<int> v;
	REP(i,n)
	{
		int tmp;cin >> tmp;tmp--;v.PB(tmp);
	}
	int ans = 0;
	REP(i,n)
	{
		if(v[v[i]] == i)ans++;
	}
	
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 892
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int h,w;
	while(cin>>h>>w,h){
		vector<pii> v(w,pii(0,0));
		rep(i,w) v[i].S=i;
		rep(i,h){
			rep(j,w){
				int t;
				cin>>t;
				v[j].F-=t;
			}
		}
		sort(ALL(v));
		rep(i,w){
			if(i) cout<<" ";
			cout<<v[i].S+1;
		}
		cout<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define con continue

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool isPerfectSquare(ll x) {   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
} 
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
bool cmp(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff); 
}
//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////

void solve()
{
    
    ll n;
    cin>>n;

    map<string , ll> m;

    loop(i,0,n)
    {
        string s; 
        cin>>s; 
        m[s]++;
    }

    cout<<m.size();

    return;
}
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 19260
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;

int main() {
	string s, str;
	cin >> s;
	str = 'I' + s + 'J';
	
	int cnt, max = 0;
	bool jok, iok;

	FOR(i, 1, s.size()) {
		cnt = 0;
		jok = iok = false;
		while(str[i] == 'O') {
			jok = iok = true;
			i++;
			cnt++;
		}
		REP(j, cnt) {
			if(str[i+j] != 'I') {
				iok = false;
				break;
			}
		}
		REP(j, cnt) {
			if(str[i-cnt-j-1] != 'J') {
				jok = false;
				break;
			}
		}

		if(jok && iok && cnt > max) {
			max = cnt;
		}
	}

	cout << max << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<bool> hy(n, true);
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        if(h[a] > h[b]) {
            // if(hy[a])hy[a] = true;
            hy[b] = false;
        }
        else if(h[a] == h[b]) {
            hy[a] = false;
            hy[b] = false;
        }
        else {
            // if(!hy[b])hy[b] = true;
            hy[a] = false;
        }
    }
    int count = 0;
    rep(i, n) if(hy[i]) count++;
    cout << count << endl;
}

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

#define MAX_H 102

int h[MAX_H];

void decrement(int l, int r, int count) {
	if (!h[l])
		return;
	for (int i = l; i < r; i++) {
		h[i] -= count;
	}
}

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	int left = 0, right = N;
	int sum = 0;
	for (; left != N;) {
		sum++;
		for (int i = left; i < N; i++) {
			if (!h[i] && i == left) {
				left = i+1;
				if (left == N)
					sum--;
				continue;
			}
			if (!h[i])
				break;
			h[i]--;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> x(N),y(N);
  for(int i=0;i<N;++i){
    cin >> x[i];
  }
  for(int i=0;i<N;++i){
    cin >> y[i];
  }
  int ans = 0;
  for(int i=0;i<N;++i){
    ans += max(0,x[i]-y[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    string s, t;
    scan(s, t);
    print(t + s);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  
  string S, T;
  cin >> S >> T;
  
  int ans = 0;
  for(int i=0; i<3; i++)
  {
    if(S[i] == T[i]) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N= 1e2+5;
int n,a[N];
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",&a[i]);
  sort(a+1,a+1+n);
  int ret=0x3f3f3f3f;
  for(int i=a[1];i<=a[n];++i){
    int tmp=0;
    for(int j=1;j<=n;++j)
      tmp+=(i-a[j])*(i-a[j]);
    ret=min(ret,tmp);
  }
  printf("%d\n",ret); 
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define int long long
using std::max;
const int mod=1000000007;
int n,m,s[3010],right[3010];
int x,y,f[3010][3010];
char S[3010];
signed main(){
	scanf("%lld%lld",&n,&m);
	scanf("%s",S+1);
	for(int i=1;i<=n;i++)
		s[i]=S[i]-'0';
	for(int i=1;i<=n+1;i++)
		s[i]+=s[i-1];
	for(int i=1;i<=n+1;i++)
		right[i]=i;
	for(int i=1;i<=m;i++){
		scanf("%lld%lld",&x,&y);
		right[x]=max(right[x],y);
	}
	for(int i=1;i<=n;i++)
		right[i]=max(right[i],right[i-1]);
	f[1][s[right[1]]]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=n;j++)
			if(f[i][j]){
				int l=right[i]+1,r=right[i+1];
				int bo1=j,bo2=right[i]-i+1-j;
				if(bo2)(f[i+1][j+s[r]-s[l-1]]+=f[i][j])%=mod;
				if(bo1)(f[i+1][j-1+s[r]-s[l-1]]+=f[i][j])%=mod;
			}
	printf("%lld\n",f[n+1][0]);
}

Measured memory_bytes: 68352
#include <bits/stdc++.h>
using namespace std;
//actual solution is at bottom//
////<pbds>////
/*OPTIONAL
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, 
    rb_tree_tag, tree_order_statistics_node_update>; 
// change null_type for map
#define ook order_of_key
#define fbo find_by_order
*/
///</pbds>///

#define int long long int
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()

///<constants>///
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; 
const ll INF = 1e18; 
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0};
///</constants>///

///<IO>/// 
namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        // cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}
 
using namespace io;
///</IO>///

///<execution-time>///
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
/*example for clock usage
    clock_t z = clock();
    debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
*/
///</execution-time>///

inline void google(int i){
    cout<<"Case #"<<i<<" :";
}
signed main(){
    setIO("");
    int n;cin>>n;
    int d[n][2];

    for(int i=0;i<n;i++){
    	cin>>d[i][0]>>d[i][1];
    }
    for(int i=0;i<n-2;i++){
    	if(d[i][0]==d[i][1]&&d[i+1][0]==d[i+1][1]&&d[i+2][0]==d[i+2][1])
    	{
    		cout<<"Yes\n";
    		exit(0);
    	}
    }
cout<<"No\n";
    return 0;
}
/* stuff you should look for
    * check whether you have read the problem correctly
    * int overflow, array bounds
    * special cases (n=1?), slow multiset operations
    * do smth instead of nothing and stay organized
*/

Measured memory_bytes: 3652
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long range = b - a + 1;
        long cMultiple = Math.floorDiv(b, c) - Math.floorDiv(a - 1, c);
        long dMultiple = Math.floorDiv(b, d) - Math.floorDiv(a - 1, d);

        long chohuku = lcm(c , d);

        long cdMultiple = Math.floorDiv(b, chohuku) - Math.floorDiv(a - 1, chohuku);

        System.out.println(range - (cMultiple + dMultiple - cdMultiple));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 22100
#include<stdio.h>

int main(void)
{
	int i, sum=0;
	char a[5];
	
	scanf("%s", a);
	
	for(i=0; i<4; i++){
		if(a[i] =='+'){
			sum++;
		}else if(a[i] == '-'){
			sum--;
		}
	}
	
	printf("%d", sum);
	
	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
requests = []
for _ in range(M):
    a, b = map(int, input().split())
    requests.append((a, b))
requests.sort(key=lambda x: x[1])
ans = 0
cut_point = -1
for a, b in requests:
    if cut_point >= a:
        continue
    else:
        cut_point = b-1
        ans += 1
print(ans)


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

#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
#define DEBUG(x) cerr << #x << " = " << x << endl

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

ll f(ll N, ll X) {
	if (N <= 1 || X == 0 || X == N) return 0;
	if (X + X >= N) {
		return f(X, N - X) + 3 * (N - X);
	}
	else {
		ll k = N / X - 1;
		return f(N - k * X, X) + 3 * k * X;
	}
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	ll N, X;

	cin >> N >> X;
	cout << f(N, X) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();

    Map<Integer, List<Integer>> f = new HashMap<>();
    for (int i = 0; i < M; i++) {
      Integer a = Integer.valueOf(A[i]);
      Integer b = Integer.valueOf(B[i]);
      if (!f.containsKey(a)) f.put(a, new ArrayList<>());
      if (!f.containsKey(b)) f.put(b, new ArrayList<>());
      f.get(a).add(b);
      f.get(b).add(a);
    }

    int[] gn = new int[N + 1];
    int[] gc = new int[N + 1];
    for (int i = 1; i < N + 1; i++) {
      Deque<Integer> q = new ArrayDeque<>();
      q.addLast(i);
      while (!q.isEmpty()) {
        int n = q.pollLast();
        if (gn[n] != 0) continue;
        gn[n] = i;
        gc[i]++;
        q.addAll(f.getOrDefault(n, Collections.emptyList()));
      }
    }

    int[] bc = new int[N + 1];
    for (int i = 0; i < K; i++) {
      int c = C[i];
      int d = D[i];
      if (gn[c] == gn[d]) {
        bc[c]++;
        bc[d]++;
      }
    }

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++)
      ans[i] = gc[gn[i]] - 1
          - f.getOrDefault(i, Collections.emptyList()).size()
          - bc[i];

    for (int i = 1; i < N + 1; i++)
      System.out.print(ans[i] + " ");
    System.out.println();
  }
}

Measured memory_bytes: 122676
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll  long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
int main()
{
    ll int n,ans=1;
    int flag=1;
    cin >> n;
    // if(n==0)
    // cout << 0;
    std::vector<int>A(n);
    for(int i=0;i<n;i++)
    cin >> A[i];
    // if(n==0&&A[0])
    sort(A.begin(),A.end());
    if(n%2)
    {
        if(A[0]!=0)
        flag=0;
        for(int i=1;i<n;i+=2)
        {
            if(!(A[i]==A[i+1]&&A[i]==(i+1)))
            flag=0;
        }
        n /=2;
        for(int i=1;i<=n;i++)
        {
            ans *=2;
            ans %=mod;
        }
    }
    else 
    {
        for(int i=0;i<n;i+=2)
        {
            if(!(A[i]==A[i+1]&&A[i]==(i+1)))
            flag = 0;
        }
        n /=2;
        for(int i=1;i<=n;i++)
        {
            // ans = (ans*2)%mod;
            ans *=2;
            ans %=mod;
        }
    }
    if(flag)
    cout << ans;
    else
    cout << 0;
    // cout << 1e9+7;
}

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

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    if(x % y == 0)
        printf("-1\n");
    else
        printf("%lld\n", (LL) x * (LL) (y - 1));
    return 0;
}


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

int main() {
  int W,H,N;
  cin >> W>>H>>N;
  vector<vector<int>> square(W, vector<int>(H));
  vector<vector<int>> data(N, vector<int>(3));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++) cin >> data[i][j];
    }

  for(int i=0;i<N;i++){
  if(data[i][2]==1){
    for(int j=0;j<data[i][0];j++){
      for(int k=0;k<H;k++){
        square[j][k]=1;
      }
    }
  }
  if(data[i][2]==2){
    for(int j=data[i][0];j<W;j++){
      for(int k=0;k<H;k++){
        square[j][k]=1;
      }
    }
  }
  if(data[i][2]==3){
    for(int j=0;j<W;j++){
      for(int k=0;k<data[i][1];k++){
        square[j][k]=1;
      }
    }
  }
  if(data[i][2]==4){
    for(int j=0;j<W;j++){
      for(int k=data[i][1];k<H;k++){
        square[j][k]=1;
      }
    }
  }
  }
  int s=0;
  for(int i=0;i<W;i++){
    for(int j=0;j<H;j++){
      if(square[i][j]==0) s++;
      //cout << square[i][j];
    }
    //cout << endl;
  }
cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  string s=to_string(a);
  string t=to_string(b);
 
  string u;
  string v;
  for(int i=0; i<b; i++){
    u = u + s;
  }
  
  for(int j=0; j<a; j++){
    v = v + t;
  }
  
  if(a<b){
    cout << u << endl;
  }
  else{
    cout << v << endl;
  }
  
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N=int(input())
MAT=[list(map(int,input().split())) for i in range(N)]

POINT=[0]*(1<<N)

for i in range(1,1<<N):
    for j in range(16):
        if i & (1<<j)!=0:
            break

    ANS=POINT[i-(i & (1<<j))]

    for k in range(16):
        if i & (1<<k)!=0:
            ANS+=MAT[k][j]

    POINT[i]=ANS
        
DPLIST=[0]*((1<<N)+1)#使った集合Sに対して,DP[S]でその総得点のmax.
#Sを部分集合として含む全てのT（次に使うグループ）へ遷移.（これがO(3^n））

for i in range(1<<N):
    k=i
    while k<(1<<N):
        DPLIST[k]=max(DPLIST[k],DPLIST[i]+POINT[k-i])
        k=(k+1)|i


print(DPLIST[(1<<N)-1])

Measured memory_bytes: 45864
if __name__ == '__main__':
    s = input()
    t = input()
    min_diff = len(t)
    for i in range(len(s)-len(t)+1):
        diff = len(t)
        for j in range(len(t)):
            if s[i+j] == t[j]:
                diff -= 1
        min_diff = min(min_diff, diff)
    print(min_diff)


Measured memory_bytes: 67476
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const int MOD = 1e9+7;

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vecl cnt(26);
    for(char c : S) cnt[(int)c-'a']++;
    ll ans = 1;
    REP(i,26) {
        //Scout << cnt[i] << endl;
        if(cnt[i] > 0) {
            ans *= cnt[i]+1;
            ans %= MOD;
        }
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 3688
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
char mp[605][605];
int vis[30];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>mp[i];
    }
    for(int i=n;i<2*n;i++){
        strcpy(mp[i],mp[i-n]);
    }
    for(int i=0;i<2*n;i++){
        for(int j=n;j<2*n;j++){
            mp[i][j]=mp[i][j-n];
        }
    }
//    for(int i=0;i<n*2;i++){
//        for(int j=0;j<n*2;j++){
//            cout<<mp[i][j];
//        }
//        cout<<endl;
//    }
    int ans=0;
    for(int x=0;x<n;x++){
            int flag=1;
            for(int i=0;i<n;i++){
                for(int j=0;j<i;j++){
                    if(mp[x+i][j]!=mp[x+j][i]){
                        flag=0;
                        break;
                    }
                }
                if(!flag) break;
            }
            if(flag) ans+=n;
    }
//    for(int x=0;x<n;x++){
//            int flag=1;
//            for(int i=0;i<n;i++){
//                for(int j=0;j<i;j++){
//                    if(mp[i][x+j]!=mp[j][x+i]){
//                        flag=0;
//                        break;
//                    }
//                }
//                if(!flag) break;
//            }
//            if(flag) ans++;
//        }
//    }
    cout<<ans<<endl;
return 0;}


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

using namespace std;

main(){
   int n;
   scanf("%d",&n);
   vector<int> A (n);
   vector<int> B (n);
   vector<int> C (n);
   for(int i=0;i<n;++i) scanf("%d",&A[i]);
   for(int i=0;i<n;++i) scanf("%d",&B[i]);
   for(int i=0;i<n;++i) scanf("%d",&C[i]);
   sort(A.begin(),A.end());
   sort(B.begin(),B.end());
   sort(C.begin(),C.end());
   vector<long long> DPB (n);
   long long counter = 0;
   for(int j=0;j<n;++j){
       vector<int>::iterator it = lower_bound (A.begin(), A.end(), B[j]);
       DPB[j] = (it-A.begin());
   }
   for(int i=1;i<n;++i) DPB[i] = DPB[i-1] + DPB[i];
   for(int i=0;i<n;++i){
       vector<int>::iterator it = lower_bound (B.begin(), B.end(), C[i]);
       if((it-B.begin()-1) >= 0){
        counter += DPB[(it-B.begin())-1];
       }
   }
   cout << counter << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,k;
    cin >> n >> k;
    int num[n];
    rep(i,n) cin >> num[i];
    for(int i=k;i<n;i++){
        if(num[i] > num[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4384
#include<iostream>
#include<vector>
#include<algorithm>
#include <functional>
#include<string>
using namespace std;struct k{string s;int n;};bool x(const k&left,const k&right){return left.n>right.n;}int main(){vector<k> t;k c;int n,i=0,w,d;string s;while(cin>>n,n){if(i)cout<<endl;t.clear();for(i=0;i++<n;){cin>>s>>w>>d>>d;c.s=s;c.n=3*w+d;t.push_back(c);}sort(t.begin(),t.end(),x);for(i=0;i<n;i++)cout<<t[i].s<<","<<t[i].n<<endl;}return 0;}

Measured memory_bytes: 0
//API???????????????
import java.util.Scanner;
import java.io.IOException;
class Main {
  	public static void main(String[] args) throws IOException{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		Nodes nodes = new Nodes();
		Node[] node = new Node[n];
		nodes.nodes = node;
		for(int i = 0;i < n;i++){
			node[i] = new Node(i);
		}
		int l = 0;
		for(int i = 0;i < n; i++){
			int id = scan.nextInt();
			int k = scan.nextInt();
			for(int j = 0;j < k; j++){
				int c = scan.nextInt();
				if(j == 0){
					node[id].left = c;
					l = c;
				}
				else{
					node[l].right = c;
					l = c;
				}
				node[c].parent = id;
			}
		}
		for(int j = 0;j < n; j++){
			System.out.print("node " + j + ": ");
			System.out.print("parent = " + node[j].parent + ", ");
			System.out.print("depth = " + nodes.getDepth(j) + ", ");
			
			if(node[j].parent == -1) System.out.print("root, ");
			else if(node[j].left == -1) System.out.print("leaf, ");
			else System.out.print("internal node, ");
			
			System.out.print("[");
			int c = node[j].left;
			while(c != -1){
				System.out.print(c);
				c = node[c].right;
				if(c != -1) System.out.print(", ");
			}
			System.out.println("]");
		}
	}
}

class Node{
	int id;
	int parent = -1;
	int left = -1;
	int right = -1;
	
	public Node(int id) {
		this.id = id;
	}
}

class Nodes{
	/*
	List<Node> nodes;
	/*/
	Node[] nodes;
	/**/
	public int getDepth(int id){
		int d = 0;
		int u = nodes[id].parent;
		while(u != -1){
			u = nodes[u].parent;
			d++;
		}
		return d;
	}

}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> pii;
typedef long long int ll;

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int a;

int main(){
  scanf("%d",&a);
  if(a<1200){
    printf("ABC\n");
    return 0;
  }
  printf("ARC\n");
}


Measured memory_bytes: 256