akhauriyash/Code-Regression huggingface dataset:
from sys import stdin


def get_result(data):
    N, K = data[0]
    A = data[1]
    trans_num = [0] * N
    curr_pos = 1
    arrival_pos = set()
    for i in range(N):
        trans_num[curr_pos-1] = i
        arrival_pos.add(curr_pos)

        # see next
        next_pos = A[curr_pos-1]
        if next_pos in arrival_pos:
            loop_start = trans_num[next_pos-1]
            loop_trans_num = i + 1 - loop_start
            break

        # update
        curr_pos = next_pos

    loop = 0
    # K が loop 開始より小さい可能性を忘れていた
    if (K - loop_start) > 0:
        loop = loop_start + (K - loop_start) % loop_trans_num
    else:
        loop = K
    curr_pos = 1
    for _ in range(loop):
        next_pos = A[curr_pos-1]
        curr_pos = next_pos
    return next_pos


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 37496
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a, b = geta(int)

    tot = 1
    ans = 0
    while tot < b:
        ans += 1
        tot += a - 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,K;
	while(cin>>N>>K) {
		VI m(N);
		REP(i, K) {
			ll d, a;
			cin>>d;
			REP(j, d) {
				cin>>a;
				a--;
				m[a]++;
			}
		}
		ll ans=count(ALL(m), 0LL);
		cout<<ans<<endl;
	}
	
	return 0;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = 998244353;

int pow(int a, int b, int m)
{
   int ans=1;
   while(b)
   {
      if(b&1)
         ans=(ans*a)%m;
      b/=2;
      a=(a*a)%m;
   }
   return ans;
}

int modinv(int k)
{
   return pow(k, MOD-2, MOD);
}

int32_t main(){
   fast;
   int n;
   cin >> n;
   int a[n],f[n] = {0};
   f(i,0,n) cin >> a[i] , f[a[i]]++;

   int ans = (f[0] == 1 && a[0] == 0);

   f(i,1,n){
      ans = (ans * pow(f[i-1] , f[i] , MOD)) % MOD;
   }
   cout << ans << "\n";
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);

		while (true) {
			int a =in.readInt();
			String op =in.read();
			if (op.equals("?")) break;
			int b =in.readInt();
			
			int ans = 0;
			switch (op) {
			case "+":
				ans = a + b ;
				break;
			case "-":
				ans = a - b ;
				break;		
			case "*":
				ans = a * b ;
				break;	
			case "/":
				ans = a / b ;
				break;	
			}
			System.out.println(ans);
		}
	}	
}

class InputReader{
	private BufferedReader br;
	private StringTokenizer buffer;
	
	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
	}
	
	public String read() throws IOException {
		while (buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return buffer.nextToken();
	}
	
	public int readInt() throws IOException {
		while (buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return Integer.parseInt(buffer.nextToken());
	}
	
	public double readDouble() throws IOException {
		while (buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return Double.parseDouble(buffer.nextToken());
	}	
}


Measured memory_bytes: 24332
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] HW = ReadLineParseIntArray();
        int H = HW[0];
        int W = HW[1];
        int[,] map = new int[H + 1, W + 1];

        for(int y = 1; y <= H; y++)
        {
            string s = ReadLine();
            for (int x = 1; x <= W; x++)
                map[y, x] = s[x - 1] == '.' ? 0 : -1;
        }
        map[1, 1] = 1;

        for(int y = 1; y <= H; y++)
        {
            for(int x = 1; x <= W; x++)
            {
                if (map[y, x] == -1)
                    continue;
                int upper = Max(map[y - 1, x], 0);
                int lefter = Max(map[y, x - 1], 0);
                map[y, x] = Max(map[y, x], (upper + lefter) % 1000000007);
            }
        }
        WriteLine(map[H, W]);
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

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

using namespace std;

typedef long long LL;

int N,M;
int col[100010];
vector<int>e[100010];
int cnt[3];

bool dfs(int x)
{
	cnt[col[x]]++;
	for (auto t:e[x])
	if (col[t])
	{
		if (col[t] == col[x]) return false;
	}
	else
	{
		col[t] = 3 - col[x];
		if (!dfs(t)) return false;
	}
	return true;
}

typedef long long LL;

int main()
{
	scanf("%d%d",&N,&M);
	for (int i=1;i<=M;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	col[1] = 1;
	long long ans = 0;
	if (dfs(1))
	{
		ans += LL(cnt[2]) * LL(cnt[1]);
		ans -= M;
	}
	else
	{
		ans += LL(N) * LL(N-1) / 2;
		ans -= M;
	}
	printf("%lld\n",ans);
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }


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

    int A, B, C;
    cin >> A >> B >>C;

    if(A+B < C){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n; int ans = 0;
  for (int i = 1; i <= n; i += 2){
    int cnt = 0;
    for (int j = 1; j <= i; j++){
      if (i % j == 0) cnt++;
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
  int a,b,c;cin >> a >> b >> c;
  vint diff={abs(a-b),abs(b-c),abs(c-a)};
  VSORT(diff);
  cout << diff[0]+diff[1] << endl;

  return 0;
}


Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
function f(A,B,T)
	N=length(A)
	for i=1:N
		@inbounds if A[i]>=2T
			@inbounds A[i]-=2T
		end
		@inbounds if B[i]>=2T
			@inbounds B[i]-=2T
		end
	end
	sort!(A)
	sort!(B)
	cnt=0
	i1=i2=i3=i4=1
	for a=reverse(A)
		@inbounds while i1<=N&&B[i1]<T-a
			i1+=1
		end
		@inbounds while i2<=N&&B[i2]<2T-a
			i2+=1
		end
		@inbounds while i3<=N&&B[i3]<3T-a
			i3+=1
		end
		@inbounds while i4<=N&&B[i4]<4T-a
			i4+=1
		end
		cnt+=i4-i3+i2-i1
	end
	cnt&1
end
function main()
	N=parse(Int,readline())
	A=map(parseInt,split(readline()))
	B=map(parseInt,split(readline()))
	ans=0
	for k=28:-1:0
		ans+=f(A,B,1<<k)*(1<<k)
	end
	println(ans)
end
main()


Measured memory_bytes: 164960
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, Z, W, A[2000];
    cin >> N >> Z >> W;
    REP(i, N) cin >> A[i];

    if (N == 1) cout << abs(A[0] - W) << endl;
    else cout << max(abs(A[N - 1] - W), abs(A[N - 2] - A[N - 1])) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int t;
    cin >> t;
    vector<ll> vec;
    vec.reserve(t);
    ll xorr = 0;
    while (t--)
    {
        ll k;
        cin >> k;
        xorr ^= k;
        vec.emplace_back(k);
    }
    for (auto &it : vec)
    {
        cout << (ll)(it xor xorr) << ' ';
    }
    cout << '\n';
}

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

int h,w,n;
inline int origin(int a, int b){
  int left = (a&1)==(b&1)?1:0;
  int rem = left?b:w-1-b;
  if(rem >= a)return left?rem-a:b+a;
  a -= rem;

  int rev = (a/w)&1;
  rem = a%w;
  if(left == 1-rev)return max(0,rem-1);
  else return min(w-1,w-rem);
}

int main(){
  scanf("%d%d%d",&h,&w,&n);
  vector< pair<int,int> > bars(n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&bars[i].first,&bars[i].second);
  }
  sort(bars.begin(),bars.end());

  vector<int> perm(w);
  for(int i=0;i<w;i++)perm[i] = i;

  for(int i=0;i<n;i++){
    int a = origin(bars[i].first-1, bars[i].second-1);
    int b = origin(bars[i].first-1, bars[i].second);
    swap(perm[a],perm[b]);
  }

  vector<int> inv_perm(w);
  for(int i=0;i<w;i++)inv_perm[perm[origin(h,i)]] = i;
  for(int i=0;i<w;i++)printf("%d\n",inv_perm[i]+1);
}

Measured memory_bytes: 4160
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	int N, M, K, i, j;
	scanf("%d %d %d", &N, &M, &K);
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= M; j++) {
			int c = i * (M - j) + j * (N - i);
			if (c == K) return !printf("Yes\n");
		}
	}
	return !printf("No\n");
}

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

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


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
K = int(input())

Ans = []
for k in range(5):
    for i in range(len(S)-k):
        s = S[i:i+k+1]
        if s not in Ans:
            Ans.append(s)

Ans.sort()
print(Ans[K-1])

Measured memory_bytes: 3956
import collections
n = int(input())
adj_list = []

for _ in range(n):
    adj = list(map(int, input().split(" ")))
    adj_list.append([c - 1 for c in adj[2:]])

distances = [-1 for _ in range(n)]
queue = collections.deque()
queue.append(0)
distances[0] = 0

while queue:
    p = queue.popleft()

    for next_p in adj_list[p]:
        if distances[next_p] == -1:
            distances[next_p] = distances[p] + 1
            queue.append(next_p)

for i in range(n):
    print(i+1, distances[i])


Measured memory_bytes: 6032
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();
    const MOD: i64 = 1000000007;

    let n = s.len();
    let mut dp = vec![vec![0; 13]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        if s[i] == '?' {
            for j in 0..13 {
                for k in 0..10 {
                    dp[i + 1][(10 * j + k) % 13] += dp[i][j];
                    dp[i + 1][(10 * j + k) % 13] %= MOD;
                }
            }
        } else {
            let d = (s[i] as u8 - b'0') as usize;
            for j in 0..13 {
                dp[i + 1][(10 * j + d) % 13] += dp[i][j];
                dp[i + 1][(10 * j + d) % 13] %= MOD;
            }
        }
    }

    println!("{}", dp[n][5]);
}


Measured memory_bytes: 18684
n,k,q = map(int,input().split())

a = [int(input()) for i in range(q)]
m = [k-q] * n

for c in a :
    m[c-1] += 1

for j in range(n) :
    if(m[j] > 0) :
        print('Yes')
    else :
        print('No')

Measured memory_bytes: 10452
#pragma GCC optimize("Ofast",3,"inline")
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans,cnt;
char c[10];
string s;
map<string,long long>mp;
string str[100010];
void input(){
	s="";
	for(int i=0;i<10;i++) cin>>c[i];
	sort(c,c+10);
	for(int i=0;i<10;i++) s+=c[i];
}
void turn(){
	mp[s]++;
	if(mp[s]==1) str[cnt++]=s; 
}
long long count(int k){
	long long num=mp[str[k]];
	if(num==1) return 0;
	return (num*(num-1))/2;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++){
		input();
		turn();
	}
	for(int i=0;i<cnt;i++)
		ans+=count(i);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 13568
s = gets.chomp.each_char.map {|x| x == '0' ? 0 : 1}

# 0101...
diff1 = 0
s.each_with_index do |x, i|
  if (i % 2 == 0) != (x == 0)
    diff1 += 1
  end
end

# 1010...
diff2 = 0
s.each_with_index do |x, i|
  if (i % 2 == 0) != (x == 1)
    diff2 += 1
  end
end

puts [diff1, diff2].min


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());
  cout << V.size();

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector< vector<int> > t(N + 1, vector<int>(N + 1));
		for (int i = 1; i <= N; i++)
			for (int j = 0; j <= N; j++) cin >> t[i][j];
		vector<int> dp(1 << (N + 1), INT_MAX);
		dp[1] = 0;
		for (int S = 1; S < (1 << (N + 1)); S += 2)
			for (int i = 1; i <= N; i++) {
				if (S & (1 << i)) continue;
				int mini = INT_MAX;
				for (int j = 0; j <= N; j++)
					if (S & (1 << j))
						mini = min(mini, t[i][j]);
				int T = S | (1 << i);
				dp[T] = min(dp[T], dp[S] + mini);
			}
		cout << dp[(1 << (N + 1)) - 1] << endl;
	}
}

Measured memory_bytes: 1732
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>

int main() {
	

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;

	return 0;
}

Measured memory_bytes: 256
# Palace
import sys

n = int(input())
t, a = map(int, input().split())
H = list(map(int, input().split()))
res = [0 for _ in range(n)]

# t - x(h) * 0.006
for i in range(n) :
    res[i] = t - H[i] * 0.006

result = 0
wk_abs = 0
bf_abs = 999
for i in range(n) :
    if res[i] == a :
        result = i + 1
    else :
        wk_abs = abs(a - res[i])
        if wk_abs < bf_abs :
            bf_abs = wk_abs
            result = i + 1

print (result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  int a=0,b=0; cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0') a++;
    else b++;
  }
    cout<<2*min(a,b)<<endl;
}  

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y) {
	while (y != 0) {
		if (x > y) {
			llint r = x % y;
			x = y;
			y = r;
		}
		else {
			llint r = y % x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	llint N, K, Q;
	cin >> N >> K >> Q;
	vint A(Q), p(N);
	for (int i = 0; i < Q; i++)cin >> A[i];
	for (int i = 0; i < N; i++)p[i] = K - Q;
	for (int i = 0; i < Q; i++)p[A[i]-1]++;
	for (int i = 0; i < N; i++){
		if (p[i]>0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
}



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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	int count = 0;
	int index = 0;
	if(s[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	
	s[0] += 32;
	for(int i=2;i<=s.size()-2;i++){
		if(s[i] == 'C'){
			count++;
			index = i;
		}
	}
	if(count!=1){
		cout << "WA" << endl;
		return 0;
	}
	s[index] += 32;
	for(int i=0;i<s.size();i++){
		if(s[i] < 97 || 122 < s[i]){
			cout << "WA" << endl;
			return 0;
		}
	}
//	cout << s << endl;
	cout << "AC" << endl;
	
	return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    int b; cin>>b;
    a[b-1]=i+1;
  }
  
  for(int i=0;i<n;i++){
    cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100000;
const int mhw = 300;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main() {

	ll n, k;
	ll ans = 0;

	cin >> n >> k;

	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}

	for (int b = k+1; b <= n; b++) {
		if (n%b == 0) {
			ans += (n / b)*(b - k);
		}
		else {
			ans += (n / b)*(b - k) + max((ll)0, n%b - (k - 1));
		}
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

int main() {
	int n,m;
	cin >> n>>m;
	string ans = "Yay!";
	if (n > 8 || m > 8) {
		ans = ":(";
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

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

// (0,0) -> (x,y)
// k=|dx|+|dy|
// nk>=x+y && nk&1=(x+y)&1

typedef long long LL;
typedef pair<int,int> PII;

int rx=0,ry=0,rxy=0;

inline void print(int x,int y)
{
	//cout<<x<<" "<<y<<endl;
	if(rxy) swap(x,y);
	if(rx) x=-x;
	if(ry) y=-y;
	printf("%d %d\n",x,y);
}

vector<PII> ans;
int nx,ny;
void move(int dx,int dy)
{
	nx+=dx; ny+=dy;
	ans.emplace_back(nx,ny);
}

int main()
{
	int k;
	int x,y;
	scanf("%d%d%d",&k,&x,&y);
	if(x<0)
	{
		rx=1;
		x=-x;
	}
	if(y<0) 
	{
		ry=1;
		y=-y;
	}
	if(x<y)
	{
		rxy=1;
		swap(x,y);
	}
	if(((x+y)&1) && (k&1)==0)
	{
		printf("-1\n");
		return 0;
	}
	//cout<<x<<" "<<y<<" "<<rx<<" "<<ry<<" "<<rxy<<endl;
	int n=(x+y+k-1)/k;
	if(((k-(x+y)%k)%k)&1) n++;
	//if((n&k&1)!=((x+y)&1)) n++;
	if(x+y<k) n=2;
	nx=0; ny=0;
	if(((x+y)&1)&&(x+y<k))
	{
		int a=k-x;
		int b=x+(k+x-y)/2;
		int c=k-x+y;
		int d=(k+x-y)/2;
		while(a>=k)
		{
			move(0,-k);
			a-=k;
		}
		while(a+b>=k)
		{
			if(a)
			{
				move(k-a,-a);
				b-=k-a;
				a=0;
			}
			else
			{
				move(k,0);
				b-=k;
			}
		}
		while(b+c>=k)
		{
			if(b)
			{
				move(b,k-b);
				c-=k-b;
				b=0;
			}
			else
			{
				move(0,k);
				c-=k;
			}
		}
		while(c+d>=k)
		{
			if(c)
			{
				move(-(k-c),c);
				d-=k-c;
				c=0;
			}
			else
			{
				move(-k,0);
				d-=k;
			}
		}
	}
	else
	{
		int a=((LL)k*n-x-y)/2;
		int b=x;
		int c=((LL)k*n-x+y)/2;
		while(a>=k)
		{
			move(0,-k);
			a-=k;
		}
		while(a+b>=k)
		{
			if(a)
			{
				move(k-a,-a);
				b-=k-a;
				a=0;
			}
			else
			{
				move(k,0);
				b-=k;
			}
		}
		while(b+c>=k)
		{
			if(b)
			{
				move(b,k-b);
				c-=k-b;
				b=0;
			}
			else
			{
				move(0,k);
				c-=k;
			}
		}
	}
	printf("%d\n",ans.size());
	for(int i=0;i<(int)ans.size();i++)
		print(ans[i].first,ans[i].second);

	return 0;
}

Measured memory_bytes: 3952
#include<stdio.h>
#include<string.h>
int main()
{
    char s[105],t[105];
    gets(s);
    gets(t);
    int i,lengthOfs,lengthOft;
    lengthOfs=strlen(s);
    lengthOft=strlen(t);
    if(lengthOfs!=lengthOft)printf("No\n");
    for(i=0;i<lengthOfs;i++) {
        if(strcmp(s,t)==0){
            printf("Yes\n");
            return 0;
        }
        int j;
        char temp;
        temp=s[0];
        for(j=0;j<lengthOfs-1;j++){
            s[j]=s[j+1];
        }
        s[j]=temp;
    }
    printf("No\n");
    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>                
using namespace std;
typedef long long lint;
#define FOR(i,o,n) for(auto i = (o); (i) < (n); ++(i))
#define REP(i,n) FOR(i,0,n) 
#define REPR(i,n) for(auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr,v) for(auto itr=v.begin(); itr != v.end(); ++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name,h,w)  vector< vector<int> > name((h), vector<int>(w));

int main(){
	int N, M; cin >> N >> M;
	vector<int> v(M+1);
	REP(i,N){
		int counter; cin >> counter;
		REP(j, counter){
			int tmp; cin >> tmp;
			v[tmp]++;
		}
	} 
	int answer = 0;
	REP(i,M+1){
		if(v[i] == N) ++answer;
	}
	cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;

using namespace std;
using Graph = vector<vector<int>>;

pair<int,int> f(int x)
{
    int a = x % 10;
    int b = 0;
    while (x)
    {
        b = x;
        x /= 10;
    }
    return mp(a, b);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<pair<int,int>, int> freq;
    reps(i, n + 1, 1)
    {
        pair<int,int> p = f(i);
        freq[p]++;
    }
    ll ans = 0;
    reps(i, n + 1, 1)
    {
        pair<int,int> p = f(i);
        pair<int,int> q = mp(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 2100000000
#define MOD 1000000007

bool dbgflag = false; //debug

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

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

  int diff = ((n+1)/2) - 1;
  int i = 0;
  while (m > i) {
    if (i%2 == 0) {
      cout << (i/2)+1 << " " << (i/2) + 1 + diff << endl;
    }
    else {
      cout << (n-(i/2)) - diff << " " << n-(i/2) << endl;
    }
    i++;
    diff--;
  }
}


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

using namespace std;

typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))

int main()
{

    string a[8]= {"MON","TUE", "WED", "THU", "FRI", "SAT","SUN"};
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<7<<endl;
    else 
    for(int i=0; i<7; i++)
        if(s==a[i])
        {
            cout<<6-i<<endl;
            break;
        }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[][] bingo = new int [3][3];
		//ビンゴカードの入力
		for(int x=0 ; x<3 ; x++) {
			for(int y=0 ; y<3 ; y++) {
				bingo[x][y] = sc.nextInt();
			}
		}

		//抽選番号の個数の入力と、配列に抽選番号を入力
		int sum = sc.nextInt();
		int num[] = new int[sum];
		int[][] bingoCheck = new int[3][3];  //チェック用
		//配列に
		for(int i=0 ; i<sum ; i++) {
			num[i] = sc.nextInt();
			//カードと抽選番号で同じ数字があれば
			//その場所のビンゴチェックに1を足す
			for(int x=0 ; x<3 ; x++) {
				for(int y=0 ; y<3 ; y++) {
					if(num[i] == bingo[x][y]) {
						bingoCheck[x][y] = 1;
					}
				}
			}
		}
		//結果を表す変数を宣言
		boolean result = false;

		//縦の当たり確認
		//x軸が0、1、2、の場合ごとにcheckが3になるか見てる
		for(int x=0 ; x<3 ; x++) {
			int check = 0;  //xの値ごとにチェックをリセットする
			for(int y=0 ; y<3 ; y++) {
				check += bingoCheck[x][y];
			}
			if(check == 3) {
				result = true;
			}
		}

		//横の当たり確認
		//y軸が0、1、2、の場合ごとにcheckが3になるか見てる
		for(int y=0 ; y<3 ; y++) {
			int check = 0;  //yの値ごとにチェックをリセットする
			for(int x =0 ; x<3 ; x++) {
				check += bingoCheck[x][y];
			}
			if(check == 3) {
				result = true;
			}
		}

		//斜めの当たり確認
		int check = 0;  //1パターンしかないからこの場所でOK
		for(int x=0 ; x<3 ; x++) {
			check += bingoCheck[x][x];
		}
		if(check == 3) {
			result = true;
		}

		//反対の斜めの当たり判断
		check = 0;  //1パターンしかないからこの場所でOK
		for(int y=0 ; y<3 ; y++) {
			check += bingoCheck[y][2-y];
		}
		if(check == 3) {
			result = true;
		}

		//結果の表示
		System.out.print(result ? "Yes" : "No");
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
for(int i=0;i<N;i++){
cin >> vec.at(i);
}
  int num=10000000;
  int res=0;
  for(int i=0;i<N;i++){
  int a=vec.at(i);
  while(a%2==0){a/=2;
  res++;}
  if(res<num)num=res;
  res=0;}
  cout << num << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

int m;
string s, p;

int main()
{
    while (cin >> s)
    {
        if (s == "-")
            return 0;
        cin >> m;
        for (int i = 0; i < m; i++)
        {
            int h;
            cin >> h;
            s = s.substr(h, s.size() - h) + s.substr(0, h);
        }
        cout << s << endl;
    }
}


Measured memory_bytes: 3216
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int a,b,c;
int main()
{
	
	scanf("%d%d%d",&a,&b,&c);
	int ans = abs(a-b) + abs(b-c);
	ans = min(ans, abs(a-c) + abs(b-c));
	
	ans = min(ans, abs(b-c) + abs(c-a));
	ans = min(ans, abs(b-a) + abs(a-c));
	
	ans = min(ans, abs(a-c) + abs(b-a));
	ans = min(ans, abs(b-c) + abs(b-a));
	
	printf("%d\n",ans);
	return 0;
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, d; cin >> n >> d;
	int num = 2 * d + 1;
	if(n % num == 0) cout << n/num << endl;
	else cout << n / num + 1 << endl;
} 

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int N, C;

int table[30][200004];

int main()
{
	cin >> N >> C;
	rep(i, N) {
		int s, t, c;
		cin >> s >> t >> c;
		table[c-1][s*2-1]++;
		table[c-1][t*2+1]--;
	}
	rep(i, C) {
		reps(j, 1, 200004) {
			table[i][j] += table[i][j-1];
		}
	}
	int ma = 0;
	rep(i, 200004) {
		int t = 0;
		rep(j, 30) {
			t += table[j][i] > 0 ? 1 : 0;
		}
		ma = max(ma, t);
	}
	cout << ma << endl;
	return 0;
}

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

#define fast ios::sync_with_stdio(0); cin.tie(NULL); 
#define fi first
#define se second
#define mp make_pair
#define pi 3.14159265359
#define MOD 1000000007
typedef long long ll;
#define mp make_pair
#define ALL(v) v.begin(), v.end() 
#define F(i,s,n) for(i=s;i<n;++i)
#define pb push_back
#define tin freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pll pair<ll,ll>
ll max(ll a,ll b)
{
    return a*(a>=b)+b*(b>a);
}
/*----------------------------------------------------------*/
ll n,w;vector<ll>we,va;
vector<vector<ll>>dp(101,vector<ll>(100010,-1));
ll fun(ll i,ll ca)
{
    if(i==-1||ca==0)return 0;
    if(dp[i][ca]!=-1) return dp[i][ca];
    if(we[i]>ca)return dp[i][ca]=fun(i-1,ca);
    return dp[i][ca]=max(fun(i-1,ca),va[i]+fun(i-1,ca-we[i]));
}
void solve()
{
    cin>>n>>w;
    we.resize(n);va.resize(n);
    ll i;
    F(i,0,n)
    {
        cin>>we[i]>>va[i];
    }
    cout<<fun(n-1,w);
}

int main()
{
    //tin
    fast
    ll tc=1;//cin>>tc;
   for(ll i=1;i<=tc;++i)
   {
    //cout<<"Case #"<<i<<": ";
    solve();
    if(i!=tc)cout<<"\n";
   }
return 0;
}
//End-Cases
//Precomputation
//Segmentation Fault
//Complexity
//Break it up
//Sub Problems


Measured memory_bytes: 83056
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100010];
struct node{int id,x;};
node ji[100010],ou[100010];
int n;

bool cmp(node x,node y)
{
	return x.x>y.x;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=100000;i++)
		ji[i].id=ou[i].id=i;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (i%2==0) ou[a[i]].x++;
		else ji[a[i]].x++;
	}
	sort(ji+1,ji+100001,cmp);
	sort(ou+1,ou+100001,cmp);
	if (ji[1].id!=ou[1].id) printf("%d\n",n-ji[1].x-ou[1].x);
	else
	{
		if (ji[1].x+ou[2].x>=ou[1].x+ji[2].x) printf("%d\n",n-ji[1].x-ou[2].x);
		else printf("%d\n",n-ou[1].x-ji[2].x);
	}
}

Measured memory_bytes: 2176
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        long N = sc.nextInt();	
	        long ans=1;
	        for(int i=0;i<N;i++) {
	        	ans=(ans*10)%mod;
	        }
	        long t=2;
	        for(int i=0;i<N;i++) {
	        	t=(t*9)%mod;
	        }
	        long t2=1;
	        for(int i=0;i<N;i++) {
	        	t2=(t2*8)%mod;
	        }
	        ans=(ans-t+t2+mod)%mod;
	        
	        
	        System.out.println(ans);
		 }
		 
	}

Measured memory_bytes: 35704
import sys

sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline

######################################################

s = input().split('T')
x, y = [int(_) for _ in input().split()]


def m(dp, first_idx):
    for i in range(first_idx, len(s), 2):
        step = len(s[i])

        next_dp = set()
        for item in dp:
            next_dp.add(item + step)
            next_dp.add(item - step)
        dp = next_dp

    return dp


if len(s) > 0:
    xs = {len(s[0])}
    xs = m(xs, 2)
else:
    xs = {0}
if len(s) > 1:
    ys = m({0}, 1)
else:
    ys = {0}

if x in xs and y in ys:
    print('Yes')
else:
    print('No')


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  int Ans=0;
  for(int i=0; i<K; i++){
    Ans+=L.at(N-i-1);
  }
  cout << Ans << endl;
}


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

#define int long long
#define MOD ((int)1e9+7)

#define MAX 2000

int N, m, ans;
int c[MAX], d[MAX];
int temp[MAX];
signed  main(){
  
  cin>>N>>m;

  for(int i = 0; i < m; i++){
    cin>>c[i]>>d[i];
    temp[c[i]]++;
    temp[d[i]]--;
  }
  for(int i = 0; i <= N; i++){
    temp[i+1] += temp[i];
  }

  for(int i = 1; i < N; i++){
    if(temp[i]) ans += 2;
  }
	
 

  cout<<ans+N+1<<endl;

  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }
 
    // 素数である
    return 1;
}
lint f[105];
int main(){
lint N;
cin>>N;
repp(i,1,N+1){
            lint x=i;
       repp(j,2,i+1){
                    if(x%j==0){f[j]++;
                    x/=j;
                    if(j!=1)j--;
                    }
       }
}
lint x4=0,x2=0,x14=0,x24=0,x74=0;
rep(i,105){
    if(f[i]>=2)x2++;
     if(f[i]>=4)x4++;
      if(f[i]>=14)x14++;
       if(f[i]>=24)x24++;
        if(f[i]>=74)x74++;
}
lint ans= x14*(x4-1)+x24*(x2-1)+x74+x4*(x4-1)/2*(x2-2);
cout<<ans;


}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<tuple>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define tii tuple<int,int>
#define tiii tuple<int,int,int>
#define mt make_tuple
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV 1000007
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
#define Nodes 100
class UF{
public:
  int value[Nodes];
  int over[Nodes]; // When over < 0, 'over' keep number of node(using negative number). -1 means this tree is a node.
  int root(int index){
    int t = index;
    stack<int> stack_i;
    while(over[t] >= 0){
      stack_i.push(t);
      t = over[t];
    }
    while(!stack_i.empty()){
      int i = stack_i.top(); stack_i.pop();
      over[i] = t;
    }// reconnect
    return t;
  }
  void merge(int a,int b){
    if(this->root(a) == this->root(b)) return;
    over[root(a)] += over[root(b)]; // over have a number of nodes.
    over[root(b)] = root(a);
  }
  UF(){rep(i,Nodes) over[i] = -1;}
};
int main(){
  int n,m; cin >> n >> m;
  vi va; vi vb;
  rep(i,m){
    int a,b; cin >> a >> b;
    a--,b--;
    va.pb(a); vb.pb(b);
  }
  if(m == 1){cout << 1 << endl; return 0;}
  int ans = 0;
  rep(i,m){
    UF u;
    rep(j,m){
      if(i == j) continue;
      u.merge(va[j],vb[j]);
    }
    rep(i,n){
      if(u.root(0) != u.root(i)){ans++; break;}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int arr[111];
int main()
{
    int n,k,i,j;
    sd(n);sd(k);
    int answer=0;
    for(i=1;i<=n;i++){
        sd(arr[i]);
        answer+=min(arr[i],abs(k-arr[i]));
    }
    answer*=2;
    pdn(answer);
    return 0;
}

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

class Cube{
public:
	int f[6];

	Cube(){}
	void roll_z(){ roll(1, 2, 4, 3); } //
	void roll_y(){ roll(0, 2, 5, 3); } // to W
	void roll_x(){ roll(0, 1, 5, 4); } // to N
	void roll(int i, int j, int k, int l){
		int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
	}
};

bool eq(Cube c1, Cube c2){
	for (int i = 0; i < 6; i++)
		if (c1.f[i] != c2.f[i]) return false;
	return true;
}

bool equal(Cube c1, Cube c2){
	for (int i = 0; i < 6; i++){
		for (int j = 0; j < 4; j++){
			if (eq(c1, c2))
				return true;
			c1.roll_z();
		}
		if (i % 2 == 0) c1.roll_y();
		else c1.roll_x();
	}
	return false;
}

Cube C[100];
int n;

bool chek(){
	for (int i = 0; i < n - 1; i++)
		for (int j = i + 1; j < n; j++)
			if (equal(C[i], C[j]))
				return false;
	return true;
}

int main(){
	cin >> n;

	for (int j = 0; j < n; j++)
		for (int i = 0; i < 6; i++)
			cin >> C[j].f[i];

	if (chek()) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1160
#
# abc054 c
#

import sys
from io import StringIO
import unittest
import itertools


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
1 2
1 3
2 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7"""
        output = """1"""
        self.assertIO(input, output)


def resolve():
    N, M = map(int, input().split())
    P = [list(map(int, input().split())) for _ in range(M)]

    R = itertools.permutations(range(1, N+1))

    ans = 0
    for r in R:
        flag = True
        r = list(r)
        if r[0] != 1:
            break
        for i in range(1, N):
            for p in P:
                if (r[i-1] == p[0] and r[i] == p[1]) or (r[i-1] == p[1] and r[i] == p[0]):
                    break
            else:
                flag = False
        if flag == True:
            ans += 1

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;
V<V<int> > v;

ll f(int a, int b, int c) {
	ll ans = 0;
	REP(i, v[a].size()) {
		REP(j, v[b].size()) {
			if(v[a][i] > v[b][j]) break;
			REP(k, v[c].size()) {
				if(v[b][j] > v[c][k]) break;
				if(v[b][j]-v[a][i] == v[c][k]-v[b][j]) continue;
				// cout << v[a][i] << " " << v[b][j] << " " << v[c][k] << endl;
				ans += 1;
			}
		}
	}
	return ans;
}

int main() {
	ll n, ans = 0;
	string s;

	cin >> n;
	cin >> s;

	REP(i,3) {
		V<int> a;
		v.push_back(a);
	}

	FORD(i,n-1,0) {
		if(s[i] == 'R') {
			v[0].push_back(i);
		} else if (s[i] == 'G') {
			v[1].push_back(i);
		} else if (s[i] == 'B') {
			v[2].push_back(i);
		}
	}
	ans += f(0,1,2);
	ans += f(0,2,1);
	ans += f(1,0,2);
	ans += f(1,2,0);
	ans += f(2,0,1);
	ans += f(2,1,0);

	// REP(i,3) {
	// 	REP(j,v[i].size()) {
	// 		cout << v[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	cout << ans << endl;
	return 0;

}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    REP(i, N){
        cin >> v[i] >> w[i];
    }
    vector<int> dp(W+1, 0);

    REP(i, W+1){
        REP(j, N){
            if(i + w[j] <= W){
                chmax(dp[i+w[j]], dp[i] + v[j]);
            }
        }
    }
    pr(dp[W]);
}


Measured memory_bytes: 3164