akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }


int cnt[10][10];

int main(int argc, char const *argv[]) {
  int n;
  ll ans=0;
  cin >> n;
  for(int i=1; i<=n; i++){
    int x=i;
    while(x>=10) x/=10;
    cnt[x][i%10]++;
  }
  for(int i=1; i<=n; i++){
    int x=i;
    while (x>=10) x/=10;
    ans+=cnt[i%10][x];
  }
  cout << ans << endl;
  return 0;
}


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

int n, k, d, a, cnt;
bool ada[105];

int main(){
	cin>>n>>k;
	for(int i=1; i<=k; i++){
		cin>>d;
		for(int j=1; j<=d; j++){
			cin>>a;
			ada[a]=true;
		}
	}
	for(int j=1; j<=n; j++){
		if(ada[j]==false)cnt++;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3624
mod = 10**9 + 7

n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

sx = 0
sy = 0

for i in range(n):
    sx += (2*i-n+1)*x[i]
    sx %= mod

for j in range(m):
    sy += (2*j-m+1)*y[j]
    sy %= mod

print((sx*sy) % mod)


Measured memory_bytes: 83044
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
const int MAX_N = 2000006;
bool isPrime[MAX_N];
void eratos() {
  for (int i = 0; i < MAX_N; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for (int i = 0; i < MAX_N; i++) {
    if (isPrime[i]) {
      for (int j = i + i; j < MAX_N; j += i) {
        isPrime[j] = false;
      }
    }
  }
}
signed main() {
  eratos();
  vector<int> prime;
  rep(i, MAX_N) if (isPrime[i]) prime.push_back(i);
  int n;
  while (cin >> n, n) {
    if (isPrime[n]) {
      cout << 0 << endl;
    } else {
      auto left = lower_bound(all(prime), n);
      left--;
      auto right = upper_bound(all(prime), n);
      cout << *right - *left << endl;
    }
  }
  return 0;
}



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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }


int main()
{
int N;
cin >> N;

string S1, S2;
cin >> S1 >> S2;

REP(i, N){
    cout << S1.at(i) << S2.at(i);
}
cout << endl;
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	double w=sc.nextDouble();
	double h=sc.nextDouble();
	double x=sc.nextDouble();
	double y=sc.nextDouble();

	int te=0;
	double ans=w*h/2;
	if(w/2==x&&h/2==y){
		te=1;
	}
System.out.print(ans);
System.out.println(" "+te);
	}}

Measured memory_bytes: 24404
import collections
n=int(input())
v=list(map(int,input().split()))

li1=[]
li2=[]

for i in range(n):
    if i%2==0:
        li1.append(v[i])
    else:
        li2.append(v[i])

li1=collections.Counter(li1).most_common()
li2=collections.Counter(li2).most_common()

if li1[0][0]!=li2[0][0]:
    print(n-li1[0][1]-li2[0][1])
else:
    if len(li1)==1 and len(li2)==1:
        print(n//2)
    elif len(li1)==1:
        print(n-li1[0][1]-li2[1][1])
    elif len(li2)==1:
        print(n-li1[1][1]-li2[0][1])
    else:
        print(min(n-li1[0][1]-li2[1][1],n-li1[1][1]-li2[0][1]))

Measured memory_bytes: 20852
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0060
public class Main {
	static Scanner sc = new Scanner(System.in);
	static final double EPS = 1e-8;
	public static void main(String[] args) {
		while (sc.hasNextInt()) {
			int c1 = sc.nextInt(), c2 = sc.nextInt(), c3 = sc.nextInt(), cnt = 0;
			for (int i = 1; i <= 10; i++) {
				if (c1 != i && c2 != i && c3 != i && (c1 + c2 + i) <= 20) {
					cnt++;
				}
			}
			double p = (double)cnt / 7 * 100;
			if (p - EPS > 50.0)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
struct UnionFind{
  vector<int> p;
  int g;
  void init(int n){
    p = vector<int>(n, -1);
    g = n;
  }
  int find(int a){
    return p[a] < 0 ? a : p[a] = find(p[a]);
  }
  bool merge(int a, int b){
    a = find(a);
    b = find(b);
    if(a == b) return 0;
    g--;
    if(p[a] > p[b]) swap(a, b);
    p[a] += p[b];
    p[b] = a;
    return 1;
  }
  bool same(int a, int b){
    return find(a) == find(b);
  }
  int size(int a){
    return -p[find(a)];
  }
} uf;
int n, m, a[N], b[N];
V<ll> v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  uf.init(n);
  FOR(i, 0, m) cin >> a[i] >> b[i];
  ll ans = ll(n)*(n-1)/2;
  FORR(i, m-1, 0){
    v.pb(ans);
    a[i]--;
    b[i]--;
    if(!uf.same(a[i], b[i])){
      ans += ll(uf.size(a[i]))*(uf.size(a[i])-1)/2;
      ans += ll(uf.size(b[i]))*(uf.size(b[i])-1)/2;
      uf.merge(a[i], b[i]);
      ans -= ll(uf.size(a[i]))*(uf.size(a[i])-1)/2;
    }
  }
  reverse(all(v));
  for(ll l:v) printf("%lld\n", l);
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi
#define se second
 
#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i< n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0) 
 
using namespace std;



 
int main()
{
//	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >>y ;
	int dp[n+2][n+2], count[n+5] ={0};
	forz(i, n+2)
	{
		forz(j , n+2)
		{
			dp[i][j] = 100000;
		}
	}

	forl(i, n+1)
	{
		forl(j , n+1)
		{
			if (i>=j)
			{
				continue;
			}
			else if (j < y && i <= x)
			{
				dp[i][j] = min(j-i, 1+y-j + x-i);
			}
			else if(j >= y && i <= x)
			{
				dp[i][j] = min(j-i, 1+j-y + x-i);
			}
			else if (j < y && i > x)
			{
				dp[i][j] = min(j-i, 1+y-j + i - x);
			}
			else if (j >= y && i > x)
			{
				dp[i][j] = min(j-i,1+j-y + i -x);
			}
		}
	}
	forl(i, n+1)
	{
		forl(j , n+1)
		{
			if (dp[i][j]< 3000)
			{
				count[dp[i][j]]++;
			}
		}
	}
	forl(i, n)
	{
		cout << count[i] << endl;
	}
	return 0;

}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


int N;
ll dp[3001][3001];

int a[3001];

ll taro(int lo, int hi);
ll jiro(int lo, int hi);

ll taro(int lo, int hi) {
    if (lo == hi) return 0;
    if (lo+1 == hi) return a[lo];
    if (dp[lo][hi] != LLONG_MIN) return dp[lo][hi];
    // lo+2 <= hi
    ll left = a[lo] + jiro(lo+1, hi);
    ll right = jiro(lo, hi-1) + a[hi-1];
    return dp[lo][hi] = max(left, right);
}
ll jiro(int lo, int hi) {
    if (lo == hi) return 0;
    if (lo+1 == hi) return -a[lo];
    if (dp[lo][hi] != LLONG_MIN) return dp[lo][hi];

    ll left = -a[lo] + taro(lo+1, hi);
    ll right = taro(lo, hi-1) + -a[hi-1];
    return dp[lo][hi] = min(left, right);
}

ll solve(){
    rep(i,3001)rep(j,3001) dp[i][j] = LLONG_MIN;
    // mset(dp, -1);
    // rep(i,N+1) dp[i][i] = 0;
    return taro(0,N);
}

int main() {
    scanf("%d", &N);
    rep(i,N) scanf("%d", &a[i]);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstdlib>

using namespace std;

int compare(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int n,*a,i,outi,outj;
    cin >> n;
    a = new int[n];
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    qsort(a,n,sizeof(int),compare);
    outi = a[n-1];
    if(n%2==0){
        int mid = outi / 2;
        for(i=0;i<n;i++){
            if(a[i]<mid){
                continue;
            }else{
                int dis1,dis2;
                dis1 = a[i] - mid;
                dis2 = mid - a[i-1];
                if(dis1<dis2){
                    outj = a[i];
                }else{
                    outj = a[i-1];
                }
                break;
            }
        }
        if(i==n){
            outj = a[n-1];
        }
    }else{
        int mid = outi / 2;
        for(i=0;i<n;i++){
            if(a[i]<mid){
                continue;
            }else{
                int dis1,dis2;
                dis1 = a[i] - mid - 1;
                dis2 = mid - a[i-1];
                if(dis1<dis2){
                    outj = a[i];
                }else{
                    outj = a[i-1];
                }
                break;
            }
        }
        if(i==n){
            outj = a[n-1];
        }
    }
    cout << outi << " " << outj << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,tmp;
    cin>>n>>a;
    vector<int> card;
    vector<vector<vector<long long int>>> table(51);
    for(int i=0;i<51;i++){
        table[i].resize(2501);
        for(int j=0;j<2501;j++){
            table[i][j].resize(51);
            for(int k=0;k<51;k++){
                table[i][j][k]=0;
            }
        }
    }
    for(int i=0;i<n;i++){
        cin>>tmp;
        card.push_back(tmp);
    }
    table[0][0][0]=1;
    for(int i=1;i<n+1;i++){
        for(int j=0;j<2501;j++){
            for(int k=0;k<50;k++){
                if(table[i-1][j][k]!=0){
                    table[i][j][k]+=table[i-1][j][k];
                    table[i][j+card[i-1]][k+1]+=table[i-1][j][k];
                }
            }
        }
    }
    long long int ans=0;
    for(int i=1;i<n+1;i++){
        ans+=table[n][a*i][i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 55168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d.begin(), d.end());
  cout << d[n/2]-d[n/2-1] << endl;
  
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{

    int n, k;
    int[] v;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        k = int.Parse(input[1]);
        v = new int[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++) v[i] = int.Parse(input[i]);
        int[] x = new int[n];
        int[] y = new int[n];
        x[0] = v[0];
        y[n - 1] = v[n - 1];
        for (int i = 1; i < n; i++) x[i] = x[i - 1] + v[i];
        for (int i = n - 2; i > -1; i--) y[i] = y[i + 1] + v[i];
        int z = Math.Min(n, k);
        var list = new List<int>();
        long ans = -9999999999999;
        long tmp = 0;
        for(int i=0; i<=z; i++)
        {
            for(int j=0; j<=i; j++)
            {
                list = new List<int>();
                for (int a = 0; a < j; a++) list.Add(v[a]);
                for (int a = n + j - i; a < n; a++) list.Add(v[a]);
                list.Sort();
                tmp = 0;
                for (int b = 0; b < k - i; b++)
                {
                    if (b < list.Count && list[b] < 0) tmp -= list[b];
                }
                for (int b = 0; b < list.Count; b++) tmp += list[b];
                if (tmp > ans) ans = tmp;
                
            }
        }

        Console.WriteLine(ans);
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 13140
#n=int(input())
n,Y=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
x,y,z=-1,-1,-1
for i in range(n+1):
    for j in range(n+1):
        k=max(0,n-(i+j))
        if i+j+k==n:
            if i*1000+j*5000+k*10000 == Y:
                x,y,z=k,j,i
                #break
print("{0} {1} {2}".format(x,y,z))


Measured memory_bytes: 9180
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int sum = 0;
    repi(i,10000,1){
        if(a * i % b == 0)continue;
        if(c % (a * i % b) == 0){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
p=[1]*1000000
for i in range(2,1000000):
    for j in range(i+i,1000000,i):
        p[j]=0
p[0]=p[1]=0
while True:
    a,d,n=map(int,input().split())
    if a<1:break
    c=0
    while True:
        c+=p[a]
        if c==n:
            print(a)
            break
        a+=d


Measured memory_bytes: 13168
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<int> s, t, e;
    for(;;){
        int a, b, c;
        cin >> a >> b >> c;
        if(a == 0)
            break;
        s.push_back(a-1);
        t.push_back(b-1);
        e.push_back(c);
    }

    int l;
    cin >> l;
    while(--l >= 0){
        vector<int> b(m);
        for(int i=0; i<m; ++i)
            cin >> b[i];

        vector<long long> ans(n);
        for(unsigned i=0; i<s.size(); ++i)
            ans[s[i]] += b[t[i]] * e[i];

        cout << ans[0];
        for(int i=1; i<n; ++i)
            cout << ' ' << ans[i];
        cout << endl;
    }

    return 0;
}

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

int main(){
  ll N;
  cin >> N;
  vector<ll> vec;
  
  for(ll i=1; i<sqrt(N)+1; i++){
    if(N%i == 0){
      ll a = i + N/i - 2;
      vec.push_back(a);
    }
  }
  
  sort(vec.begin(), vec.end());
  cout << vec.at(0) << endl;
}


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

int main(){

	# ifdef FILEs
		freopen( "input.txt", "r", stdin );
		freopen( "output.txt", "w", stdout );
	# endif
	ios_base::sync_with_stdio( false );
	int n;
	cin >> n;
	int mn = 1e9, cnt = 0;
	for( int i = 0; i < n; i ++ ){
		int a;
		cin >> a;
		if( mn >= a ) cnt ++;
		mn = min( mn, a );
		//cout << i << ' '<< a << ' '<< mn << endl;
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int d,c,a;
	scanf("%d %d",&d,&c);
	if((1<=d && d<=100) && (1<=c && c<=10)){
		a=d*c;
		printf("%d\n",a);
	}
	else{
		printf("error\n");
	}
	return 0;
}


Measured memory_bytes: 2120
#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;
    vector<double> v(n);
    rep(i,n) cin >> v[i];
    rep(i,n-1){
        sort(v.begin(), v.end());
        v[0] = (v[0] + v[1])/2;
        v[1] = 1001;
    }

    cout << setprecision(10) << v[0] << endl;

    
    return 0;
}

Measured memory_bytes: 256
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()

ans=0
te=[]
for i in range(k):
    if t[i]=='r':
        ans+=p
        te.append('p')
    elif t[i]=='p':
        ans+=s
        te.append('s')
    elif t[i]=='s':
        ans+=r
        te.append('r')

for i in range(k,n):
    if t[i]=='r' and te[i-k]!='p':
        ans+=p
        te.append('p')
    elif t[i]=='p' and te[i-k]!='s':
        ans+=s
        te.append('s')
    elif t[i]=='s' and te[i-k]!='r':
        ans+=r
        te.append('r')
    else:
        te.append('*')
print(ans)


Measured memory_bytes: 4212
N, X, M = map(int, input().split())

id_ = [-1] * M
a = []
len_ = 0
ans = 0
x = X
while id_[x] == -1:
    id_[x] = len_
    len_ += 1
    ans += x
    a.append(x)
    x = x**2 % M

c = len_ - id_[x]
s = 0
for i in range(id_[x], len_):
    s += a[i]

if len_ >= N:
    ans = 0
    for i in range(N):
        ans += a[i]
else:
    n = N
    n -= len_
    ans += s * (n // c)
    n %= c
    for i in range(n):
        ans += a[id_[x]+i]
print(ans)

Measured memory_bytes: 69736
# Code for B - ATCoder
# Use input() to fetch data from STDIN
s = input()

acgt = ["A", "C", "G", "T"]

m = []
c = 0
for x in s:
    if not x in acgt:
        m.append(c)
        c = 0
    else:
        c += 1
m.append(c)

print(max(m))


Measured memory_bytes: 2940
#include <iostream>
#define MOD 1000000007

using namespace std;

int main(void) {
	long long a, b, ans = 2;
	cin >> a >> b;
	if (abs(a - b) > 1) {
		printf("0\n");
		return 0;
	}
	ans -= abs(a - b);
	for (; a > 1; a--) {
		ans *= a;
		ans %= MOD;
	}
	for (; b > 1; b--) {
		ans *= b;
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}

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

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 in [0, 2, 4, 5, 6, 8]:
        print(-1)
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break

if __name__ == '__main__':
    main()


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

int main(){
  int a,b;
  string s,t,u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(u==s)cout << a-1 << " " << b << endl;
  else if(u==t)cout << a << " " << b-1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int A[100][100];
int B[100][100];

int main(void)
{
int n, m, l, i, j, k;
long sum;

scanf("%d %d %d", &n, &m, &l);

for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &A[i][j]);
}
}

for (j = 0; j < m; j++)
{
for (k = 0; k < l; k++)
{
scanf("%d", &B[j][k]);
}
}

for (i = 0; i < n; i++)
{
for (k = 0; k < l; k++)
{
sum = 0L;
for (j = 0; j < m; j++)
{
sum += (long)A[i][j] * (long)B[j][k];
}
if (k > 0) { putchar(' '); }
printf("%ld", sum);
}
putchar('\n');
}

return 0;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

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

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 4003;

int n, m;
int a[N], b[N];
int sr[N], sg[N], sb[N];
char s[N];

int main()
{
    n = gi();
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i+=1)
    {
        sr[i] = sr[i - 1] + (s[i] == 'R');
        sg[i] = sg[i - 1] + (s[i] == 'G');
        sb[i] = sb[i - 1] + (s[i] == 'B');
    }
    LL ans = 0;
    for (int i = 1; i <= n; i+=1)
        for (int k = i + 1; k <= n; k+=1)
        {
            if (s[i] == s[k]) continue;
            int xr = 0, xg = 0, xb = 0;
            if (s[i] == 'R') xr = 1;
            else if (s[i] == 'G') xg = 1;
            else if (s[i] == 'B') xb = 1;
            if (s[k] == 'R') xr = 1;
            else if (s[k] == 'G') xg = 1;
            else if (s[k] == 'B') xb = 1;
            int now = 0;
            if (!xr) now = 1;
            else if (!xg) now = 2;
            else now = 3;
            if ((k - i) & 1)
            {
                if (now == 1) ans += sr[k] - sr[i - 1];
                else if (now == 2) ans += sg[k] - sg[i - 1];
                else ans += sb[k] - sb[i - 1];
            }
            else
            {
                if (now == 1) ans += sr[k] - sr[i - 1] - (s[(k + i) >> 1] == 'R');
                else if (now == 2) ans += sg[k] - sg[i - 1] - (s[(k + i) >> 1] == 'G');
                else ans += sb[k] - sb[i - 1] - (s[(k + i) >> 1] == 'B');
            }
        }
    printf("%lld\n", ans);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, t, l, b;
int masu[105];
double dp[105][105];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        cin >> n >> t >> l >> b;
        if (n == 0) break;
        rep(i, 105) masu[i] = 0;
        rep(i, 105)rep(j, 105) dp[i][j] = 0.0;
        rep(i, l) {
            int idx;
            cin >> idx;
            masu[idx] = 1;
        }
        rep(i, b) {
            int idx;
            cin >> idx;
            masu[idx] = 2;
        }
        dp[0][0] = 1.0;
        rep(i, t)rep(j, n + 1) {
            if (j == n) {
                dp[i + 1][n] += dp[i][n];
                continue;
            }
            rep2(k, 1, 7) {
                int nx = j + k;
                if (nx > n) nx = n - (j + k - n);
                if (masu[nx] == 1) {
                    dp[i + 2][nx] += dp[i][j] / 6.0;
                }
                else if (masu[nx] == 2) {
                    dp[i + 1][0] += dp[i][j] / 6.0;
                }
                else {
                    dp[i + 1][nx] += dp[i][j] / 6.0;
                }
            }
        }
        cout << fixed << setprecision(10) << dp[t][n] << endl;
    }
}

Measured memory_bytes: 3340
t=int(raw_input())
for tt in range(t):
    n,k=map(int,raw_input().split())
    k=min(n,k)
    A=map(int,raw_input().split())
    B=[]
    for i in range(1,n):
        B.append(A[i]-A[i-1])
    B.sort()
    for i in range(1,k):
        B[-i]=0
    print sum(B)

Measured memory_bytes: 19592
N, M = map(int, input().split())


def divisors(n):
    d = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            d.append(i)
            if i != n // i:
                d.append(n // i)
    return d


d = divisors(M)

ans = 0

for i in d:
    if N * i <= M:
        ans = max(ans, i)

print(ans)


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

using namespace std;

map<string, int> dict; 
map<string, int> enter;

int dates[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
    //freopen("input.txt", "r" ,stdin);
    for (int i=1; i<=12; i++)
        dates[i] = dates[i-1] + dates[i]*1440;
    int n;
    while (scanf("%d", &n)==1)
    {
        if (n==0)
            break;
        dict.clear();
        enter.clear();
        int m, d, hours, minutes;
        char str[100];
        char flag[100];
        for (int i=1; i<=n; i++)
        {
            scanf("%d/%d", &m, &d);
            scanf("%d:%d", &hours, &minutes);
            scanf("%s%s", flag, str);
            int time = dates[m-1] + d*1440 + hours*60 + minutes;

            if (string(str) == "000")
            {
                if (flag[0] == 'I')
                {
                    for(map<string, int>::iterator ite = enter.begin(); ite!=enter.end(); ite++)
                        ite->second = time;
                    enter["000"] = time;
                }
                else
                {
                    for(map<string, int>::iterator ite = enter.begin(); ite!=enter.end(); ite++)
                    {
                        if (ite->first == "000")
                            continue;
                        dict[ite->first] += time - ite->second;
                        ite->second = time;
                    }
                    enter.erase("000");
                }
            }
            else
            {
                if (flag[0] == 'I')
                {
                    enter[string(str)] = time;
                }
                else
                {
                    if (enter["000"])
                    {
                        dict[string(str)] += time - enter[string(str)];
                    }
                    enter.erase(string(str));
                }
            }
            //printf("%d %d %d %d %s %s\n", m, d, hours, minutes, flag, str);
        }
        int ans = 0;
        for (map<string, int>::iterator ite = dict.begin(); ite!=dict.end(); ite++)
        {
            //printf("%s %d\n", ite->first.c_str(), ite->second);
            ans = max(ans, ite->second);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1296
/*
 ============================================================================
 Name        : alds1_4_c_dictionary.c
 Author      : lovesaemi
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <string.h>

//#define M 1046527
#define MAX 244140625
#define NIL (-1)
#define L 14

char H[MAX];
char s[13];


int getChar(char ch) {
	if (ch == 'A')
		return 1;
	else if (ch == 'C')
		return 2;
	else if (ch == 'G')
		return 3;
	else if (ch == 'T')
		return 4;
	else
		return 0;
}
long long getKey() {
	long long sum = 0, p = 1, i, l;
	for (i = 0, l = strlen(s); i < l; i++) {
		sum += p * (getChar(s[i]));
		p *= 5;
	}
	return sum;
}

int find() {
	int key = getKey();
	if (H[key]) {
		return 1;
	}
	return 0;
}
void insert() {
	H[getKey()] = 1;
}

int main(void) {
	int i, n, h;
	char str[L], com[9];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s %s", com, s);
		if (com[0] == 'i') {
			insert();
		} else {
			if (find()) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}



Measured memory_bytes: 6868
N,M,S=map(int,input().split())
from heapq import heappop,heappush 

inf = float('inf')
cost=[[] for _ in range(N)]
exc=[]


for _ in range(M):
    u,v,a,b=map(int,input().split())
    u,v=u-1,v-1
    cost[u].append((v,a,b))
    cost[v].append((u,a,b))
for _ in range(N):
    c,d=map(int,input().split())
    exc.append((c,d))

di=[inf]*2451*N
if S>2450:
    S=2450
di[S]=0
hq=[(0,S)] #時間,都市名*2451+銀貨

while hq:
    t,v=heappop(hq)
    u=v//2451 #都市名
    s=v%2451 #所持金

    for x,a,b in cost[u]:
        if s>=a:
            v_new=x*2451+s-a
            t_new=t+b
            if t_new<di[v_new]:
                di[v_new]=t_new
                heappush(hq,(t_new,v_new))
    
    c,d=exc[u]
    if s+c>2450:
        c=2450-s
    v_new=v+c
    t_new=t+d
    if t_new<di[v_new]:
        di[v_new]=t_new
        heappush(hq,(t_new,v_new))

for i in range(1,N):
    m=di[i*2451]
    for j in range(1,2451):
        m=min(m,di[i*2451+j])
    print(m)

Measured memory_bytes: 23784
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	int Q = Read(), H = Read(), S = Read(), D = Read(), N = Read();
	return printf("%lld\n", 1LL * (N >> 1) * min(D, min(S << 1, min(H << 2, Q << 3))) + (N & 1) * (min(S, min(H << 1, Q << 2)))), 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    if(c < a + b) {
        cout << "No" << endl;
        return 0;
    }
    if(4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [0 for i in range(n)]
j = 0
count = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        count += 1
    else:
        b[j] += count
        j += 1
        count=1
b[j] += count
b.sort()
b.reverse()
sum = 0
for i in range(k):
    sum += b[i]
print(n-sum)

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

using namespace std;

int main(void) {
  char str[33];

  char l[15] = {'q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', 'v', 'b'};

  char r[11] = {'y', 'u', 'i', 'o', 'p', 'h', 'j', 'k', 'l', 'n', 'm'};
  
  while(1){
    cin >> str; if(str[0] == '#') break;
    
    int counter = 0;
    int flag = 0;
    for(int i = 0; str[i] != '\0'; i++){
      
      for(int j = 0; j < 15; j++){
	if(str[i] == l[j]){
	  if(flag == 2) counter++;
	  flag = 1;
	  break;
	}
      }

      for(int j = 0; j < 11; j++){
	if(str[i] == r[j]){
	  if(flag == 1) counter++;
	  flag = 2;
	  break;
	}
      }
    
    }

    cout << counter << endl;

  }

  return 0;

}

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
const long long LLINF = 1LL << 62;
const int INF = 1LL << 30;
using namespace std;

const int N_MAX = 110;
const int W_MAX = 100010;

int main(void) {
	int N, W;
	cin >> N >> W;

	vector<int> weight(N_MAX);
	vector<int> value(N_MAX);
	for (int i = 1; i <= N; i++) cin >> weight[i] >> value[i];

	vector<vector<LL> > dp(N_MAX,vector<LL>(W_MAX));

	for (int i = 1; i <= N; i++) {
		for (int w = 0; w < W_MAX; w++) {
			if (w - weight[i] >= 0) {
				dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - weight[i]] + value[i]);
			}
			else {
				dp[i][w] = max(dp[i - 1][w],dp[i][w]);
			}
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 87296
from collections import defaultdict
n = int(input())
S = [input() for _ in range(n)]
dics = [defaultdict(int) for _ in range(n)]
keys = set()
for i in range(n):
    for c in S[i]:
        keys.add(c)
        dics[i][c] += 1
dic = defaultdict(int)
for k in dics[0]:
    dic[k] = dics[0][k]
for i in range(1, n):
    for k in keys:
        dic[k] = min(dic[k], dics[i][k])
ls = list(dic.keys())
ls.sort()
ans = ""
for k in ls:
    ans += k*dic[k]
print(ans)

Measured memory_bytes: 3436
n, f = map(int, input().split())
pair = {}
for i in range(n):
    m, *items = input().split()
    m = int(m)
    for p in range(m):
        for q in range(p):
            key = tuple(sorted([items[p], items[q]]))
            pair[key] = pair.get(key, 0) + 1
ans = sorted(key for key in pair if pair[key] >= f)
print(len(ans))
if ans:
    for a, b in ans:
        print(a, b)

Measured memory_bytes: 8188
using System;

class Program
{
    static void Main()
    {
      string line = System.Console.ReadLine();
      long N = long.Parse(line);
      line = System.Console.ReadLine();
      string []stArrayData = line.Split(' ');
      long []data = new long[stArrayData.Length];
      long ans = 0;
      for(int i = 0; i < stArrayData.Length; i++){
        data[i] = long.Parse(stArrayData[i]);
        ans = ans ^ data[i];
      }
      
      for(int i = 0; i < N; i++){
        Console.Write(ans ^ data[i]);
        if(i != N -1)
        Console.Write(" ");

      }
    }
}

Measured memory_bytes: 53876
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	VI v(5);
	trav(i, v) cin >> i;
	int c = 1;
	trav(i, v)
	{
		if (i == 0)
		{
			cout << c << "\n";
			break;
		}
		c++;
	}

	return 0;
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main()
{
    int n, ans=0;
    cin>>n;
    while(cin>>n) {
        bool ok = false;
        for(int y=1; y*y<n; y++) {
            if((n-y)%(2*y+1))continue;
            ok = true;
            break;
        }
        ans += !ok;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
  int64_t N, X, M;
  cin >> N >> X >> M;
  N--;
  vector<int64_t> visit(M, -1);
  vector<int64_t> R(M, -1);
  visit[X] = 0;
  int64_t prev = X;
  R[0] = X;

  int64_t loop_first = -1;
  int64_t loop_second = -1;
  {
    int64_t turn = 1;
    while (true) {
      R[turn] = R[turn - 1] * R[turn - 1] % M;
      if (visit[R[turn]] >= 0) {
        loop_first = visit[R[turn]];
        loop_second = turn;
        break;
      }
      visit[R[turn]] = turn;
      turn++;
    }
  }

  int64_t answer = 0;
  for (int64_t turn = 0; turn < min(N + 1, (int64_t )loop_first); turn++) {
    answer += R[turn];
  }
  int64_t loop_size = loop_second - loop_first;
  int64_t loop_count = (N - loop_first + 1) / (loop_size);
  int64_t sum_one_loop = 0;
  for (int i = loop_first; i < loop_second; i++) {
    sum_one_loop += R[i];
  }
  answer += sum_one_loop * loop_count;
  {
    int64_t turn = loop_first + loop_count * loop_size;
    int64_t r = R[loop_first];
    for (; turn <= N; turn++) {
      answer += r;
      r = r * r % M;
    }
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 4832
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 50010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int main(){
    int T,i,j,k,ca=0,m,n,K;
    //cout<<setprecision(10)<<fixed;
    scanf("%d",&T);
    while(T--){
    	scanf("%d%d",&n,&m);
    	if(n==1){printf("%d\n",m);continue;}
    	int ans=(n-1)*127,x=127^m;
    	if(n&1)ans+=m;else ans+=x;
    	printf("%d\n",ans);
    }
    return 0;
}



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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  if (N % 2) cout << "No";
  else {
    for (int i = 0; i < N / 2; i++) {
      if (S.at(i) != S.at(i + N / 2)) {
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
  }
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  vector<int64_t> sum(N+1);
  for(int i=0; i<N; i++){
    sum.at(i+1) = vec.at(i) + sum.at(i);
  }
  
  int64_t ok = 0;
  int64_t ng = 1000000000000000000;
  
  vector<int64_t>::iterator pos;
  int64_t idx;
  
  while(ng - ok > 1){
    int64_t mid = (ok+ng)/2;
    int64_t cnt = 0;
    for(int i=0; i<N; i++){
      pos = lower_bound(vec.begin(),vec.end(),mid-vec.at(i));
      idx = distance(vec.begin(),pos);
      cnt += N - idx;
    }
    if(cnt < M){
      ng = mid;
    }
    else{
      ok = mid;
    }
  }
  
  int64_t ans = 0;
  int64_t over = 0;
  for(int i=0; i<N; i++){
    pos = lower_bound(vec.begin(),vec.end(),ok-vec.at(i));
    idx = distance(vec.begin(),pos);
    if(idx < N){
      ans += vec.at(i)*(N-idx) + sum.at(N) - sum.at(idx);
    }
    over += N - idx;
  }
  ans -= ok*(over-M);
  cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())
data = [tuple(map(int, input().split())) for _ in range(n)]
ax, ay, ah = list(filter(lambda x:x[2], data))[0]

for cx in range(101):
    for cy in range(101):
        H = ah + abs(ax-cx) + abs(ay-cy)
        if all(max(H-abs(d[0]-cx)-abs(d[1]-cy),0)==d[2] for d in data):
            print(cx, cy, H)
            exit()

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

typedef struct NODE 
{
    int key;
    NODE *pre, *next;
} node;

node *head;

void init() 
{
    head = (node *)malloc(sizeof(node));
    head->next = head;
    head->pre = head;
}

void insert(int d) 
{
    node *new_node = (node *)malloc(sizeof(node));
    new_node->key = d;
    new_node->next = head->next;
    head->next->pre = new_node;
    head->next = new_node;
    new_node->pre = head;
}

void delete_node(node *target) {
    if( target == head ) return;
    target->pre->next = target->next;
    target->next->pre = target->pre;
    free(target);
}

node *list_search(int key)
{
    node *presence = head->next;
    while(presence != head && presence->key != key)
    {
        presence = presence->next;
    }
    return presence;
}

void delete_num(int key)
{
    delete_node(list_search(key));
}

void deleteFirst()
{
    delete_node(head->next);
}

void deleteLast()
{
    delete_node(head->pre);
}

void print_list()
{
    node *presence = head->next;
    while(presence != head)
    {
        cout << presence->key;
        if( presence->next != head ) cout << ' ';
        presence = presence->next;
    }
    cout << endl;
}

int main() 
{
    init();
    int n; cin >> n;
    for(int i = 0; i< n; i++) 
    {
        char command[20]; int d; scanf("%s", command);
        if( command[0] == 'i' ) 
        {
            cin >> d;
            insert(d);
        }
        else if( strlen(command) > 6)
        {
            if( command[6] == 'F')
            { deleteFirst(); }
            else if( command[6] == 'L')
            { deleteLast(); }
        } else 
        { cin >> d; delete_num(d); }
    }

    print_list();

    return 0;
}




Measured memory_bytes: 34432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        
        String seikai = null;
        String hare = "Sunny";
        String kumori = "Cloudy";
        String Ame = "Rainy";
        
        if(S.equals(hare)) {
        	seikai = "Cloudy";
        }
        if(S.equals(kumori)) {
        	seikai = "Rainy";
        }
        if(S.equals(Ame)) {
        	seikai = "Sunny";
        }

        System.out.println(seikai);

	}

}


Measured memory_bytes: 19796