akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll a, ll b){ return b? gcd(b, a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    bool flag = false;
    sort(a.begin(), a.end(), greater<int>());
    for(int i = 0; i < n; i++){
        h -= a[i];
        if(h <= 0){
            flag = true;
            break;
        }
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
N=int(input())
x=[]
y=[]
l=[]
for i in range(N):
    a,b=map(int,input().split())
    x.append(a)
    y.append(b)
l.sort()

d=dict()
r=[]
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        p = x[i]-x[j]
        q = y[i]-y[j]
        c=(p,q)
        if c in d:
            d[c]+=1
        else:
            d[c]=1
ans=0
#print(d)
for i,j in d.items():
    ans=max(ans,j)

print(N-ans)

Measured memory_bytes: 39280
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  map<ll,ll>M;
  rep(i,n){
    if(a[i]%4==0)M[4]++;
    else if(a[i]%2==0)M[2]++;
    else M[1]++;
  }
  if(M[2]==n || M[4]==n/2 ||M[2]>=n-2*M[4]){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

bool is753(ll v) {
    bool has3 = false, has5 = false, has7 = false, hasOther = false;
    while (v > 0) {
        switch (v%10)
        {
        case 3:
            has3 = true;
            break;
        case 5:
            has5 = true;
            break;
        case 7:
            has7 = true;
            break;
        default:
            hasOther = true;
            break;
        }
        v /= 10;
    }
    return has3 && has5 && has7 && !hasOther;
}

int main() {
    ll n;
    cin >> n;
    queue<ll> q;
    q.push(3);
    q.push(5);
    q.push(7);
    ll res = 0;
    while (!q.empty()) {
        auto v = q.front();
        q.pop();
        if (v > n) {
            continue;
        } else {
            if (is753(v)) {
                ++res;
            }
            q.push(v*10 + 3);
            q.push(v*10 + 5);
            q.push(v*10 + 7);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
 
int main(void){
  long long int l,n;
  long long int i;
  long long int min=100000;
  long long int s=0;
  long long int a=0;
  long long int b=0;
  long long int c=0;
  long long int d=0;
  scanf("%lld %lld",&n,&l);
  a = n*l;
  b = (1+n)*n/2;
  s = a+b-n;
  
  for(i=1;i<=n;i++){
    d = abs(l+i-1);
    if(min>d){
      min = d;
      c = l+i-1;
    }
  }
  printf("%d",s-c);
  return 0;
}

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

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

    long long ans = 0;
    range (a, 1, n + 1) {
        long long amari = k - (a % k);
        long long va = ((n - amari) / k) + 1;
        if (amari * 2LL % k == 0LL)ans += va * va;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable.{Set => MSet}

object SetTest {
/** @see  m
  *
  * */
  val sc = new java.util.Scanner(System.in)

  def cards: Set[String] ={
    val m: MSet[String] = MSet.empty[String]
    val f = List ("S", "H", "C", "D")
    for (i<- f; j <- 1 to 13) m.add (s"$i $j")
    m.toSet
  }

  def run() = {
    val m0 = cards
    val f = List ("S", "H", "C", "D")
    val n = sc.nextInt // ???????????°??????????????????
    val m1 = Array.fill(n+1)(sc.nextLine).toSet[String]
   

    val m3 = m0 diff m1
    val a = new Array[List[String]](4)
    for ( i<- 0 until 4) a(i) = m3.filter(p => p.startsWith(f(i))).toList.sortWith((a,b) => a.split(" ")(1).toInt < b.split(" ")(1).toInt)

    for ( i<- a; j <- i) println(j)
  }

}
object Main {
  def main(args: Array[String]): Unit = {

    SetTest.run
  }
}

Measured memory_bytes: 45520
import math
import sys
x, y = map(int, input().split())
a = (4 * x - y) / 2
if y % 2:
    print('No')
    sys.exit()
if a >= 0 and a <= x:
    if math.floor(a) == int(a):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <numeric>
#include <limits>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;

 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() {
	int a, b, c;
	std::cin >> a >> b >> c;
	a -= b;
	while (a > 0) {
		if (a - c < 0) {
			break;
		}
		a -= c;
	}
	std::cout << a << std::endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1000000000;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

int calc(int n){
  if (n % 4 == 0) return n;
  else if (n % 4 == 1) return 1;
  else if (n % 4 == 2) return n + 1;
  else  return 0;	
}

void solve(){
   int a, b;
   cin >> a >> b;
   int ret = calc(b);
   ret ^= calc(a - 1);
   cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >>s;
  bool ans1 =false;
  bool ans2=false;
  for(int i=0;i<s.size();i++){
    if( s.at(i)== 'C'){
      ans1 =true;
    }
    else if(s.at(i) == 'F'&& ans1){
      ans2=true;
    }
  }
  cout <<(ans1&&ans2 ? "Yes":"No")<<endl;
  
}


Measured memory_bytes: 256
def c_one_stroke_path(N, M, E):
    from itertools import permutations
    edge = [[] for j in range(N + 1)]
    for a, b in E:
        edge[a].append(b)
        edge[b].append(a)

    ans = 0
    # 頂点1を始点としてこの順番に頂点を回れるか試す
    routes = permutations(range(2, N + 1), N - 1)
    for route in routes:
        r = [1] + list(route)
        for i in range(len(r) - 1):
            if not r[i + 1] in edge[r[i]]:
                break  # 次の行き先に行くことができなかった
        else:
            ans += 1  # すべての頂点を訪れることができた
    return ans

N,M = [int(i) for i in input().split()]
E = [[int(i) for i in input().split()] for j in range(M)]
print(c_one_stroke_path(N, M, E))


Measured memory_bytes: 3064
N = int(input())

for h in range(1, 3501):
  for n in range(h, 3501):
    if (4 * h * n - N * n - h * N) == 0:
      continue
    w = (N * h * n) / (4 * h * n - N * n - h * N)
    if w.is_integer() and 1 <= w < 3501:
      print(h, n, int(w))
      exit()

Measured memory_bytes: 40684
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  long long int b,a;
  cin >> a >> b;
  for (int i = 1; i <= 1000; ++i)
  {
    int r1 = i*(0.08);
    int r2 = i*(0.1);
    if(r1 == a && r2 == b)
    {
      cout << i;
      return 0;
    }
  }
  cout << -1;
	return 0;
}	

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	ll res = 0;
	ll tmp;
	REP(i, N){
		cin >> tmp;
		res += (tmp-1);
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(int i =a ;i <= b;i++)
using namespace std;

int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	cout.sync_with_stdio(false);
	cin.tie(0);
	ll n,x,y;
	long double d;
	cin>>n>>d;
	ll count = 0;
	rep(i,0,n-1)
	{
		cin>>x>>y;
		long double dist = sqrt(x*x + y*y);

		//cout<<dist<<" "<<d<<"\n";
		if(dist <= d)
			count+=1;
	}
	cout<<count;	
}

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> v;
  rep(n)
  {
    ll tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  v[n-1] = v[n-1]/2;
  ll tmp = 0;
  rep(n) tmp+=v[i];
  cout << tmp << endl;
  return 0;
}

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

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;


bool graph[8][8];


int dfs(int v, int n, bool visited[8]) {
	bool all_visited = true;
	rep(i, 0, n) {
		if (visited[i] == false)
			all_visited = false;
	}

	if (all_visited)return 1;


	int ret=0;
	rep(i, 0, n) {
		if (visited[i] == true)continue;
		if (graph[v][i] == false)continue;

		visited[i] = true;
		ret += dfs(i,n,visited);
		//次の頂点に移る前にvisitedを初期化
		visited[i] = false;
	}

	return ret;

}


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

	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
	}

	bool visited[8];
	rep(i, 0, n)visited[i] = false;

	visited[0] = true;
	cout << dfs(0, n, visited) << endl;
	return 0;
}



Measured memory_bytes: 256
N = int(input())
Alist = list(map(int, input().split()))
Alist = sorted(Alist, reverse = True)

current = 1
count = 0
comfort = Alist[0]
for i in range(2,N):
  if (count < 2):
    count += 1
    comfort += Alist[current]
  else:
    count = 1
    current += 1
    comfort += Alist[current]
    
    

print(comfort)
    
    

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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int ans = 1;
    int prev = s[0];
    for(int i=1; i<n; i++){
        if(s[i] == prev) continue;
        ans++;
        prev = s[i];
    }
    cout << ans << endl;    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n;
  cin >> n;
  V w;
  ll sum =0;

  for(ll i=0; i<n ;i++) {
    ll t;
    cin >> t;
    w.push_back(t);
    sum += t;
  }

  ll res;
  ll lsum = 0;
  for(ll i=0; i<n; i++) {
    lsum += w[i];
    if(res > abs(lsum - (sum-lsum))) {
      res = abs(lsum - (sum-lsum));
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#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;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; 

struct Res {
    ll g, x, y;
};

Res gcd(ll a, ll b) {
    if(b == 0) return {a, 1, 0};
    Res r = gcd(b, a % b);
    return {r.g, r.y, r.x - r.y * (a / b)};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n; cin >> n;
    vector<ll> a(n);
    unordered_map<int, int> occ;
    for(ll &i : a) {
        cin >> i;
        ll tmp = i;
        for(int j = 2; j * j <= tmp; j++) {
            int cnt = 0;
            while(tmp % j == 0) {
                cnt++;
                tmp /= j;
            }
            occ[j] = max(occ[j], cnt);
        }
        if(tmp) occ[tmp] = max(occ[tmp], 1);
    }

    ll lcm = 1LL;
    for(const auto &p : occ)
        for(int i = 0; i < p.second; i++)
            lcm = (lcm * p.first) % MOD;

    ll sum = 0LL;
    for(ll &i : a) {
        ll iinv = gcd(ll(MOD), i).y;
        iinv = (iinv + MOD) % MOD;
        sum = (sum + (iinv * lcm) % MOD) % MOD;
    }

    cout << sum << endl;
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << "\n"
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << "\n"
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
int lowerbound(vector<int> &v, int num) {
  int left = 0, right = v.size()-1;
  while(right-left > 0) {
    int mid = (left + right) / 2;
    if(v[mid] >= num) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  if(v[left] >= num) return left;
  else return v.size();
}

int upperbound(vector<int> &v, int num) {
  int left = 0, right = v.size()-1;
  while(right-left > 0) {
    int mid = (left + right) / 2;
    if(v[mid] > num) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  if(v[left] > num) return left;
  else return v.size();
}
signed main() {
  int n; cin >> n;
  vector<int> a(n), b(n), c(n);
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) cin >> c[i];
  SORT(a); SORT(b); SORT(c);
  int ans = 0;
  REP(i,n) {
    int upper_count = lowerbound(a, b[i]);
    int lower_count = n - upperbound(c, b[i]);
    ans += upper_count * lower_count;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/

Measured memory_bytes: 5648
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,M;
int main(){
    string s;
    char a[50][50],b[50][50];
    cin >> N >> M;
    rep(i,N){
        cin >> s;
        rep(j,N) a[i][j] = s[j];
    }
    rep(i,M){
        cin >> s;
        rep(j,M) b[i][j] = s[j];
    }
    
    rep(i,N-M+1) rep(j,N-M+1){
        bool flag = true;
        rep(h,M) rep(w,M) if(a[i+h][j+w] != b[h][w]) flag = false;
        if(flag){ pr(yes); return 0;}
    }
    
    pr(no);
    
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class UnionFind{
public:
	vector<ll> par;
	vector<ll> num;

	UnionFind(ll N):par(N),num(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		return par[x]=root(par[x]);
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
		num[ry] += num[rx];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}
};


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

	auto N=in(),Q=in();
	UnionFind uf(N);

	REP(i,Q){
		int q=in();
		int u=in(),v=in();
		if(q==1){
			out(uf.same(u,v)?1:0);
		}
		else{
			uf.unite(u,v);
		}
	}
	
	return 0;
}



Measured memory_bytes: 3316
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


def judge(y, x, dis):
    if info[y][x] == ".":
        info[y][x] = "#"
        stack.append([y, x, dis + 1])


H, W = map(int, input().split())
info = [["#"] * (W + 2)]
for _ in range(H):
    info.append(["#"] + list(input()) + ["#"])
info.append(["#"] * (W + 2))
white = 0
for i in range(H + 2):
    for j in range(W + 2):
        if info[i][j] == ".":
            white += 1

stack = deque([[1, 1, 0]])
while len(stack) > 0:
    y, x, dis = stack.popleft()
    if y == H and x == W:
        ans = dis
        break
    judge(y + 1, x, dis)
    judge(y, x + 1, dis)
    judge(y - 1, x, dis)
    judge(y, x - 1, dis)
    if len(stack) == 0:
        print(-1)
        sys.exit()
print(white - dis - 1)


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

int main(){
	string str;
	while(getline(cin,str) && str != "."){
		string c;
		for(int i = 0 ; i < str.size() ; i++)
			if(str[i] == ')' || str[i] == '(' || str[i] == '[' || str[i] == ']')
				c += str[i];
		stack<char> s;
		bool f = true;
		for(int i = 0 ; i < c.length() ; i++){
			if(s.empty() || c[i] == '(' || c[i] == '[')
				s.push(c[i]);
			else if( (s.top() == '(' && c[i] == ')') || (s.top() == '[' && c[i] == ']') ){
				s.pop();
			}else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ?"yes":"no") << endl;
	}
}

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


int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string a;
  rep(i,n){
    a += s[i];
    a += t[i];
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){

    int A,B;cin>>A>>B;
    if((A+B)%2==0){
        cout<<(A+B)/2<<endl;
    }else cout<<"IMPOSSIBLE"<<endl;
}



Measured memory_bytes: 256
import math

def lca(x, y):
    if d[x] < d[y]:
        x,y = y,x
    dy = d[y]
    k = d[x]-dy#abs(depth)
    #Align depth
    while k:
        x = p[x][int(math.log(k,2))]
        k = d[x]-dy

    if x == y:
        return x

    for i in range(h)[::-1]:
        #print(h)
        if p[x][i] != p[y][i]:
            x = p[x][i]
            y = p[y][i]
    return p[x][0]
  
if __name__ == "__main__":
    n = int(input())
    #depth
    d = [0] * n
    d[0] = 1
    #parent
    p = [[] for i in range(n)]
    p[0].append(0)
    for i in range(n):
        vi = map(int, input().split()[1:])
        nd = d[i] + 1
        for j in vi:
            p[j].append(i)
            d[j] = nd
    
    #print(p)
    #print(d)
    
    h = int(math.log(max(d),2)) + 1
    for i in range(h - 1):
        for x in range(n):
            p[x].append(p[p[x][i]][i])
    #print(p)
    
    q = int(input())
    for _ in range(q):
        x,y = map(int, input().split())
        print(lca(x,y))



Measured memory_bytes: 43112
#include <iostream>

using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		bool f = false;
		int ans = 0;
		for(int i=0;i<n;i++){
			int k;
			cin >> k;
			if(k >= 2) f = true;
			if(k > 0) ans++;
		}
		if(f) cout << ans + 1 << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n; cin>>n;
    string s; cin>>s;
    ll r=0,ans=0;
    rep(i,s.size()){
        if(s[i]=='R')r++;
    }
    rep(i,r){
        if(s[i]=='W')ans++;
    }
    cout<<ans<<endl;
}








































Measured memory_bytes: 3760
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e5+5;
const ll inf = 1e18+7;
ll w[MAX],valor[MAX],dp[MAX];
int main() {
  fastio;
  ll n,cap;
  cin>>n>>cap;
  f(i,0,n) cin>>w[i]>>valor[i];
  f(i,0,n){
    af(j,cap,1){
      if(j>=w[i]) dp[j] = max(dp[j],dp[j-w[i]]+valor[i]);
    }
  }
  cout<<dp[cap]<<"\n";
  return 0; 
}

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

int main() {
    int n; cin >> n;
    vector<vector<int>> abc(n, vector<int>(3));
    for(int i = 0; i < n; i ++) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    vector<vector<int>> dp(n, vector<int>(3));
    dp[0] = {abc[0][0], abc[0][1], abc[0][2]};
    for(int i = 1; i < n; i++) {
        dp[i] = {abc[i][0]+max(dp[i-1][1], dp[i-1][2]), abc[i][1]+max(dp[i-1][0], dp[i-1][2]), abc[i][2]+max(dp[i-1][0], dp[i-1][1])};
    }
    cout << *max_element(dp[n-1].begin(), dp[n-1].end()) << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	ld a, b, x;
	cin >> a >> b >> x;
	ld ans;
	if (a * a * b / 2.0 <= x) {
		ans = atan(2 * (a * a * b - x) / (a * a * a));
	} else {
		ans = M_PI / 2 - atan(2 * x / (a * b * b));
	}
	cout << prec << ans * 180.0 / M_PI;
}

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


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define print(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pdd pair<ld,ld> 
#define ld double
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int mod = 998244353, x = 864197532, N = 50000;
const double eps = 1e-6, Pi = 3.1415926535;

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, s;
	cin >> n >> s;
	int a[n];
	fop (i,0,n) cin >> a[i];
	/*
	dp[i][j][0] += dp[i - 1][j - a[k]][0] ~ [2]
	dp[i][j][1] += dp[i - 1][j][0] ~ [2]
	dp[i][j][2] *= 2
	*/
	lli dp[n + 1][s + 1][3];
	fop (i,0,n + 1) fop (j,0,s + 1) fop (k,0,3) dp[i][j][k] = 0;
	dp[0][0][0] = 1;
	fop (i,1,n + 1) {
		fop (j,0,s + 1) {
			fop (l,0,3) if (j >= a[i - 1]) {
				dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j - a[i - 1]][l]) % mod;
			}
			fop (l,0,3) {
				dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j][l]) % mod;
			}
			fop (l,0,3) {
				dp[i][j][2] = (dp[i][j][2] + dp[i - 1][j][l]) % mod;
			}
		}
	}
	lli ans = 0;
	fop (i,0,3) ans = (ans + dp[n][s][i]) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 214684
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<ll> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mxn = 1e5;
// int cnt1[mxn+2],cnt2[mxn+2];

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int base = 1;
	while(base<n){
		base<<=1;
	}
	int t[26][2*base];
	memset(t,0,sizeof(t));

	for(int i =0;i<n;i++){
		char c = s[i];
		t[c-'a'][i+base]++;
		// for(int j = (i+base)/2;j>0;j>>=1){
		// 	t[c-'a'][j] = t[c-'a'][j<<1] + t[c-'a'][j<<1|1];
		// }
	}
	// for(int i =0;i<26;i++){
	// 	for(int j =base;j<n+base;j++){
	// 		cout << t[i][j]<< " " << i << " " << j  << endl;
	// 	}
	// }
	for(int j = 0;j<26;j++){
		for(int i =base-1;i>0;--i){
			t[j][i]  = t[j][i<<1]| t[j][i<<1|1];
		}
	}
	// for(int i =0;i<2;i++){
	// 	cout << t[i][1] << endl;
	// }
	int q;
	cin >> q;
	while(q--){
		int type;
		cin >> type;
		if(type==1){
			int idx;char c;
			cin >> idx >> c;
			--idx;
			t[s[idx]-'a'][idx+base]--;
			t[c-'a'][idx+base]++;
			for(int j = (idx+base)/2;j>0;j>>=1){
				t[s[idx]-'a'][j] = t[s[idx]-'a'][j<<1] | t[s[idx]-'a'][j<<1|1];
				t[c-'a'][j] =t[c-'a'][j<<1] | t[c-'a'][j<<1|1];
			}
			s[idx] = c;
			// cout << s << endl;
		}
		else{
			int l; int r;
			cin >> l >> r;
			int cpyl,cpyr;
			cpyl = l; cpyr = r;
			cpyl--;
			int ans =0;
			--l;
			for(int i =0;i<26;i++){
				int is_there = 0;
				for(l=cpyl+base,r=cpyr+base;l<r;l>>=1, r>>=1){
					if(l&1) is_there+=t[i][l++];
					if(r&1) is_there+=t[i][--r];
				}
				// cout << i << " " << is_there << endl;
				if(is_there>0)
					ans++;
			}
			cout << ans << endl;

		}
	}
}

int main(){
	fast;
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 107420
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n,w;
    cin>>n>>w;
    int a[n],b[n],mx=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int dp[w+1]={0};
    for(int i=0;i<n;i++)
    {
        for(int j=w;j>0;j--)
        {
            if(dp[j]>0 && j+a[i]<=w)
            {
                dp[j+a[i]]=max(dp[j+a[i]],dp[j]+b[i]);
                mx=max(mx,dp[j+a[i]]);
            }
        }
        if(a[i]<=w)
        {
            dp[a[i]]=max(dp[a[i]],b[i]);
            mx=max(mx,dp[a[i]]);
        }
    }
    cout<<mx;
}

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

using namespace std;

typedef struct {
    string n;
    int t;
} Process;

int main() {
    int n, q, total;
    Process p;
    deque<Process> dq;

    cin >> n >> q;

    for (int i = 0; i < n; i++) {
        cin >> p.n >> p.t;
        dq.push_back(p);
    }

    total = 0;
    while (!dq.empty()) {
        p = dq.front();
        dq.pop_front();

        total += (p.t > q)? q: p.t;

        if (p.t > q) {
            dq.push_back({p.n, p.t - q});
        } else {
            cout << p.n << " " << total << endl;
        }
    }
}

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

using namespace std;

int main() {
    int N, M, X, Y;
    int x[102], y[102];

    cin >> N >> M >> X >> Y;

    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }

    int x_max, y_min;

    x_max = *max_element(x, x+N);
    y_min = *min_element(y, y+M);

    if (X < Y && x_max < Y && X < y_min && x_max < y_min) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		Ink l = Ink.LARGE;
		Ink m = Ink.MIDDLE;
		Ink s = Ink.SMALL;
		Paper p = new Paper(10);
		
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			Scanner scstr = new Scanner(sc.nextLine());
			scstr.useDelimiter(",");
			
			int x = scstr.nextInt();
			int y = scstr.nextInt();
			Ink i = null;
			int ink_size = scstr.nextInt();
			if(ink_size == 1) i = s;
			else if(ink_size == 2) i = m;
			else if(ink_size == 3) i = l;
			
			p.drop(x, y, i);
			scstr.close();
		}
		System.out.println(p.countWhiteCells());
		System.out.println(p.maxDensity());
		sc.close();
	}
	
}

class Paper{
	int[][] paper;
	
	Paper(int size){
		this.paper = new int[size][size];
		for(int[] row: this.paper) {
			Arrays.fill(row, 0);
		}
	}
	
	void drop(int x, int y, Ink ink) {
		for(int i = 0; i < ink.range.length; i++) {
			for(int j = 0; j < ink.range.length; j++) {
				if(ink.range[i][j]) paint(this.paper, x - ink.center_x + i, y - ink.center_y + j);
			}
		}
	}
	
	void paint(int[][] paper, int x, int y) {
		if(0 <= x && x < paper.length && 0 <= y && y < paper.length) paper[x][y]++;
	}
	
	int countWhiteCells() {
		int result = 0;
		for(int[] i: paper) {
			for(int j: i) {
				if(j == 0) result++;
			}
		}
		return result;
	}
	
	int maxDensity() {
		int max = 0;
		for(int[] i: paper) {
			for(int j: i) {
				if(j > max) max = j;
			}
		}
		return max;
	}
	
}

enum Ink{
	SMALL(new boolean[][] {
			{false,	true,	false},
			{true,	true,	true},
			{false,	true,	false}
	}, 1, 1), 
	
	MIDDLE(new boolean[][] {
			{true,	true,	true},
			{true,	true,	true},
			{true,	true,	true}
	}, 1, 1), 
	
	LARGE(new boolean[][] {
			{false,	false,	true,	false,	false},
			{false,	true,	true,	true,	false},
			{true,	true,	true,	true,	true},
			{false,	true,	true,	true,	false},
			{false,	false,	true,	false,	false}
	}, 2, 2);
	
	boolean[][] range;
	int center_x;
	int center_y;
	
	private Ink(boolean[][] range, int center_x, int center_y) {
		this.range = range;
		this.center_x = center_x;
		this.center_y = center_y;
	}
}

Measured memory_bytes: 22724
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<vector<int>> a(n,vector<int>(n,-1));
    
    for(int i = 0;i < n;i++){
          int A;
          cin >> A;
          for(int j = 0;j < A;j++){
                int x,y;
                cin >> x >> y;
                x--;
                a[i][x] = y;
          }
    }
    int ans = 0;
    for(int i = 0;i < 1 << n;i++){
          int t = __builtin_popcount(i);
          vector<int>v(n);
          for(int j = 0;j < n;j++){
                if(i >> j & 1)v[j] = 1;
          }
          bool ok = true;
          for(int j = 0;j < n;j++){
                if(v[j]){
                      for(int k = 0;k < n;k++){
                            if(a[j][k] == -1)continue;
                            if(a[j][k] != v[k]){
                                  ok = false;
                            }
                      }
                }
          }
          if(ok)ans = max(ans,t);
          
    }
    cout << ans << endl;
}


Measured memory_bytes: 3588
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
BC=[0]*N
for i in range(N):
  id = bisect.bisect_right(C,B[i])
  BC[i]=N-id
sBC=[0]*(N+1)
for i in range(1,N+1):
  sBC[i]=sBC[i-1]+BC[i-1]
for i in range(N):
  id=bisect.bisect_right(B,A[i])
  ans+=sBC[N]-sBC[id]
print(ans)
  

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int x; cin >> x;
  cout << 10 - x/200 << endl;
  return 0;
}


Measured memory_bytes: 3632
from collections import deque

q = deque()

while True:
    w, h = [int(_) for _ in raw_input().split()]
    if w == h == 0:
        break

    c = [[int(_) for _ in raw_input().split()] for __ in xrange(h)]
    ans = 0
    while True:
        for y in xrange(h):
            for x in xrange(w):
                if c[y][x] == 1:
                    c[y][x] = 0
                    q.append((x, y))
                    break
            else:
                continue
            break
        else:
            # No more land area
            break
        ans += 1
        while q:
            x, y = q.popleft()
            for dx, dy in ((x, y) for x in [-1, 0, 1] for y in [-1, 0, 1] if (x, y) != (0, 0)):
                nx = x + dx
                ny = y + dy
                if not (0 <= nx < w and 0 <= ny < h):
                    continue
                if c[ny][nx] == 1:
                    q.append((nx, ny))
                    c[ny][nx] = 0
    print ans

Measured memory_bytes: 6588
mod = 1000000007
n = int(input())
s = [ input() for i in range(2)]
ans = 1
i = 0
while i < n:
  if s[0][i] == s[1][i]:
    if i == 0:
      ans *= 3
    elif s[0][i-1] == s[1][i-1]:
      ans *= 2
    i += 1
  else:
    if i == 0:
      ans *= 6
    elif s[0][i-1] == s[1][i-1]:
      ans *= 2
    else:
      ans *= 3
    i+=2
  ans %= mod
print(ans)

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

int main(void)
{
  ll N;
  cin >> N;
  
  ll min_sum=N;	// i+jが最小のもの
  ll i,j;
  for(i=1;i<=(N+i-1)/i;i++)
  {
    if(N%i==0)
    {
      if(min_sum > i+N/i) min_sum=i+N/i;
    }
  }
  
  if(min_sum==2)
  {
    cout << 1;
  }
  else if( min_sum==N)
  {
    cout << min_sum-1;
  }
  else
  {
    cout << min_sum-2;
  }
  
  return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: usize,
        Hs: [i64; N],
    }

    // 足場dp_cost[i] : 足場(i+1)に到達するのに必要な最小のコスト
    let mut dp_cost = vec![0i64; N];

    for j in 1..N {
        let cand1 = dp_cost[j - 1] + (Hs[j] - Hs[j - 1]).abs();
        let cand2 = if j as i64 - 2 >= 0 {dp_cost[j - 2] + (Hs[j] - Hs[j - 2]).abs()} else {std::i64::MAX};
        dp_cost[j] = std::cmp::min(cand1, cand2);
    }

    let ans = dp_cost[N - 1];
    println!("{}", ans);
}


Measured memory_bytes: 3968
{-# LANGUAGE BangPatterns #-}


import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import System.IO

main :: IO ()
main = do
  x <- read <$> getLine :: IO Int
  putStrLn $ "Christmas" ++ case x of
                              24 -> " Eve"
                              23 -> " Eve Eve"
                              22 -> " Eve Eve Eve"
                              25 -> ""

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

int main()
{
    int n;
    int x;
    int t;

    cin >> n >> x >> t;

    int ans;
    if (n % x == 0)
    {
        ans = n / x;
    }
    else
    {
        ans = n / x + 1;
    }

    cout << ans * t << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cout(n/3);
}

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

using namespace std;

int main() {
	int n;

	while (cin >> n, n) {
		bool c_flag = false;
		map< char, vector<int> > m;
		vector<char> v;

		map< char, int > c1, c2;

		for (int i = 0; i < n; ++i) {
			string str; cin >> str;
			m[str[0]].push_back(i);
			v.push_back(str[str.size()-1]);

			++c1[str[0]], ++c2[str[str.size()-1]];
		}

		for (char k = 'a'; k <= 'z'; ++k)
			if (c1[k] != c2[k]) {
				cout << "NG" << endl;
				c_flag = true;
				break;
			}

		if (c_flag) continue;

		vector<bool> used;
		for (int i = 0; i < n; ++i)
			used.push_back(false);

		queue<int> que; que.push(0);
		while ( !que.empty() ) {
			int pos = que.front(); que.pop();

			if (used[pos]) continue;

			used[pos] = true;

			for (int i = 0; i < m[v[pos]].size(); ++i)
				que.push(m[v[pos]][i]);
		}

		for (int i = 0; i < n; ++i)
			if (!used[i]) {
				cout << "NG" << endl;
				c_flag = true;
				break;
			}

		if (c_flag) continue;

		cout << "OK" << endl;
	}
}

Measured memory_bytes: 1004
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,m,x;cin>>n>>m>>x;
    int a[n+1];for(int i = 0;i<n+1;i++){a[i]= 0;}
    for(int i = 0;i<m;i++){
    	int am;cin>>am;
        a[am-1] = 1; 
    }
    int gg = 0;
    int sg = 0;
    for(int i = x;i<n+1;i++){
    	gg += a[i];
    }
    for(int i = 0;i<x;i++){
    	sg+=a[i];
    }
    cout<<min(sg,gg);
    return 0;
}

Measured memory_bytes: 3124
// Created by sz
#include <bits/stdc++.h>
using namespace std;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+1>=c)cout<<b+c;
    else cout<<a+2*b+1;
    
    cout<<endl;
    

    
    return 0;
}



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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();}
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);}
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}
 

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n;
    cin>>n;
    Vi a(n+1);
    a[0]=0;
    REP(i,1,n+1) cin>>a[i];

    map<Pii,int> ma;
    REP(i,0,n+1){
        ma[mp(i,i+1)]=abs(a[i]-a[(i+1)%(n+1)]);
    }
    REP(i,0,n+1){
        ma[mp(i,i+2)]=abs(a[i]-a[(i+2)%(n+1)]);
    }

    int allcost=0;
    REP(i,0,n+1){
        allcost += abs(a[i]-a[(i+1)%(n+1)]);
    }
    REP(i,1,n+1){
        cout<<allcost-(ma[mp(i-1,i)]+ma[mp(i,i+1)])+ma[mp(i-1,i+1)]<<endl;
    }
    return 0;
}


Measured memory_bytes: 14592
package main

import (
	"fmt"
	"math"
)

func Traveling(array [][3]int,N int) string{
	for i:=1; i < N+1 ; i++ {
		distx := int(math.Abs(float64(array[i][1] - array[i-1][1])))
		disty := int(math.Abs(float64(array[i][2] - array[i-1][2])))
		time  := array[i][0] - array[i-1][0]
		if (time - distx - disty) % 2 != 0  ||  (time - distx - disty) < 0 {
			return "No"
		}
	}
	return "Yes"
}

func main() {
	var N int
	fmt.Scan(&N)
        array := [][3]int{{0,0,0}}

        for i:=0; i < N; i ++ {
		var t int
		var x int
		var y int
                fmt.Scan(&t)
                fmt.Scan(&x)
                fmt.Scan(&y)
		locate:= [3] int{t,x,y}
                array = append(array,locate)

        }
        fmt.Println(Traveling(array,N))

}

Measured memory_bytes: 12544