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

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}


vlint base_3(int k){
    vlint ret;
    while (k > 0){
        ret.pb(k % 3);
        k /= 3;
    }
    reverse(all(ret));
    return ret;
}

int main(){
    INT(x);
    print(Yes[x >= 30]);
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M; cin >> N >> M;
  vector<int> H(N + 1); for(int i = 1; i <= N; ++i) cin >> H.at(i);
  vector<int> A(M), B(M); REP(i, M) cin >> A.at(i) >> B.at(i);

  vector<int> ans(N + 1);
  for(int i = 1; i <= N; ++i) ans.at(i) = 0;

  REP(i, M) {
    ans[A.at(i)] = max(ans[A.at(i)], H[B.at(i)]);
    ans[B.at(i)] = max(ans[B.at(i)], H[A.at(i)]);
  }

  int cnt = 0;
  for(int i = 1; i <= N; ++i) {
    if(H.at(i) > ans.at(i)) cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 4836
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main()
{
    int i, j, k;
    int n, t, m;
    string s;
    cin >> s;
    if(s.length() == 6 && s[2] == s[3] && s[4] == s[5]) {
        puts("Yes");
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
	string s;
	cin>>s;
	if (s[2]==s[3] && s[4]==s[5])
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
#define mod 1000000007
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;


int main(){
    long long  n,m;
    long long b_max=-1;
    long long a[100000],b[100000],c[100000];
    
    cin>>n>>m;
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);

    vector<pair<long long,long long >> p(m);
    rep(i,m){
        cin>>b[i]>>c[i];
        p[i]=make_pair(c[i],b[i]);
    }
    sort(p.begin(),p.end(),greater<pair<long long ,long long>>());
    vector <long long> v(n);
    long long n_sum=0;
    rep(i,m){
        rep(j,p[i].second){
            v.push_back(p[i].first);
            n_sum++;
            if(n_sum>=n)break;
        }
        if(n_sum>=n)break;
    }
    for(int i=0;i<=n;i++){
        v.push_back(a[i]);
    }

    sort(v.begin(),v.end(),greater<long long>());
    long long s=0;
    rep(i,n)s+=v[i];
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 8176
#include <iostream>
#include <cmath>

using namespace std;

main(){
  int a, b, n;
  while(cin >> a >> b >> n){
    int ans=0;
    a*=10;
    for(int i=0;i<n;i++){
      ans+=(a/b)%10;
      a%=b;
      a*=10;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void) {
   int t;
   scanf("%d",&t);
   
   
   int n=t%10;
   if(n==2||n==4||n==5||n==7||n==9)
   printf("hon\n");
    if(n==0||n==1||n==6||n==8)
   printf("pon\n");
   if(n==3)
   printf("bon\n");
}



Measured memory_bytes: 1624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

int n;
int v[100010];
int numCount[100010];


struct Elem
{
	int num;
	int count;
};

std::vector<Elem> numsOdd;
std::vector<Elem> numsEven;

bool compare(const Elem &a, const Elem &b)
{
	if (a.count == b.count)
		return a.num < b.num;
	else
		return a.count < b.count;
}


int main()
{
	scanf("%d", &n);
	
	for (int i = 0 ; i < n ; i++)
		scanf("%d", &(v[i]));
		
	memset(numCount, 0, sizeof(numCount));
	for (int i = 0 ; i < n ; i+=2)
		numCount[v[i]]++;
		
	for (int i = 1 ; i <= 100000  ; i++)
	{
		Elem newNum;
		newNum.count = n / 2 - numCount[i];
		newNum.num = i;
		numsOdd.push_back(newNum);
	}
	sort(numsOdd.begin(), numsOdd.end(), compare);		
	
	memset(numCount, 0, sizeof(numCount));
	for (int i = 1 ; i < n ; i+=2)
		numCount[v[i]]++;
		
	for (int i = 1 ; i <= 100000  ; i++)
	{
		Elem newNum;
		newNum.count = n / 2 - numCount[i];
		newNum.num = i;
		numsEven.push_back(newNum);
	}
	sort(numsEven.begin(), numsEven.end(), compare);		
	
	int ans;
	if (numsEven[0].num != numsOdd[0].num)
	{
		ans = numsEven[0].count + numsOdd[0].count;
	}
	else
	{
		ans = numsEven[0].count + numsOdd[1].count;
		
		int other = numsEven[1].count + numsOdd[0].count;
		if (other < ans)
			ans = other;
	}
	
	printf("%d\n", ans);
	
	
	return 0;
}

Measured memory_bytes: 3316
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int *a, *b;
	a = (int*)malloc(sizeof(int)*M);
	b = (int*)malloc(sizeof(int)*M);
	for (int i = 0;i < M;i++)cin >> a[i] >> b[i];
	int d[51][51] = { 0 };
	int num[51] = { 0 };
	for (int i = 0;i < M;i++) {
			d[a[i]][b[i]]=1;
			d[b[i]][b[i]]=1;
			num[a[i]]+= d[a[i]][b[i]];
			num[b[i]] += d[a[i]][b[i]];
	}
	for (int i = 1;i <= N;i++)cout << num[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n,m,ans=0;
vector <int> a[2][2002];
char c[2002][2002];
int main(){
	for (int i=0;i<2;i++) for (int j=0;j<2002;j++) a[i][j].push_back(0);  
	cin>>n>>m;
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			cin>>c[i][j];
			if (c[i][j]=='#'){
				a[0][i+1].push_back(j+1);
				a[1][j+1].push_back(i+1);  
			}
		}
	}
	for (int j=0;j<2002;j++) a[0][j].push_back(m+1),a[1][j].push_back(n+1); 
	for (int i=0;i<2002;i++) sort(a[0][i].begin(),a[0][i].end());
	for (int i=0;i<2002;i++) sort(a[1][i].begin(),a[1][i].end());
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if (c[i-1][j-1]!='#'){
		int a1=lower_bound(a[0][i].begin(),a[0][i].end(),j)-a[0][i].begin();
		int res=a[0][i][a1]-a[0][i][a1-1]-1;
		int b1=lower_bound(a[1][j].begin(),a[1][j].end(),i)-a[1][j].begin();
		res+=a[1][j][b1]-a[1][j][b1-1]-1;
		ans=max(ans,res-1);
	}
	cout<<ans;
}

Measured memory_bytes: 38272
// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define int             long long
#define ld              long double
#define ll              long long
#define pb              push_back
#define fi              first
#define se              second
// #define mod             1000000007  //998244353// 1e9 + 7
int mod = 1e9;
int modd = 1e9;
#define inf             1000000007 // 1e9 + 7
#define MAX             8000000000000000064LL
#define MIN            -8000000000000000064LL
#define MAXN 			10000004
#define mt 				make_tuple
#define eps             1e-6
#define endl			'\n'
#define test            int t; cin>>t; while(t--)
#define fast_io         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define tree            tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
// int fact[1000007]={0};
// int spf[(int)(1e7) + 20];
// bool prime[(int)((1e7) + 20)];
// int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
// void sp(int n){spf[1]=1;for(int i=2;i<n;i++)spf[i]=i;for(int i=4;i<n;i+=2)spf[i]=2;for(int i=3;i*i<n;i++){if(spf[i]==i){for(int j=i*i;j<n;j+=i)if(spf[j]==j)spf[j]=i;}}}
// void sieve(int n){memset(prime,true,sizeof(prime) );for(int p=2;p*p<=n;p++){if(prime[p]==true)for(int i=p*p;i<=n;i+=p)prime[i]=false;}prime[0]=false;prime[1]=false;}
// int xyp(int x,int y){int res=1;while(y>0){if(y%2==1) res=(res*x)%mod;x=(x*x)%mod;y/=2;}return res%mod;}
// int inv(int x){return xyp(x,mod - 2);}
// int inv_euclid(int a, int m = mod){int m0 = m;int y = 0, x = 1;if (m == 1)return 0;while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
// void init() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
// int ncr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[r],mod-2)))%mod; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res;}
// int npr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res; }
// bool isp(int a){if(a == 2)return true;if(a == 1)return false;for(int x= 2; x <= sqrt(a) + 1; x++)if(a % x == 0)return false;return true;}
// int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
// int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
// int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
// #define p_set tree< pair<int,int> ,  null_type ,  less<pair<int,int>> ,  rb_tree_tag ,  tree_order_statistics_node_update>
// #define i_set tree< int ,  null_type ,  less< int > ,  rb_tree_tag ,  tree_order_statistics_node_update>
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// int dx[] = {1, -1, 0};
// int dy[] = {1, -1, 0};
signed main()
{
	fast_io
	ld r;
	cin >> r; 
	r *= 2.00000000000000*acos(-1);
	cout << fixed << setprecision(10) << r << endl;
}

Measured memory_bytes: 3808
#include <iostream>

int main(){
    std::string s;
    std::cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" <<  std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
A, V = [int(_) for _ in input().split()]
B, W = [int(_) for _ in input().split()]
T = int(input())

if V <= W:
    print("NO")
else:
    X = abs(A - B)
    Y = V - W
    if X > Y * T:
        print("NO")
    else:
        print("YES")


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

int main() {
    int n;
    cin >> n;
    cin.ignore();
    while (n--) {
        string line;
        getline(cin, line);
        string trainCars = "";
        trainCars += line[0];
        line.erase(0, 1);
        int i = 0;
        while (line.empty() == false) {
            if (line.substr(0, 2) == "->") {
                i++;
            } else {
                i--;
            }
            line.erase(0, 2);
            if (i == -1) {
                trainCars.insert(0, 1, line[0]);
                i = 0;
            } else if (i == (int) trainCars.length()) {
                trainCars += line[0];
            }
            line.erase(0, 1);
        }
        cout << trainCars << endl;
    }
}

Measured memory_bytes: 0
import kotlin.math.*
fun list() = readLine()!!.split(" ").map {it.toLong()}

fun main() {
	val (x,k,d) = list()
	val t = abs(x)/d

	if(t<=k) {
		abs(abs(x)-d*(t+(k-t)%2))
	} else {
		abs(x)-d*k
	}.let {println(it)}
}


Measured memory_bytes: 36500
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = NextInt();
        int C = NextInt();
        List<int[]> D = new List<int[]>();
        List<int[]> c = new List<int[]>();
        for (int i = 0; i < C; i++) D.Add(LineInt());
        for (int i = 0; i < N; i++) c.Add(LineInt());
        //WF
        int[,] WF = new int[C, C];
        for (int i = 0; i < C; i++)
            for (int j = 0; j < C; j++) WF[i, j] = INF;
        for (int i = 0; i < C; i++)
            for (int j = 0; j < C; j++) WF[i, j] = D[i][j];
        //for (int x = 0; x < C; x++)
        //    for (int s = 0; s < C; s++)
        //        for (int t = 0; t < C; t++)
        //            WF[s, t] = Math.Min(WF[s, t], WF[s, x] + WF[x, t]);
        Dictionary<int, int>[] d = new Dictionary<int, int>[3];
        d[0] = new Dictionary<int, int>();
        d[1] = new Dictionary<int, int>();
        d[2] = new Dictionary<int, int>();
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
            {
                if (!d[(i + j) % 3].ContainsKey(c[i][j] - 1)) d[(i + j) % 3][c[i][j] - 1] = 0;
                d[(i + j) % 3][c[i][j] - 1]++;
            }
        long ans = INF;
        for (int x = 0; x < C; x++)
            for (int y = 0; y < C; y++)
                for (int z = 0; z < C; z++)
                {
                    if (x == y || y == z || z == x) continue;
                    //%=0 : x   %=1 : y %=2 : z とする
                    //それぞれの色をxyzに変えていく
                    int cost = 0;
                    foreach (var e in d[0])
                        if (e.Key != x) cost += e.Value * WF[e.Key, x];
                    foreach (var e in d[1])
                        if (e.Key != y) cost += e.Value * WF[e.Key, y];
                    foreach (var e in d[2])
                        if (e.Key != z) cost += e.Value * WF[e.Key, z];
                    ans = Math.Min(cost, ans);
                }
        Console.WriteLine(ans);
    }

}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 20932
//minamoto
#include<bits/stdc++.h>
#define R register
#define int unsigned int
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int P,D,LL;
inline void upd(R int &x,R int y){x+=y,x-=P*D*(x>>30),x%=P;}
inline int add(R int x,R int y){return x+=y,x-=P*D*(x>>30),x%=P;}
inline int mul(R int x,R int y){return 1ull*x*y-1ull*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
const int N=105;
int f[N][N][N][2],coef[N][N][N][2],bn[N][N];
int n,m,L,ret,cp;
signed main(){
//	freopen("testdata.in","r",stdin);
    scanf("%u%u%u%u",&n,&m,&L,&P);
    D=(1<<30)/P;
    fp(i,0,max(n,m)){
        bn[i][0]=1;
        fp(j,1,i)bn[i][j]=add(bn[i-1][j],bn[i-1][j-1]);
    }
    fp(k,1,L)fp(i,0,m){
        cp=mul(ksm(L-k+1,i),add(ksm(k,m-i),P-ksm(k-1,m-i)));
        ret=1;
        fp(j,0,n)coef[k][i][j][0]=ret,ret=mul(ret,cp);
    }
    fp(k,1,L)fp(i,0,n){
        cp=mul(add(ksm(L-k+1,i),P-ksm(L-k,i)),ksm(k,n-i));
        ret=1;
        fp(j,0,m)coef[k][i][j][1]=ret,ret=mul(ret,cp);
    }
    f[1][0][0][0]=1;
    fp(k,1,L)fp(i,0,n)fp(j,0,m){
        ret=f[k][i][j][0];
        fp(l,0,n-i)upd(f[k][i+l][j][1],1ull*ret*bn[n-i][l]%P*coef[k][j][l][0]%P);
        ret=f[k][i][j][1];
        fp(l,0,m-j)upd(f[k+1][i][j+l][0],1ull*ret*bn[m-j][l]%P*coef[k][i][l][1]%P);
    }
    printf("%u\n",f[L+1][n][m][0]%P);
    return 0;
}

Measured memory_bytes: 18048
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  string s; cin >> s;
  bool cond1 = (s.size()%2 == 0);
  bool cond2 = (s[0] == s[s.size()-1]);
  if(cond1^cond2) cout << "Second" << endl;
  else cout << "First" << endl;
  
  return 0;
}

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

int main()
{
    int k,a,b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
#define MOD 1000000007
#define B2 100000007
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
#define P pair<int,int>
ll n,a,ans = 0,c,x,y,t;
string s;
int main() {
    cin >> s; vector<ll> al(26,0);
    n = s.size();
    rep(i, s.size()) {
        al[s[i] - 'a']++;
    }rep(i, 26) {
        ans += al[i] * (al[i] - 1) / 2;
    }cout << n * (n - 1) / 2 - ans + 1 << endl;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;cin>>S;
    stack<char> a;
    for(int i=0;i<S.size();i++){
        if(a.size()&&a.top()==S.at(i)-1)a.pop();
        else a.push(S.at(i));
    }cout<<a.size();
}

Measured memory_bytes: 644
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	counter := 0
	for a := 1; a <= 9; a++ {
		for b := 1; b <= 9; b++ {
			counter += count(n, a, b) * count(n, b, a)
		}
	}

	fmt.Printf("%d\n", counter)
}

func count(bound, l, r int) int {
	c := 0
	for i := 1; i <= bound; i++ {
		t := i
		for t >= 10 {
			t /= 10
		}
		if t == l && i%10 == r {
			c++
		}
	}
	return c
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

bool flg[100005][27];
vector<int> G[100005];
	
int V,E;
char A[100005]={0};

int main()
{
	scanf("%d%d\n",&V,&E);
	for(int i=0;i<V;i++)
	{
		scanf("%c%*c",&A[i]);
	}
	for(int i=0;i<E;i++)
	{
		int s,t;
		scanf("%d%d",&s,&t);
		G[s].push_back(t);
		G[t].push_back(s);
	}
	for(int i=0;i<V;i++)
	{
		if(A[i]!='?')flg[i][A[i]-'a']=1;
	}
	for(int i=0;i<V;i++)
	{
		if(A[i]=='?')
		{
			for(char x='a';x<='z';x++)
			{
				int j;
				for(j=0;j<G[i].size();j++)
				{
					if(flg[G[i][j]][x-'a'])break;
				}
				if(j==G[i].size())
				{
					A[i]=x;
					flg[i][x-'a']=1;
					break;
				}
			}
		}
	}
	puts(A);
}


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}


signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    vector<int> b(n);
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    vector<int> c(n);
    for(int i=0; i<n; i++){
        cin >> c[i];
    }
    // sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    vector<int> c_gt_b(n);

    for(int i=0; i<n; i++){
        auto it = upper_bound(c.begin(), c.end(), b[i]);
        int idx = distance(c.begin(), it);
        c_gt_b[i] = n-idx;
    }
    int ans = 0;

    for(int i=n-2; i>=0; i--){
        c_gt_b[i] += c_gt_b[i+1];
    }

    for(int i=0; i<n; i++){
        auto it = upper_bound(b.begin(), b.end(), a[i]);
        int idx = distance(b.begin(), it);
        ans += c_gt_b[idx];
    }
    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 6468
from collections import deque

class Edge:
	def __init__(self, t, w):
		self.to = t
		self.ew = w

class Graph:
	def __init__(self, N):
		self.nw = [-1] * N
		self.al = [[] for i in range(N)]

	def add_edge(self, fr, to, weight):
		self.al[fr].append(Edge(to, weight))
		self.al[to].append(Edge(fr, -weight))

	def dfs(self, s, used):
		self.nw[s] = 0
		q = deque([s])
		used.add(s)
		while q:
			h = q.popleft()
			for e in self.al[h]:
				if e.to in used:
					if self.nw[h] + e.ew != self.nw[e.to]:
						return False
					continue
				used.add(e.to)
				self.nw[e.to] = self.nw[h] + e.ew
				q.appendleft(e.to)
		return True


def main():
	N, M = map(int, input().split())
	graph = Graph(N)
	for i in range(M):
		l, r, d = map(int, input().split())
		graph.add_edge(l - 1, r - 1, d)

	used = set()
	for i in range(N):
		if i in used or graph.dfs(i, used):
			continue
		print("No")
		break
	else:
		print("Yes")


if __name__ == "__main__":
	main()


Measured memory_bytes: 111128
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::array<i64, 5> x;
  tools::read(x);
  std::cout << std::distance(x.begin(), std::find(x.begin(), x.end(), 0)) + 1 << std::endl;
  return 0;
}

Measured memory_bytes: 3580
n=int(input())
a=list(map(int,input().split()))
m=0
ans=0
for i in range(n-1):
    if a[i]>=a[i+1]:
        ans+=1
    else:
        m=max(m,ans)
        ans=0
m=max(m,ans)
print(m)
    


Measured memory_bytes: 20396
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
count :: (a -> Bool) -> [a] -> Int
count = (length .) . filter
-- end of templete

primes = runSTUArray $ do
    arr <- newArray (2,10000) True :: ST s (STUArray s Int Bool)
    forM [2..100] $ \p -> do
        c <- readArray arr p
        when c $ do
            forM_ [p*2,p*3..10000] $ flip (writeArray arr) False
    return arr

twinPrimes = [(p-2, p) | p <- [5..10000], primes!p, primes!(p-2)]

main = takeWhile (/=0) . map readInt . lines <$> getContents >>= mapM_ (\n -> let (p, q) = last $ takeWhile ((<=n) . snd) twinPrimes in putStrLn $ show p ++ " " ++ show q)


Measured memory_bytes: 5548
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define int long long
#define mpr make_pair 
typedef long long ll;
#pragma GCC optimize("Ofast")

const int maxn = 3e5+10;
const int N = 1e6+5;
const int mod = 998244353;
const int inf = 1e9+10;

int n, k;
int a[maxn], pos[maxn];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n;
    for(int i = 1; i <= n; i++)
    {
        cin>> a[i];
        pos[a[i]] = i;
    }

    int ans = n-1, d = 1;
    for(int i = 2; i <= n; i++)
    {
        if(pos[i] > pos[i-1]) d++;
        else d = 1;
        ans = min(ans,n-d);
    }
    cout<< ans;
}





Measured memory_bytes: 3840
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int r, d, x[20];
    cin >> r >> d >> x[0];
    for (int i = 0; i < 10; ++i) {
        x[i+1] = x[i]*r - d;
    }

    for (int i = 0; i < 10; ++i) {
        cout << x[i+1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int n, max_cnt, cnt;

int next(int pos) {
    int i = pos / n, j = pos % n;
    if (j + 1 < i) return i * n + j + 1;
    else if (i == n - 1) return -1;
    else return (i + 1) * n + 0;
}

void dfs(int pos, vvi wl, vi cnt_w, vi cnt_l) {
    if (pos == -1) {
        cnt++;
        return;
    }
    int i = pos / n, j = pos % n;
    if (wl[i][j] == 0) {
        if (cnt_w[i] < max_cnt && cnt_l[j] < max_cnt) {
            wl[i][j] = 1; cnt_w[i]++;
            wl[j][i] = -1; cnt_l[j]++;
            dfs(next(pos), wl, cnt_w, cnt_l);
            wl[i][j] = 0; cnt_w[i]--;
            wl[j][i] = 0; cnt_l[j]--;
        }
        if (cnt_l[i] < max_cnt && cnt_w[j] < max_cnt) {
            wl[j][i] = 1; cnt_w[j]++;
            wl[i][j] = -1; cnt_l[i]++;
            dfs(next(pos), wl, cnt_w, cnt_l);
            wl[j][i] = 0; cnt_w[j]--;
            wl[i][j] = 0; cnt_l[i]--;
        }
    } else {
        bool ok = cnt_w[i] <= max_cnt && cnt_l[i] <= max_cnt;
        ok &= cnt_w[j] <= max_cnt && cnt_l[j] <= max_cnt;
        if (ok) dfs(next(pos), wl, cnt_w, cnt_l);
    }
}

int main() {
    while (cin >> n, n) {
        max_cnt = (n - 1) / 2;
        cnt = 0;
        vvi wl(n, vi(n, 0));
        vi cnt_w(n), cnt_l(n);
        int m; cin >> m;
        while (m--) {
            int x, y; cin >> x >> y; x--, y--;
            wl[x][y] = 1; cnt_w[x]++;
            wl[y][x] = -1; cnt_l[y]++;
        }
        dfs(next(0), wl, cnt_w, cnt_l);
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3180
package main

import (
	"bufio"
	. "fmt"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	r := bufio.NewReader(os.Stdin)
	o := bufio.NewWriter(os.Stdout)
	var n, m, v, w int
	Fscan(r, &n, &m)
	g := make([][]int, n+1)
	for ; m > 0; m-- {
		Fscan(r, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	a := make([]int, n+1)
	c := 1
	s := make([]bool, n+1)
	s[1] = true
	q := []int{1}
	for len(q) > 0 {
		v, q = q[0], q[1:]
		for _, w := range g[v] {
			if !s[w] {
				s[w] = true
				c++
				a[w] = v
				q = append(q, w)
			}
		}
	}
	if c < n {
		Fprint(o, "No")
		return
	}
	Fprintln(o, "Yes")
	for _, v := range a[2:] {
		Fprintln(o, v)
	}
	o.Flush()
}


Measured memory_bytes: 17748
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <tuple>

int f(intmax_t H, intmax_t W) {
  intmax_t res = std::min(H, W);
  for (intmax_t i = 1; i < H; ++i) {
    intmax_t a = i * W;
    intmax_t b = intmax_t(H-i) * (W / 2);
    intmax_t c = intmax_t(H) * W - (a+b);

    intmax_t min, max;
    std::tie(min, max) = std::minmax({a, b, c});
    res = std::min(res, max-min);
  }
  return res;
}

int main() {
  int H, W;
  scanf("%d %d", &H, &W);

  if (H % 3 == 0 || W % 3 == 0) return puts("0"), 0;
  printf("%d\n", std::min({H, W, f(H, W), f(W, H)}));
}


Measured memory_bytes: 128
/*
  Longest Common Subsequence problem
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 1001

int max(int, int);
int LCSLength(char x[], char y[], int, int);

int main()
{
  int i, q, *res;
  char x[MAX_LEN], y[MAX_LEN];

  scanf("%d", &q);
  res = (int *)malloc( sizeof(int) * q );

  for( i = 0; i<q; i++ )
    {
      scanf("%s%s", x, y);
      res[i] = LCSLength(x, y, strlen(x), strlen(y));          /*　最長共通部分列の長さを求める　*/
    }

  /*　各データセットの最長共通部分列の長さを出力　*/
  for( i = 0; i<q; i++ )
    printf("%d\n", res[i]);
  
  return 0;
}


/* int型整数 a,b　の大きい方を求めて返す関数　*/
int max(int a, int b)
{
  if( a >= b )
    return a;
  else
    return b;
}


/*　文字列xとyの最長共通部分列の長さを求めて返す関数　*/
int LCSLength(char x[], char y[], int x_len, int y_len)
{
  int i, j, c[x_len+1][y_len+1], max_len = 0;

  /*　cの0行目と0列目を０で初期化　*/
  for( i = 1; i<=x_len; i++ )
    c[i][0] = 0;
  for( j = 0; j<=y_len; j++ )
    c[0][j] = 0;

  /* c[i][j]を求める　*/
  for( i = 1; i<=x_len; i++ )
    {
      for( j = 1; j<=y_len; j++ )
	{
	  if( x[i-1] == y[j-1] )
	    c[i][j] = c[i-1][j-1] + 1;
	  else if( c[i-1][j] >= c[i][j-1] )
	    c[i][j] = c[i-1][j];
	  else
	    c[i][j] = c[i][j-1];

	  max_len = max(max_len, c[i][j]);
	}
    }
  
  return max_len;
}



Measured memory_bytes: 5652
/*
*                                 Name : chaitanya
*
*                         Institute : ANITS,Visakhapatnam
*   "Don't regret anything you do, because in the end it makes you who you are."
*
*/
#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>
#include<sstream>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;

int main()
{

    int n,c = 0;
    cin >> n;
    for (int i = 1; i <= n ; i++)
    {
        int a;
        cin >> a;
        if( a%2 != 0 && i%2 != 0)
        {
            c++;
        }
   }
    cout << c;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
#prod = functools.partial(functools.reduce, operator.mul)
#c=np.array(A)
#p=np.prod(A)
c=1
if 0 in A:
    print(0)
    exit()
for i in A:
    c=c*i
    if c>10**18:
        print(-1)
        exit()
print(c)


Measured memory_bytes: 21788
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>


#include <map>

using namespace std;

typedef long long LL;

int n, a, b;

int main() {
    cin >> n;
    if (n - 1) { cin >> a >> b; cout << a+b << endl; }
    else cout << "Hello World";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# E-LCS: Longest Common Subsequence


'''
axyb
abyxb
'''

import sys

sys.setrecursionlimit(4000)
S = input()
T = input()

lcs = [[0] * (len(T) + 1) for i in range(len(S) + 1)]

for i in range(1, len(S) + 1):
    for j in range(1, len(T) + 1):
        if S[i - 1] == T[j - 1]:
            x = 1
        else:
            x = 0
        lcs[i][j] = max(lcs[i - 1][j - 1] + x, lcs[i - 1][j], lcs[i][j - 1])

# print(lcs)


def print_lcs (S, T, lcs, i, j):
    global ans
    if (i == 0 or j == 0):
        return
    if (S[i - 1] == T[j - 1]):
        print_lcs(S, T, lcs, i - 1, j - 1)
        ans.append(S[i - 1])
    else:
        if lcs[i-1][j] >= lcs[i][j-1]:
            print_lcs(S, T, lcs, i - 1, j)
        else:
            print_lcs(S, T, lcs, i, j - 1)


ans = []
print_lcs(S, T, lcs, len(S), len(T))
print("".join(ans))


Measured memory_bytes: 115932
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main(){
	long long n,ma=-1e10,mi=1e10,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		mi=mi<a?mi:a;
		ma=ma>a?ma:a;
	}
	 cout<<ma-mi;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0){
                break;
        }else if(x>y){
            printf("%d %d\n",y,x);
        }else{
            printf("%d %d\n",x,y);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

const int MAX = 10001000;
bool prime[MAX];
vector<int> Era(int n = MAX)
{
	vector<int> res;
	prime[0] = prime[1] = false;
	for (int i = 2; i < n; ++i)prime[i] = true;
	for (int i = 2; i < n; ++i)
	{
		if (prime[i])
		{
			res.push_back(i);
			for (int j = i + i; j < n; j += i)prime[j] = false;
		}
	}
	return res;
}

int main()
{
	Era();
	int q; cin >> q;
	vector<int> sum(MAX, 0);
	for (int i = 2; i < MAX; ++i)
	{
		sum[i + 1] = sum[i];
		if (i % 2 == 1 && prime[i] && prime[(i + 1) / 2])++sum[i + 1];
	}
	while (q--)
	{
		int l, r; cin >> l >> r;
		cout << sum[r + 1] - sum[l] << endl;
	}
}

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

using namespace std;

bool solve() {
    int N, M, T, P;
    cin >> N >> M >> T >> P;
    if (N == 0) return false;

    vector<vector<int>> card(500, vector<int>(500, 0));
    for (int x = 0; x < N; ++x) {
        for (int y = 0; y < M; ++y) {
            card[x][y] = 1;
        }
    }

    int l = 0, u = 0;
    for (int q = 0; q < T; ++q) {
        int d, c;
        cin >> d >> c;
        if (d == 1) {
            for (int x = 0; x < c; ++x) {
                for (int y = 0; y < M; ++y) {
                    card[l + 2 * c - 1 - x][u + y] += card[l + x][u + y];
                    card[l + x][u + y] = 0;
                }
            }
            l += c;
            N = max(c, N - c);
        } else {
            for (int x = 0; x < N; ++x) {
                for (int y = 0; y < c; ++y) {
                    card[l + x][u + 2 * c - 1 - y] += card[l + x][u + y];
                    card[l + x][u + y] = 0;
                }
            }
            u += c;
            M = max(c, M - c);
        }
    }

    for (int q = 0; q < P; ++q) {
        int x, y;
        cin >> x >> y;
        cout << card[l + x][u + y] << endl;
    }

    return true;
}

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



Measured memory_bytes: 3880
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	double cur = 0;
	int n;
	cin >> n;
	while (n--) {
		int x;
		cin >> x;
		cur += (double)1 / x;
	}
	cout << fixed << setprecision(15);
	cout << 1 / cur << endl;
} 


Measured memory_bytes: 256
#include <stdio.h>

#define MOD 1000000007

long long powerl (long long x, int n) {
	if (n==0)
		return 1;
	if (n==1)
		return x;
	long long tmp = powerl (x, n/2);
	if (n%2)
		return tmp*tmp*x % MOD;
	return tmp*tmp % MOD;
}

int main () {
	int N, flag=1;
	int arr[100000];
	for (int i=0; i<100000; i++)
		arr[i] = 0;
	scanf ("%d", &N);
	for (int i=0; i<N; i++) {
		int tmp;
		scanf ("%d", &tmp);
		if (tmp==0) {
			if (arr[0]>0 || N%2==0)
				flag=0;
			else
				arr[0] ++;
		} else {
			if (arr[tmp]<2) 
				arr[tmp] ++;
			else
				flag = 0;
		}
	}
	if (flag)
		printf ("%lld\n", powerl (2,N/2));
	else
		printf ("0\n");
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vector<vector<int> > mp;
int w, h;


void hoge(int wo, int ho) {
	mp[wo][ho] = 0;
	REP(i, 8) {
		int nw = wo + qx[i];
		int nh = ho + qy[i];
		if(nw >= 0 && nw < w && nh >= 0 && nh < h && mp[nw][nh] == 1) hoge(nw, nh);
	}
}
int main(void) {
	while(true) {
	ll count = 0;
	cin>>w>>h;
		if(w == 0 && h == 0) return 0;
		swap(w, h);
	mp.resize(w);
	REP(i, w) mp[i].resize(h);
	REP(i, w) {
		REP(j, h) {
			cin>> mp[i][j];
		}
	}
	REP(i, w) {
		REP(j, h) {
			if(mp[i][j] == 1) {
				count++;
				hoge(i, j);
			}
		}
	}
	cout<<count<<endl;
}
}

Measured memory_bytes: 3140
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"


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

    int n; cin >> n;
    vector<vector<ll>> edges(n);
    for_(i, 0, n-1) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        edges[a-1].push_back(b-1);
    }

    ll ans = 0;
    for__(i, 1, n+1) ans += i * (n-i+1);
    for__(i, 0, n) for (auto j: edges[i]) {
        ans -= (i+1) * (n-j);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14260
package main
import "fmt"

func main() {
  var s, t string
  var a, b int
  var u string
  fmt.Scan(&s, &t)
  fmt.Scan(&a, &b)
  fmt.Scan(&u)

  if u == s {
    a--
  } else if u == t {
    b--
  }
  fmt.Println(a, b)
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 998244353;
// int MOD = 1000000007;
ll M;
//matrix
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

vec matmul(vec &dp,mat &mt){ // ret = Mv;
    ll m = dp.size();
    vec ret(m,0);
    rep(i,m){
        rep(j,m){
            ret[i] += (mt[i][j]*dp[j])%M;
            ret[i] %= M;
        }
    }
    return ret;
}

mat update(mat &mt){ //ret = M^2
    int m = mt.size();
    mat ret(m,vec(m,0));
    rep(i,m) rep(j,m) rep(k,m) ret[i][j] = (ret[i][j] + mt[i][k]*mt[k][j]%M)%M;
    return ret;
}

void matpow(vec &dp,mat &mt,int k){// dp = (M^k)dp
    int m = dp.size();
    while(k){
        if(k&1) dp = matmul(dp,mt);
        mt = update(mt);
        k /= 2;
    }
}

signed main(){

    ll l,a,b;
    cin >> l >> a >> b >> M;

    ll p[19];
    p[0] = 1;
    for(int i = 1;i <= 18;i++) p[i] = 10*p[i-1];

    ll d[20]; // 10^d 以上になる最初のs
    rep(i,19){
        // 条件を満たす最小を求める
        ll ok = l;  //解が存在する値
        ll ng = -1;  //解が存在しない値 

        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(a+b*mid >= p[i]){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        d[i] = ok;
    }
    d[19] = l;

    
    vec dp(3,0);
    dp[1] = a%M;
    dp[2] = 1;
    rep(i,19){
        mat mt(3,vec(3,0));
        mt[0][0] = ((p[i]%M)*10)%M;
        mt[0][1] = mt[1][1] = mt[2][2] = 1;
        mt[1][2] = b%M;
        matpow(dp,mt,d[i+1]-d[i]);
    }

    cout << dp[0]%M << endl;

    //rep(i,19)cerr << i << " " << d[i] << endl;

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc129.contest.atcoder.jp/tasks/abc129_f


Measured memory_bytes: 256
#include<stdio.h>
#define MX 300009
typedef struct LOC {
	int x, y;
}LOC;
LOC loc[MX];
int X[MX], Y[MX], mx_X, mx_Y, num_X, num_Y, num;
int main() {
	int h, w, m;
	scanf("%d%d%d", &h, &w, &m);
	int i;
	for (i = 1; i <= m; i++) {
		scanf("%d%d", &loc[i].x, &loc[i].y);
		++X[loc[i].x], ++Y[loc[i].y];
	}
	for (i = 1; i <= h; i++) {
		mx_X = mx_X > X[i] ? mx_X : X[i];
	}
	for (i = 1; i <= w; i++) {
		mx_Y = mx_Y > Y[i] ? mx_Y : Y[i];
	}
	for (i = 1; i <= h; i++) {
		if (X[i] == mx_X) {
			++num_X;
		}
	}
	for (i = 1; i <= w; i++) {
		if (Y[i] == mx_Y) {
			++num_Y;
		}
	}
	for (i = 1; i <= m; i++) {
		if (X[loc[i].x] == mx_X && Y[loc[i].y] == mx_Y) {
			++num;
		}
	}
	printf("%d", mx_X + mx_Y - (num == (num_X*num_Y) ? 1 : 0));
}

Measured memory_bytes: 6400
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    mountains = {i:'WIN' for i in range(N)}
    for road in range(M):
        if H[A[road]] < H [B[road]]:
            mountains[A[road]] = 'LOSE'
        elif H[A[road]] == H[B[road]]:
            mountains[A[road]] = 'LOSE'
            mountains[B[road]] = 'LOSE'
        elif H[A[road]] > H[B[road]]:
            mountains[B[road]] = 'LOSE'
    count = 0
    for i in range(N):
        if mountains[i] == 'WIN':
            count += 1
    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens)) - 1
        B[i] = int(next(tokens)) - 1
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()


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

int main()
{
  int x, i = 0, k;
  cin >> x;
  do
  {
    i++;
    k = 360 * i % x;
    if (k == 0)
    {
      cout << 360 * i / x << endl;
      break;
    }
  } while (i < 1000);

  return 0;
}

Measured memory_bytes: 3620