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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

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



int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    ll a[n];
    ll sum = 0;

    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }

    ll ans = LLONG_MAX;
    ll x = 0;
    rep(i, n){
        x += a[i];
        if(i+1 < n)
            ans = min(ans, abs(sum-2*x));
    }

    ppp(ans);

    return 0;
}


Measured memory_bytes: 1792
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>

#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int gcd(int a, int b);

int main(){
  int n;
  string s;
  cin >> n >> s;
  string ans = "";
  string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  rep(i,s.length()){
    rep(j,26){
      if(s.substr(i,1) == alp.substr(j,1)){
        ans += alp.substr(j+n,1);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] S = sc.next().toCharArray();
    boolean foundA = false;
    boolean foundB = false;
    boolean foundC = false;
    for (char c : S) {
      if (c == 'a') {
        foundA = true;
      }
      if (c == 'b') {
        foundB = true;
      }
      if (c == 'c') {
        foundC = true;
      }
    }
    
    System.out.println(foundA && foundB && foundC ? "Yes" : "No");
  }
}

Measured memory_bytes: 23764
n, k = map(int, input().split())
d = map(str, input().split())
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(n, 100000):
    Nums = set(str(i))
    if Nums <= left:
        print(i)
        break

Measured memory_bytes: 40300
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <bitset>
#include <memory>

int main() {
	int k, q; std::cin >> k >> q;
	std::vector<int> diff(k); for (auto& d : diff) std::cin >> d;
	for (auto i = 0; i < q; ++i) {
		int n, x, m; std::cin >> n >> x >> m;
		long long int back = 0;
		long long int part = 0;
		int just = 0;
		int part_just = 0;
		for (auto j = 0; j < diff.size(); ++j) {
			back += diff[j] % m;
			if (diff[j] % m == 0) ++just;
			if (j == (n - 2) % k) {
				part = back;
				part_just = just;
			}
		}
		long long int max = x + back * ((n - 2) / k) + part;
		long long int min = x;
		long long int dec = max / m - min / m;
		std::cout << n - 1LL - dec - just * ((n - 2LL) / k) - part_just << '\n';
	}
}


Measured memory_bytes: 888
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    res = 0
    for i in range(0, a + 1):
        for j in range(0, b + 1):
            for k in range(0, c + 1):
                if i * 500 + j * 100 + k * 50 == x:
                    res += 1
    print(res)


if __name__ == '__main__':
    main()


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

/***typededfs***/
typedef long long ll;
typedef long double ldb;

/***defines***/
#define M1 1000000007
#define M2 998244353
#define F first
#define S second
#define pb push_back
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forz(i,n) for(int i=0;i<(n);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define rforz(i,n) for(int i=(n-1);i>=0;i--)
#define rfore(i,a,b) for(int i=(a);i>=(b);i--)
#define test int T; cin>>T; while(T--)
#define all(v) v.begin(),v.end()
#define mm(a,b) ((a%M1)*(b%M1))%M1
#define ma(a,b) ((a%M1)+(b%M1))%M1

int main(){
    FASTIO;
  	int n;
  	cin>>n;
  	int cnt{},ok{};
  	forz(i,n){
  		int x,y;
  		cin>>x>>y;
  		if(x==y)cnt++;
  		else cnt=0;
  		if(cnt>=3)ok=1;
  	}    
  	if(ok==1) cout<<"Yes\n";
  	else cout<<"No\n";
  	
}

Measured memory_bytes: 3648
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		T[] ts = new T[100];
		int n = 0;
		for (;;) {
			String[] ss = sc.next().split(",");
			if (ss[0].equals("0")) break;
			T t = new T();
			t.id = Integer.parseInt(ss[0]);
			t.v = Integer.parseInt(ss[1]);
			ts[n++] = t;
		}
		ts = Arrays.copyOfRange(ts, 0, n);
		sort(ts);
		ts[0].rank = 1;
		for (int i = 1; i < ts.length; i++) {
			if (ts[i-1].v == ts[i].v) {
				ts[i].rank = ts[i-1].rank;
			} else {
				ts[i].rank = ts[i-1].rank + 1;
			}
		}
		for (;sc.hasNext();) {
			int x = sc.nextInt();
			for (T t : ts) if (t.id == x) out.println(t.rank);
			out.flush();
		}
	}

	class T implements Comparable<T> {
		int id;
		int v;
		int rank;
		@Override
		public int compareTo(T o) {
			return o.v - v;
		}
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 16964
import sys


def mulmod(x, y, p=10**9 + 7):
    return x * y % p


def combmod(n, k, p=10**9 + 7):
    from functools import reduce
    k = min(k, n - k)
    x = reduce(mulmod, range(n - k + 1, n + 1), 1)
    y = reduce(mulmod, range(1, k + 1), 1)
    return x * pow(y, p - 2, p) % p


def solve(string):
    x, y = map(int, string.split())
    m0, m1, n = min(x, y), max(x, y), (x + y) // 3
    return "0" if (x + y) % 3 > 0 or m1 / m0 > 2 else str(combmod(n, m0 - n))


if __name__ == '__main__':
    print(solve(sys.stdin.read()))


Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b;
    if (a <= b)
        for (int i = 0; i < b; i++)
            cout << a;
    else
        for (int i = 0; i < a; i++)
            cout << b;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int N; cin >> N;
	set<char> s;
	for (int i = 0; i < N; i++) {
		string p; cin >> p;
		s.insert(p[0]);
	}
	if (s.size() == 4)cout << "Four" << endl;
	else cout << "Three" << endl;


	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i,n){
		cin >> a[i];
		a[i] /= 2;
	}
	ll c = 0, A = a[0];
	while(A%2 == 0){
		++c;
		A /= 2;
	}
	ll l = a[0];
	rep(i,n){
		l = lcm(l, a[i]);
		A = a[i];
		ll cnt = 0;
		while(A%2 == 0){
			++cnt;
			A /= 2;
		}
		if(cnt != c){
			cout << 0 << endl;
			return 0;
		}
		a[i] = A;
	}
	ll ans = (m / l + 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3972
#include<stdio.h>

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

  for(i=0;i<N;i++){
    mini = i;
    for(k=i;k<N;k++){
      if(A[k]<A[mini]){
	mini=k;
      }
    }
    k=A[i];
    A[i]=A[mini];
    A[mini]=k;
    if(i!=mini)c++;//i=cの場合交換は無い
  }
  for(k=0;k<N;k++)if(k!=N-1)printf("%d ",A[k]);else printf("%d\n",A[k]);
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2104
print_endline @@ Scanf.scanf "%d %d %d %d" @@ fun n m x y ->
let xM = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 1)) |> Array.fold_left max (-100) in
let ym = Array.init m (fun _ -> Scanf.scanf " %d" ((+) 0)) |> Array.fold_left min 100 in
if max xM (x+1) <= min ym y then "No War" else "War"

Measured memory_bytes: 512
import java.util.Scanner;

//Extraordinary Grid 1
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			int n = sc.nextInt();
			boolean[] b = new boolean[4*n+1];
			char[] yn = sc.next().toCharArray();
			for(int i=1;i<=4*n;i++)b[i]=yn[i-1]=='Y';
			int[][] cost = new int[n+1][3];
			if(b[4*n]){
				cost[n][0]=6;
				cost[n][1]=4;
				cost[n][2]=4;
			}
			else if(b[2*n]){
				cost[n][0]=2;
				cost[n][1]=2;
				cost[n][2]=4;
			}
			else {
				cost[n][0]=0;
				cost[n][1]=2;
				cost[n][2]=4;
			}
			for(int i=n-1;i>0;i--){
				boolean f1 = b[2*i]||b[2*i+1];
				boolean f2 = b[2*n+2*i]||b[2*n+2*i+1];
				if(f1&&f2){
					cost[i][0] = Math.min(6+cost[i+1][2], Math.min(4+cost[i+1][1], 6+cost[i+1][0]));
					cost[i][1] = Math.min(4+cost[i+1][2], Math.min(4+cost[i+1][1], 4+cost[i+1][0]));
					cost[i][2] = Math.min(6+cost[i+1][2], Math.min(4+cost[i+1][1], 4+cost[i+1][0]));
				}
				else if(f1&&!f2){
					cost[i][0] = Math.min(4+cost[i+1][2], Math.min(2+cost[i+1][1], 2+cost[i+1][0]));
					cost[i][1] = Math.min(4+cost[i+1][2], Math.min(2+cost[i+1][1], 2+cost[i+1][0]));
					cost[i][2] = Math.min(6+cost[i+1][2], Math.min(4+cost[i+1][1], 4+cost[i+1][0]));
				}
				else if(!f1&&f2){
					cost[i][0] = Math.min(4+cost[i+1][2], Math.min(4+cost[i+1][1], 6+cost[i+1][0]));
					cost[i][1] = Math.min(2+cost[i+1][2], Math.min(2+cost[i+1][1], 4+cost[i+1][0]));
					cost[i][2] = Math.min(2+cost[i+1][2], Math.min(2+cost[i+1][1], 4+cost[i+1][0]));
				}
				else{
					cost[i][0] = Math.min(4+cost[i+1][2], Math.min(2+cost[i+1][1], cost[i+1][0]));
					cost[i][1] = Math.min(2+cost[i+1][2], Math.min(cost[i+1][1], 2+cost[i+1][0]));
					cost[i][2] = Math.min(cost[i+1][2], Math.min(2+cost[i+1][1], 4+cost[i+1][0]));
				}
			}
			boolean f1 = b[1];
			boolean f2 = b[2*n+1];
			if(f1&&f2)
				cost[0][0] = Math.min(4+cost[1][2], Math.min(4+cost[1][1], 6+cost[1][0]));
			else if(f1&&!f2)
				cost[0][0] = Math.min(4+cost[1][2], Math.min(2+cost[1][1], 2+cost[1][0]));
			else if(!f1&&f2)
				cost[0][0] = Math.min(4+cost[1][2], Math.min(4+cost[1][1], 6+cost[1][0]));
			else
				cost[0][0] = Math.min(4+cost[1][2], Math.min(2+cost[1][1], cost[1][0]));
			System.out.println(n+cost[0][0]/2);
		}
	}
}

Measured memory_bytes: 13000
#include <stdio.h>
#include <stdlib.h>
int main() {
  int N,M,i=0;
  scanf("%d%d", &N,&M);
  int L[M],R[M],maxL=0,minR=100000;
  for(i=0;i<M;i++){
    scanf("%d%d",&L[i],&R[i]);
    if(L[i]>maxL){
      maxL=L[i];
    }
    if(R[i]<minR){
      minR=R[i];
    }
  }
  if(minR-maxL+1>0){
    printf("%d\n",minR-maxL+1);
  }
  else{
    printf("0\n");
  }
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    string s; cin>>s;

    int cur=0;
    REP(i,N) cur+=(s[i]=='E');
    int ans=cur;

    REP(i,N){
        if(s[i]=='E') cur--;
        ans=min(ans,cur);
        if(s[i]=='W') cur++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 900
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , ans , p[MAXN];

int main() {
    fast_io;

    cin >> n;
    for(ll i = 1 ; i <= n ; i++)    cin >> p[i];
    for(ll i = 2 ; i < n ; i++){
        if(p[i] > min(p[i - 1] , p[i + 1]) && p[i] < max(p[i - 1] , p[i + 1]))  ans++;
    }
    cout << ans << endl;

    return 0;
}
/*

*/


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

using namespace std;

typedef long long ll;

int main() {
		int N, K;
		cin >> N >> K;
		vector<ll> num(K, 0);
		for (int i = 1; i <= N; i++) {
				num[i%K]++;
		}

		ll ans = 0;
		for (int a = 0; a < K; a++) {
				int b = (K - a) % K;
				int c = (K - a) % K;
				if ((b+c) % K != 0) continue;
				ans += num[a] * num[b] * num[c];
		}

		cout << ans << endl;
		return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		a = a + b;
		if(a >= 10)System.out.print("error");
		else System.out.print(a);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

int mat[13][13];
// End of template code!
int main() 
{
    buff();
    int n, m, x;
    cin >> n >> m >> x;
    // n books, m algo, x knowledge
    vi cost(n);
    vi sum(m, 0); 
    for(int i = 0; i < n; ++i) {
        cin >> cost[i];
        for(int j = 0; j < m; ++j) {
            cin >> mat[i][j];
            sum[j] += mat[i][j];
        }
    }
    bool da_pra_ser = true;
    for(int i = 0; i < m; ++i) {
        if(sum[i] < x) {
            da_pra_ser = false;
            break;
        }
    }
    if(da_pra_ser == false) {
        cout << -1 << '\n';
    }
    else {
        int best = 2e8;
        for(int i = 0; i < (1 << n); ++i) {
            int C = 0;
            vi soma(m, 0);
            for(int b = 0; b < n; ++b) {
                if(i & (1 << b)) {
                    C += cost[b];
                    for(int j = 0; j < m; ++j) {
                        soma[j] += mat[b][j];
                    }
                }
            }
            bool bom = true;
            for(int v = 0; v < m; ++v) {
                if(soma[v] < x) {
                    bom = false;
                    break;
                }
            }
            if(bom) best = min(best, C);
        }
        cout << best << '\n';
    }
    return 0;
}



Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
N,K=map(int, sys.stdin.readline().split())
A=[None]+map(int, sys.stdin.readline().split())

L={}        #循環している町のみ記録。L[テレポーターの使用回数]=町の番号
visit=defaultdict(lambda: 0)    #visit[町の番号]=訪問回数
x=1         #スタート地点は常に1
cnt=0       #テレポーターの使用回数
while visit[x]<=2: #まだ未訪問だったら
    if visit[x]==2:
        L[cnt]=x
    if cnt==K:  #使用回数に達したら
        print x #現在の位置を表示
        quit()
    visit[x]+=1  #xを訪問済みに変更
    x=A[x]      #次の訪問先をセット
    cnt+=1

len_L=len(L)

LL={}
for cnt,city_num in L.items():
    LL[cnt%len_L]=city_num

print LL[K%len_L]

Measured memory_bytes: 129480
import string
numbers = "0123456789"
alphabets = string.ascii_letters # a-z+A-Zをロード
characters = numbers + alphabets

def base_cvt(value, n=2):
    try:
        tmp = int(value)
    except:
        raise ValueError('Invalid value:', value)
 
    if n < 2 or n > len(characters):
        raise ValueError('Invalid n:', value)
 
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp%n
        result = characters[idx] + result
        tmp = int(tmp / n)
    idx = tmp%n
    result = characters[idx] + result
    return result
  
a, b = map(int, input().split(" "))

print(len(base_cvt(a,b)))

Measured memory_bytes: 4084
def actual(n, k):
    """10進数のnをk進数に変換してその桁数を返す"""

    # 文字列で考えていく方が楽 
    s = ''
    
    while True:
        n, y = divmod(n, k)

        s += str(y)

        if n == 0:
            num_as_k = s[::-1]  # 不要だけど一応やっとく

            return len(num_as_k)

n, k = map(int, input().split())

print(actual(n, k))

Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc061/tasks/abc061_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, c;
  string r;

  cin >> a >> b >> c;

  r = a <= c && c <= b ? "Yes" : "No";

  cout << r << "\n";

  return 0;
}


Measured memory_bytes: 256
a,b,c = map(int,input().rstrip().split())

if a==5 and b==7 and c==5:
  print("YES")
elif a==7 and b==5 and c==5:
  print("YES")
elif a==5 and b==5 and c==7:
  print("YES")
else:
  print("NO")

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

const double PI = acos(-1);
#define MOD 1000000007

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

main()
{
    optimize();
    ll a,i,j,k,s=0;
    cin>>a;
    for(i=1;i<=a;i++){
        for(j=1;j<=a;j++){
            for(k=1;k<=a;k++) s+=gcd(i,gcd(j,k));
        }
    }
    cout<<s el;
}










//Brainless_Loco Terminates Here!


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

using namespace std;

int main(){
        string s;
        while(cin >> s){ 
                for(int i = 0; i < s.length(); i++){
                        if(s.at(i) == '@'){
                                for(int j = 0; j < s.at(i+1)-'0'; j++){
                                        cout << s.at(i+2);
                                }   
                                i += 2;
                        }else cout << s.at(i);
                }   
                cout << endl;
        }   
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
template<class T>using pqueue = std::priority_queue<T, std::vector<T>, std::greater<T>>;

int get_depth(std::vector<std::set<int>>const& win, int player)
{
	std::priority_queue<int> queue;
	for (auto p : win[player])
	{
		queue.emplace(get_depth(win, p));
	}
	int dep = 0;
	for (int i = 1;queue.size();++i)
	{
		int top = queue.top();
		queue.pop();
		dep = std::max(dep, top + i);
	}
	return dep;
}

int main()
{
	int N;
	std::cin >> N;
	std::vector<std::set<int>> win(N);
	for (int i = 1;i < N;++i)
	{
		int a;
		std::cin >> a;
		win[a - 1].emplace(i);
	}
	std::cout << get_depth(win, 0) << std::endl;
}

Measured memory_bytes: 17408
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

		ArrayList<Integer> al = new ArrayList<>();
		for (int i=0; i<3; i++){
			al.add(Integer.parseInt(sc.next()));
		}

		Collections.sort(al);

		System.out.println((10*al.get(2)+al.get(1)+al.get(0)));
	}
}

Measured memory_bytes: 20948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int MAX = 1000000;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            var memo = Enumerable.Range(0, MAX).ToArray();
            memo[0] = memo[1] = -1;

            int len = (int)Math.Sqrt(MAX);

            for (int i = 2; i < len; i++)
            {
                if (memo[i] == -1) continue;

                for (int j = i + i; j < MAX; j += i)
                {
                    memo[j] = -1;
                }
            }

            var primes = memo.Where(a => a != -1).ToArray();


            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int res = 0;

                for (int i = 0; i < n; i++)
                {
                    string[] input = Console.ReadLine().Split(' ');
                    int p = int.Parse(input[0]);
                    int m = int.Parse(input[1]);

                    int s = p - m;
                    int t = p + m;

                    s = LowerBound(primes, s);
                    t = UpperBound(primes, t);

                    res += (t - s - 1);
                }
                sb.AppendLine(res.ToString());
            }
            Console.Write(sb);
        }

        static int LowerBound(int[] arr, int value)
        {
            int low = 0, high = arr.Length;

            while (low < high)
            {
                int mid = ((high - low) >> 1) + low;

                if (arr[mid] < value) low = mid + 1;
                else high = mid;
            }
            return low;
        }

        static int UpperBound(int[] arr, int value)
        {
            int low = 0, high = arr.Length;

            while (low < high)
            {
                int mid = ((high - low) >> 1) + low;

                if (arr[mid] <= value) low = mid + 1;
                else high = mid;
            }
            return low;
        }
    }
}

Measured memory_bytes: 20624
n,x = map(int,input().split())

ans = n
e = n-x
count = 0
while True:
    
    if x%e == 0:    
        ans += x//e*(e*2)-e
        break
    else:
        ans += (x//e)*e*2
    x,e = e,x%e
    count += 1
    
print(ans)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int D, G;
vector<int> p(11, 0);
vector<int> c(11, 0);
vector<int> dp(18000000, INT_MAX);

int main(void){
    
    scanf("%d %d", &D, &G);
    for(int i = 0; i < D; ++i) scanf("%d %d", &p[i], &c[i]);
    
    dp[0] = 0;
    for(int i = 0; i < D; ++i){
        for(int sum = G - 1; sum >= 0; --sum){
            if(dp[sum] == INT_MAX) continue;
            for(int n = 0; n <= p[i]; ++n){
                int point = (n == p[i]) ? 100 * (i + 1) * n + c[i] : 100 * (i + 1) * n;
                if(G <= sum + point) dp[G] = min(dp[G], dp[sum] + n);
                else dp[sum + point] = min(dp[sum + point], dp[sum] + n);
            }
        }
    }
    printf("%d\n", dp[G]);
    
    return 0;
}


Measured memory_bytes: 70528
# -*- coding: utf-8 -*-

import bisect

if __name__ == '__main__':

    n = int(input())
    a = [int(input()) for _ in range(n)]

    L = [None] * n
    L[0] = a[0]
    length = 1

    for i in range(1, n):
        if L[length - 1] < a[i]:
            L[length] = a[i]
            length += 1
        else:
            indx = bisect.bisect_left(L[:length], a[i])
            L[indx] = a[i]

    print(length)



Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll a,b;
  cin>>a>>b;



  cout << 6-a-b << endl;

}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int A[110000], B[110000];
pint pA[110000], pB[110000];
set<int> setA, setB;
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i] >> B[i];
    for (int i = 0; i < N; i++)pA[i] = pint(A[i], i), pB[i] = pint(B[i], i);
    sort(pA, pA + N);
    sort(pB, pB + N);
    reverse(pB, pB + N);
    int ans = 0;
    int idx = -1;
    for (int i = 0; i < N; i++) {
        ans += min(pA[i].first, pB[i].first);
        if (pA[i].first <= pB[i].first) {
            setA.insert(pA[i].second), setB.insert(pB[i].second);
            idx = i;
        }
    }
    if (idx == -1 || idx == N - 1) {
        cout << ans << endl;
        return 0;
    }
    if (setA == setB) {
        vint vecA, vecB;
        if (idx != 0 && pA[idx].second == pB[idx].second) {
            vecA.push_back(pA[idx - 1].first); vecA.push_back(pA[idx].first);
            vecB.push_back(pB[idx - 1].first); vecB.push_back(pB[idx].first);
        } else {
            vecA.push_back(pA[idx].first); vecA.push_back(pA[idx].first);
            vecB.push_back(pB[idx].first); vecB.push_back(pB[idx].first);
        }

        if (idx != N - 2 && pA[idx + 1].second == pB[idx + 1].second) {
            vecA.push_back(pA[idx + 1].first); vecA.push_back(pA[idx + 2].first);
            vecB.push_back(pB[idx + 1].first); vecB.push_back(pB[idx + 2].first);
        } else {
            vecA.push_back(pA[idx + 1].first); vecA.push_back(pA[idx + 1].first);
            vecB.push_back(pB[idx + 1].first); vecB.push_back(pB[idx + 1].first);
        }

        int cur = 1145141919810LL;
        for (int i = 0; i < 2; i++) {
            for (int j = 2; j < 4; j++) {
                cur = min(cur, min(vecA[i], vecB[j]) + min(vecA[5 - j], vecB[1 - i]) - vecA[i] - vecB[j]);
            }
        }
        ans += cur;
    }
    cout << ans << endl;
}


Measured memory_bytes: 14464
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	vector<string>V(3);
	rep(i, 3) {
		cin >> V[i];
	}
	rep(i, 3) {
		cout << V[i][0];
	}
	cout << endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

from heapq import heappop, heappush

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist


H, W = MAP()
C = [LIST() for i in range(10)]
A = [LIST() for i in range(H)]

graph = defaultdict(list)

for i in range(10):
    for j in range(10):
        cost = C[i][j]
        graph[i].append((j, cost))

ans = 0
for i in range(H):
    for j in range(W):
        from_num = A[i][j]
        if from_num == -1:
            continue
        elif from_num == 1:
            continue
        else:
            ans += dijkstra(graph, from_num)[1]
print(ans)

Measured memory_bytes: 5608
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


#define H 0
#define V 1


bool feasible(const int x, const std::vector<int>& a)
{
  if (a.empty())
    return x == 0;
  
  bool dp[2][20000], *curr = dp[0], *next = dp[1];

  memset(dp, 0, sizeof(dp));

  curr[10000] = true;

  for (const auto& i : a) {
    for (int j = 0; j < 20000; j ++) {
      if (j - i >= 0) {
        if (! curr[j - i])
          next[j] = false;
      }
      else {
        next[j] = false;
      }
        
      if (curr[j]) {
        assert(0 <= j - i && j + i < 20000);
        
        next[j - i] = next[j + i] = true;
      }
    }

    std::swap(curr, next);
  }

  return curr[x + 10000];
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::string s;

  int x, y, size;

  std::cin >> s >> x >> y;

  size = s.size();

  std::reverse(ALL(s));

  while (! s.empty()) {
    char c = s.back();

    if (c == 'T')
      break;

    x --;

    s.pop_back();
  }

  int d = H;

  std::vector<int> h, v;

  while (! s.empty()) {
    char c = s.back();

    int n = 1;

    s.pop_back();

    while (! s.empty() && s.back() == c) {
      s.pop_back();

      n ++;
    }

    if (c == 'T') {
      if (n % 2)
        d = 1 - d;
    }
    else {
      (d == H ? h : v).push_back(n);
    }
  }

  std::cout << (feasible(x, h) && feasible(y, v) ? "Yes" : "No") << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;

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

template<class T>
int read(T &ans) {
	ans=0;char ch=gc();T f=1;
	while(!isdigit(ch)) {
		if(ch==EOF) return -1;
		if(ch=='-') f=-1;
		ch=gc();
	}
	while(isdigit(ch))
		ans=ans*10+ch-'0',ch=gc();
	ans*=f;return 1;
}

template<class T1,class T2>
int read(T1 &a,T2 &b) {
	return read(a)!=EOF&&read(b)!=EOF?2:EOF;
}

template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
	return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
}

typedef long long ll;
const int Maxn=3100000;
const int inf=0x3f3f3f3f;
const ll mod=1000000007;

int n,a[30][30],f[Maxn];

signed main() {
//	freopen("test.in","r",stdin);
	read(n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			read(a[i][j]);
	int end=1<<n;f[0]=1;
	for(int i=1;i<end;i++) {
		int cnt=0;
		for(int j=1,nh=1;j<=n;j++,nh<<=1)
			if(i&nh) cnt++;
		for(int j=1,nh=1;j<=n;j++,nh<<=1)
			if((i&nh)&&a[cnt][j]) f[i]=(f[i]+f[i^nh])%mod;
	}
	printf("%d\n",f[end-1]);
	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> A(N+2,0);
  for(int i=1;i<N+1;i++){
    cin >> A[i];
  }
  long long cost=0;
  for(int i=0;i<N+1;i++){
    cost += abs(A[i+1]-A[i]);
  }
  //cout << cost << endl;
  for(int i=1;i<N+1;i++){
    long long ans=cost-abs(A[i]-A[i+1])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]);
    cout << ans << endl;
  }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





ll solve(vector<ll> v) {
    int n = v.size();
    ll res = 0;
    for (ll i=0; i<n; i++) {
	res += i*v[i]%mod;
	res %= mod;
	res -= 1ll*(n-i-1)*v[i]%mod;
	res %= mod;
    }

    return res;
}


int n, m;
vector<ll> r, c;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m;
    for (int i=0; i<n; i++) {
	ll x; cin>>x;
	r.push_back(x);
    }
    for (int i=0; i<m; i++) {
	ll x; cin>>x;
	c.push_back(x);
    }

    sort(r.begin(), r.end());
    sort(c.begin(), c.end());

    ll ans = solve(r)*solve(c)%mod;

    ans += mod;
    ans %= mod;
    out(ans);  

    return 0;
}


Measured memory_bytes: 3572
package main

import (
	"fmt"
	//"math"
)

func main() {
	var s string
	fmt.Scanf("%s ", &s)
	var c byte
	c = 10
	for i := 0; i < 4; i++ {
		if s[i] == c {
			fmt.Print("Bad")
			return
		}
		c = s[i]
	}
	fmt.Print("Good")
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a+b==15)
    {
        cout<<"+"<<endl;
        return 0;
    }
    else if(a*b==15)
    {
        cout<<"*"<<endl;
        return 0;
    }
    else
    {
        cout<<"x"<<endl;
        return 0;
    }
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < m; i++) cin >> t[i];

    vector< vector<ll> > dp(n + 1, vector<ll>(m + 1, 0));
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }

    for (int j = 0; j <= m; j++) {
        dp[0][j] = 1;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
            } else {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] + MOD - dp[i][j]) % MOD;
            }
        }
    }

    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 31616
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 100;

int W, H;
int dirx[] = {1, 0, -1, 0}, diry[4] = {0, 1, 0, -1};
char fruit[MAXN+5][MAXN+5];

void dfs(int r, int c) {
    char ch = fruit[r][c];
    fruit[r][c] = '\0';
    for (int i = 0; i < 4; i++) {
        int nr = r + diry[i], nc = c + dirx[i];
        if (nr < 0 || nr >= H) continue;
        if (nc < 0 || nc >= W) continue;
        if (fruit[nr][nc] != ch) continue;
        dfs(nr, nc);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    while (cin >> H >> W) {
        if (!W and !H) break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> fruit[i][j];
            }
        }

        int ans = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (fruit[i][j] != '\0') {
                    ans++;
                    dfs(i, j);
                }
            }
        }

        cout << ans << "\n";
    }
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int r;cin>>r;co(3*r*r);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    long long int n, k;
    scanf("%lld %lld", &n, &k);
    long long int arrInput[n];
    for(int i=0;i<n;i++){
        scanf("%lld", &arrInput[i]);
    }
    for(int j=0;j<(n-k);j++){
        if(arrInput[j]>=arrInput[j+k]){
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }

    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
#include <iomanip>
#include <limits>
#include <type_traits>
using namespace std;
using ll = long long int;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
  ll N;
  cin >> N;
  string S;
  cin >> S;

  vector<int> nums;
  char now = S[0];
  if (now == 'W')
    nums.push_back(0);
  int count = 1;
  for (int index = 1; index < S.size(); index++)
  {
    if (S[index] == now) 
    {
      count++;
    }
    else
    {
      nums.push_back(count);
      now = S[index];
      count = 1;
    }

    if (index == S.size()-1)
    {
      nums.push_back(count);
    }

    if (index == S.size()-1 && S[index] == 'W')
    {
      nums.push_back(0);
    }
  }

  vector<int> acc(nums.size(), 0);
  vector<int> acc_W(nums.size(), 0);
  vector<int> acc_E(nums.size(), 0);
  for (int index = 1; index < nums.size(); index++)
  {
    acc[index] = acc[index-1] + nums[index];
    if (index%2 == 0)
    {
      acc_E[index] = acc_E[index-1] + nums[index];
      acc_W[index] = acc_W[index-1];
    }
    else
    {
      acc_E[index] = acc_E[index-1];
      acc_W[index] = acc_W[index-1] + nums[index];
    }
  }

  // for(auto iter : acc_E)
  // {
  //   cout << iter;
  // } cout << endl;
  // for(auto iter : acc_W)
  // {
  //   cout << iter;
  // }

  int min = 1e9;
  int cost = 0;
  for (int index = 0; index < acc.size(); index++)
  {
    cost = 0;
    // left
    cost += acc_W[index];
    // right
    cost += (acc_E.back() - acc_E[index]);

    chmin(min, cost);
  }
  
  cout << min << endl;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 1000000007
#define INF 2147483647
#define fi first
#define se second
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0;
  cin>>a>>b>>c;
  for(int i=1;i<=a;i++){
    int e=i,f=0,g=i;
    while(true){
      if(e==0) break;
      f=e%10+f;
      e/=10;
    }
    if(b<=f&&f<=c) d+=g;
  }
  cout<<d<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define SORT(x) (sort(x.begin(),x.end()))
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) (reverse(x.begin(),x.end()))

struct RMQRUQ {
	int n;
	vector<int> dat, lazy;
 
	RMQRUQ(){}
	RMQRUQ(int n_) {
		n = 1; while(n < n_) n *= 2;
		dat.assign(n*2, INT_MAX);
		lazy.assign(n*2, INT_MAX);
	}
 
	void eval(int len, int k) {
		if(lazy[k] == INT_MAX) return;
		if(k*2+1 < n*2-1) {
			lazy[2*k+1] = lazy[k];
			lazy[2*k+2] = lazy[k];
		}
		dat[k] = lazy[k];
		lazy[k] = INT_MAX;
	}
 
  // [a, b)
	int update(int a, int b, int x, int k, int l, int r) {
		eval(r-l, k);
		if(b <= l || r <= a) return dat[k];
		if(a <= l && r <= b) {
			lazy[k] = x;
			return lazy[k];
		}
		return dat[k] = min(update(a, b, x, 2*k+1, l, (l+r)/2), update(a, b, x, 2*k+2, (l+r)/2, r));
	}
	int update(int a, int b, int x) { return update(a, b, x, 0, 0, n); }
	// [a, b)
	int query(int a, int b, int k, int l, int r) {
		eval(r-l, k);
		if(b <= l || r <= a) return INT_MAX;
		if(a <= l && r <= b) return dat[k];
		int vl = query(a, b, 2*k+1, l, (l+r)/2);
		int vr = query(a, b, 2*k+2, (l+r)/2, r);
		return min(vl, vr);
	}
	int query(int a, int b) { return query(a, b, 0, 0, n); }
};

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

	int N,Q;
	cin >> N >> Q;
	RMQRUQ tr(Q+8);
	tr.update(0,Q+7,-1);
	vector< pair<int, pair<int,int> > > xst(N);
	FOR(i,0,N){
		int s,t,x;
		cin >> s >> t >> x;
		xst[i] = {x,{s,t}};
	}
	vector<int> D(Q);
	FOR(i,0,Q){
		cin >> D[i];
	}
	D.push_back(INT_MAX);
	SORT(xst);
	REV(xst);
	FOR(i,0,N){
		int s_x = xst[i].second.first - xst[i].first;
		int t_x = xst[i].second.second - xst[i].first;
		int a = POSL(D,s_x);
		int b = POSU(D,t_x-1);
		tr.update(a,b,xst[i].first);
	}
	FOR(i,0,Q){
		cout << tr.query(i,i+1) << endl;
	}
}


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

int main(){
    int a[1000];
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    for(int i=0;i<n;i++){
        cout<<a[n-1-i]<<flush;
        if(i==n-1) break;
        cout<<" "<<flush;
    }
    cout<<endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int h[100010],f[100010];//f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
int k,n;
int main(){
	memset(f,0x3f,sizeof(f));
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	f[1]=0;
	for(int i=1;i<=n;i++){
		for(int j=max(i-k,1);j<i;j++) {
			f[i]=min(f[i],abs(h[i]-h[j])+f[j]);//cout<<j<<" ";
		}
		//cout<<f[i]<<endl;
	}
	cout<<f[n];
}
//https://atcoder.jp/contests/dp/tasks/dp_b

Measured memory_bytes: 1024