akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define ar array
#define pb push_back


int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("outputc.txt","w",stdout);
	// #endif
	
	//int t;
	//cin>>t;
	//while(t--)
	{
		int n;
		cin>>n;
		ll a[n];
		for(auto &x:a)
		{
			cin>>x;
		}
		ll dp[n];
		memset(dp,0x3f,sizeof(dp));
		dp[0]=0;
		for(int i=1;i<n;i++)
		{
			if(i-1>=0)
				dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
			if(i-2>=0)
				dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
		}
		cout<<dp[n-1];
	}
		
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

s = s_in()

if 'RRR' in s:
    print(3)
    exit()
if 'RR' in s:
    print(2)
    exit()
if 'R' in s:
    print(1)
    exit()
    

print(0)


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a.at(i);
    for(int i = n - 1; i >= 0; i--){
        cout << a.at(i);
        if(i != 0)
            cout << " ";
        else
            cout << endl;
    }  
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int res = (a + b) - (c + d);

  if (res < 0) {
    cout << "Right";
  } else if (res == 0) {
    cout << "Balanced";
  } else {
    cout << "Left";
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,q,b,c;
vector<int>a(100001);
ll sum;
int main(){
	cin>>n;
	int x;
	for(int i=0;i<n;i++){
		cin>>x;
		a[x]++;
		sum+=x; 
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>b>>c;
		int v=c-b;
		sum+=a[b]*v;
		cout<<sum<<endl;
		a[c]+=a[b];
		a[b]=0;
	}
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int,int>
template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9+15;
ll INF = 2e18L+15;
const int mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	int a[n][n];
	rep(i,n){
		rep(j,n){
			cin >> a[i][j];
		}
	}
	vll dp(1<<n,0);
	for(int mask = 0; mask < (1<<n); ++mask){
		for(int i = 0; i < n; ++i){
			if(mask&(1<<i)){
				for(int j = i+1; j < n; ++j){
					if(mask&(1<<j)){
						dp[mask] += a[i][j];
					}
				}
			}
		}
	}
	for(int mask = 0; mask < (1<<n); ++mask){
		for(int submask = mask; submask; submask = (submask-1)&mask){
			amax(dp[mask], dp[submask]+dp[mask^submask]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size() - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

int main() {
    long N, M;
    cin >> N >> M;
    long D = 0;
    for (long i = (M / N); i >= 1; i--) {
        if (M % i == 0) {
            D = i;
            break;
        }
    }
    cout << D << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define ii pair <int, int>
#define mp make_pair
using namespace std;

const int MAXN = 100010;
const ll MOD = 1000000007;

char word[MAXN];
ll dp[MAXN];
ll freq[MAXN];

ll solve(int letra) {
	if (dp[letra] != -1) return dp[letra];
	if (letra > ('z'-'a')) return 1;

	ll op = (solve(letra+1) * freq[letra]) % MOD;
	op += (solve(letra+1)) % MOD;
	return dp[letra] = op % MOD;
}

int main(){
	int n;
	memset(dp, -1, sizeof dp);
	scanf("%d", &n);
	scanf("%s", word);

	ll total = 0;
	for (int i=0; i<n; i++){
		freq[word[i] - 'a']++;
	}

	printf("%lld\n", solve(0) - 1);

	return 0;
}

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

int main() {
  using vote= pair<string, int>;
  int N;
  cin >> N;

  map<string, int> data;
  deque<vote> ans;
  string buf;
  for(int i=0; i<N; i++){
    cin >> buf;
    if(data.count(buf)){
      data.at(buf)++;
    }
    else{
      data[buf]= 1;
    }
  }

  int max_vote= -1;
  for(auto e:data){
    if(max_vote < e.second){
      max_vote= e.second;
      ans.clear();
      ans.push_back(e);
    }
    else if(max_vote==e.second){
      ans.push_back(e);
    }
    else continue;
  }

  while(!ans.empty()){
    auto elem= ans.front();
    cout << elem.first << endl;
    ans.pop_front(); 
  }
}

Measured memory_bytes: 28544
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define r0 return 0;
#define PI 3.141592653589793


double angle(int h, int m)  
{    
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
   
    double hour_angle = 0.5 * double((h * 60 + m));  
    double minute_angle = 6 * double(m);  
  
    // Find the difference between two angles  
    double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360 - angle, angle);  
  
    return angle;
}  

  
  

int main()
{
   fastio
   int a,b,h,m;
   cin>>a>>b>>h>>m;
   double x=angle(h,m);
   double y=cos(x*PI/180.0);
   double ans=sqrt(a*a+b*b-2*a*b*y);
   cout<<fixed<<setprecision(19)<<ans;
}


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

char s[500][500],a[500][500];
int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%s",s[i]);
	int cnt=0;
	rep(i,n){
		rep(j,n)rep(k,n)a[j][k]=s[(j+i)%n][k];
		bool flag=true;
		rep(j,n)rep(k,n){
			if(a[j][k]!=a[k][j])flag=false;
		}
		if(flag)cnt+=n;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;

long long n, m,l;
string s;
typedef pair<long long, long long> P;


int main() {
	cin >> n >> m;
	vector<P> p(n + m);
	for (int i = 0; i < n; i++)
	{
		cin >> p[i].first;
		p[i].second = 1;
	}
	for (int i = 0; i < m; i++)
	{
		cin >> p[i + n].second >> p[i + n ].first;
	}
	sort(p.begin(), p.end());
	long long ans = 0;
	int res = 0;
	int iter = n+m-1;
	while (res < n) {
		if (res+p[iter].second<n)
		{
			ans += p[iter].second*p[iter].first;
			res += p[iter].second;
		}
		else {
			ans += p[iter].first*(n - res);
			break;
		}
		iter--;
	}
	cout << ans << endl;

}





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


bool primeCheck(lli n)
{
	for(lli i = 2; i*i <= n; i++)
	{
		if(n%i == 0) 
			return false;
	}
	return true;
}

int main() 
{
	int n, k;
	cin >> n >> k;
	int a[n], sum = 0;
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a, a+n);
	for(int i=0;i<k;i++)
		sum += a[i];
	cout << sum;
	return 0;
}
   








Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
	int D; cin >> D; 
	int C[30] = {}; 
	for(int i = 1; i <= 26; i++) cin >> C[i]; 
	int S[370][30] = {}; 
	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= 26; j++){
			cin >> S[i][j]; 
		}
	}
	int ans[370] = {}; 
	int L[30] = {}; 
	for(int i = 1; i < D; i+= 2){
		int E[700] = {}; 
		for(int j = 1; j <= 676; j++){
			int p = (j - 1) % 26 + 1; // i日目
			int q = (j - 1) / 26 + 1; // i+1日目
			int M[30] = {}; 
			for(int k = 1; k <= 26; k++){
				M[k] = L[k]; 
			}
			E[j] += S[i][p] + C[p] * (i - M[p]); 
			M[p] = i; 
			E[j] += S[i+1][q] + C[q] * (i + 1 - M[q]);
		}
		int a = 0; int mx = -1145141919; 
		for(int j = 1; j <= 676; j++){
			if(E[j] > mx){
				a = j; mx = E[j]; 
			}
		}
		ans[i] = (a-1) % 26 + 1; ans[i+1] = (a-1) / 26 + 1; 
		L[(a-1) % 26 + 1] = i; L[(a-1) / 26 + 1] = i + 1; 
	}
	for(int i = D; i <= D; i++){
		int E[30] = {}; 
		for(int j = 1; j <= 26; j++){
			E[j] = S[i][j] + C[j] * (i - L[j]); 
		}
		int a = 0; int mx = -1145141919; 
		for(int j = 1; j <= 26; j++){
			if(E[j] > mx){
				a = j; mx = E[j]; 
			}
		}
		ans[i] = a; L[a] = i; 
	}
	for(int i = 1; i <= D; i++) cout << ans[i] << endl; 
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, 0, n) cin >> p[i];
	int ans = 0;
	int MIN = INF;
	rep(i, 0, n){
		if(MIN > p[i]){
			MIN = p[i];
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

char mcxi[]={'m','c','x','i'};
int v[]={1000,100,10,1};

int toint(string x){
	int d=1;
	int sum=0;
	for(int i=0;i<x.size();i++){
		if(x[i]>='0' &&x[i]<='9'){
			d=x[i]-'0';
		}else{
			for(int j=0;j<4;j++){
				if(x[i]!=mcxi[j])continue;
				sum+=d*v[j];
				d=1;
				break;
			}
		}
	}
	return sum;

}
int main(void){
	int n,sum,cnt;
	string a,b;

	cin>>n;
	while(n--){
		cin>>a>>b;
		sum=toint(a)+toint(b);
		for(int i=0;i<4;i++){
			cnt=0;
			while(sum>=v[i]){
				sum-=v[i];
				cnt++;
			}
			if(cnt>1)cout<<cnt;
			if(cnt>0)cout<<mcxi[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,n) for (int i=1;i<=n;i++)
#define repn(i,n1,n2) for (int i=n1;i<=n2;i++)
#define pb push_back
typedef vector<int> vi;
typedef long long ll;
vi son[100005];
int getdep(int node){
	if (son[node].empty()) return 0;
	int res=0,sz=son[node].size();
	vi dep;
	dep.clear();
	for (int i=0;i<sz;i++){
		dep.pb(getdep(son[node][i]));
	} 
	sort(dep.begin(),dep.end());
	for (int i=0;i<sz;i++){
		res=max(res,dep[i]+sz-i);
	}
	return res;
}
int main()
{
	int n;
	cin>>n;
	for (int i=0;i<100005;i++) son[i].clear();
	for (int i=2;i<=n;i++){
		int x;
		scanf("%d",&x);
		son[x].pb(i);
	}
	printf("%d",getdep(1));
}

Measured memory_bytes: 15104
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Grid Components
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int H = 100, HH = H / 2;
const int W = 100;

/* typedef */

/* global variables */

string flds[H];

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  a--, b--;

  for (int y = 0; y < HH; y++) flds[y].assign(W, '#');
  for (int y = HH; y < H; y++) flds[y].assign(W, '.');

  for (int x = 0, y = 0; a > 0; a--) {
    flds[y][x] = '.';
    x += 2;
    if (x >= W) x = 0, y += 2;
  }
  for (int x = 0, y = H - 1; b > 0; b--) {
    flds[y][x] = '#';
    x += 2;
    if (x >= W) x = 0, y -= 2;
  }

  printf("%d %d\n", H, W);
  for (int y = 0; y < H; y++) cout << flds[y] << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int n = inp[0];
            int l = inp[1];

            int min = 100000;
            int sum = 0;

            for (int i = 1; i < n+1; i++)
            {
                int t = l + i - 1;
                if (Math.Abs(t) < Math.Abs(min))
                {
                    min = t;
                }
                sum += t;
            }
            Console.WriteLine(sum - min);
        }
    }
}

Measured memory_bytes: 11220
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int n;cin>>n;
  VV<string> v(11,V<string>(0));
  v[0].pb("a");

  rep(i,1,11){
    rep(j,0,siz(v[i-1])){
      string nex=v[i-1][j];
      char mx='a';
      rep(k,0,siz(nex)){
        chmax(mx,nex[k]);
      }

      for(char k='a';k<mx+2;++k){
        v[i].pb(nex+k);
      }
    }
  }

  sort(all(v[n-1]));

  rep(i,0,siz(v[n-1])){
    cout<<v[n-1][i]<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 59752
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"10 8"# => r#"322828856"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: u32, k: u32,
    }

    (k * (k - 1).pow(n - 1)).to_string()
}

Measured memory_bytes: 4352
L, R = gets.chomp.split(" ").map(&:to_i)

num_loop = R - L
if num_loop >= 2019
  puts 0
  exit
end

min_m = 2019
0.upto(num_loop) do |i|
  (i + 1).upto(num_loop) do |j|
    m = ((L + i) * (L + j)) % 2019
    min_m = m if m < min_m
  end
end
puts min_m


Measured memory_bytes: 3836
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N, Y;
  cin >> N >> Y;
  int ans[3] = {-1, -1, -1};
  for(int i=0; i<Y/10000+1; ++i){
    int v = Y- 10000*i;
    for(int j=0; j<v/5000+1; ++j){
      int k = (v-5000*j) / 1000;
      if(i+j+k == N){
        ans[0] = i;
        ans[1] = j;
        ans[2] = k;
        break;
      }
    }
  }

  cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;

}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        r: i64,
        d: i64,
        x_2000: i64,
    }

    let mut cur = x_2000;
    for i in 2001..2010 + 1 {
        let next = r * cur - d;
        println!("{}", next);
        cur = next;
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
class Team {
public:
	int rank, score, num;
	Team() { rank = 0, score = 0, num = 0; }
};
bool by_score(const Team &a, const Team &b) {
	return a.score > b.score;
}
bool by_num(const Team &a, const Team &b) {
	return a.num < b.num;
}
signed main() {
	int n; cin >> n;
	int battle = n*(n - 1) / 2;
	vector<Team>team(n);
	rep(i, 0, n)team[i].num = i;
	rep(i, 0, battle) {
		int a, b, c, d;
		cin >> a >> b >> c >> d; a--, b--;
		if (c == d) team[a].score++, team[b].score++;
		else if (c < d) team[b].score += 3;
		else team[a].score += 3;
	}
	sort(all(team), by_score);
	team[0].rank = 1;
	int r = 2;
	rep(i, 1, n) {
		if (team[i].score == team[i - 1].score) {
			team[i].rank = team[i - 1].rank;
			r++;
		}
		else team[i].rank = r, r++;
	}
	sort(all(team), by_num);
	rep(i, 0, n)cout << team[i].rank << endl;
	
	return 0;
}

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

using Graph = vector<vector<int>>;

int to_v(auto x, auto y, auto N) {return N * y + x;}
int to_x(auto v, auto N) {return v % N;}
int to_y(auto v, auto N) {return v / N;}
void paint(const auto& G, auto& color, auto v) {
  function<void(int)> dfs = [&](auto cur) {
    for(auto nex: G[cur]) if(!color[nex]) {
      color[nex] = 3 - color[cur];
      dfs(nex);
    }
  };
  color[v] = 1;
  dfs(v);
}

int main() {
  int N, D1, D2;
  cin >> N >> D1 >> D2;

  vector<pair<int, int>> d1, d2;
  for(auto x=0; x<2*N; ++x) for(auto y=0; y<2*N; ++y) {
    if(x*x+y*y == D1) d1.emplace_back(x, y), d1.emplace_back(-x, y), d1.emplace_back(x, -y);
    if(x*x+y*y == D2) d2.emplace_back(x, y), d2.emplace_back(-x, y), d2.emplace_back(x, -y);
  }

  Graph G1(4*N*N), G2(4*N*N);
  for(auto x=0; x<2*N; ++x) for(auto y=0; y<2*N; ++y) {
    for(auto d: d1) {
      auto nx = x + d.first;
      auto ny = y + d.second;
      if(nx<0 || 2*N<=nx || ny<0 || 2*N<=ny) continue;
      auto u = to_v(x, y, 2*N);
      auto v = to_v(nx, ny, 2*N);
      G1[u].emplace_back(v);
      G1[v].emplace_back(u);
    }
    for(auto d: d2) {
      auto nx = x + d.first;
      auto ny = y + d.second;
      if(nx<0 || 2*N<=nx || ny<0 || 2*N<=ny) continue;
      auto u = to_v(x, y, 2*N);
      auto v = to_v(nx, ny, 2*N);
      G2[u].emplace_back(v);
      G2[v].emplace_back(u);
    }
  }

  vector<int> color1(4*N*N), color2(4*N*N);
  for(auto v=0; v<4*N*N; ++v) {
    if(!color1[v]) paint(G1, color1, v);
    if(!color2[v]) paint(G2, color2, v);
  }

  for(auto c1: {1, 2}) for(auto c2: {1, 2}) {
    auto n = 0;
    for(auto v=0; v<4*N*N; ++v) if(color1[v]==c1 && color2[v]==c2) ++n;
    if(n < N*N) continue;

    auto V = 0;
    for(auto v=0; v<4*N*N; ++v)
      if(color1[v]==c1 && color2[v]==c2)
        if(V++ < N*N)
          cout << to_x(v, 2*N) << " " << to_y(v, 2*N) << endl;

    return 0;
  }
}


Measured memory_bytes: 182400
n = int(input())
data = []
for i in range(n-1):
    station_data = [int(x) for x in input().split()]
    data.append(station_data)

time_list = []

for i in range(n):
    total_time = 0

    for j in range(i, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += data[j][2] - total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

answer = map(str, time_list)
print("\n".join(answer))

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
if(s=="ABC"){
    cout<<"ARC"<<endl;
}
else{
    cout << "ABC" << endl;
}
return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

Vi v[100001];
ll a[100001];
ll dfs(int N,int p)
{
	ll sum=0,mx=-1,cnt=0;
	for(int next:v[N])
	{
		if(next==p)continue;
		ll t=dfs(next,N);
		if(t==-INF)return -INF;
		cnt++;
		sum+=t;
		mx=max(mx,t);
	}
	if(cnt==0)return a[N];
	if(cnt==1)
	{
		if(N==1)
		{
			if(sum==a[N])return 0;
			return -INF;
		}
		if(a[N]==sum)return a[N];
		return -INF;
	}
	if(a[N]>sum)return -INF;
	if(a[N]<mx)return -INF;
	if(2*a[N]-sum<0)return -INF;
	return 2*a[N]-sum;
}
int main() {
	int n;
	scanf("%d",&n);
	fup(i,1,n,1)scanf("%lld",a+i);
	fup(i,1,n-1,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	if(dfs(1,-1)==0)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=int(a); i<int(b); ++i)
#define FORD(i,a,b) for(int i=int(a); i<int(b); --i)
#define REP(i,N) for(int i=0; i<int(N); ++i)
#define REPD(i,N) for(int i=0; i<int(N); --i)
#define PB push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //配列の最大のrenge

int main() {
    int N; cin>>N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    int p = 0;
    REP(i,N) {
        if (A[p] == 2) {
            cout << i+1;
            return 0;
        }
        p = A[p] - 1;
    }
    cout << -1;
}

Measured memory_bytes: 3760
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		int N = GetInt();
		string[] s = Enumerable.Range(0, N).Select(_ => GetString()).ToArray();

		var dict = new Dictionary<string, long>();
		for(int i = 0; i < N; i++)
		{
			char[] tmp = s[i].ToCharArray();
			Array.Sort(tmp);
			string t = new String(tmp);
			long num = 0;
			dict.TryGetValue(t, out num);
			dict[t] = num + 1;
		}

		long ans = 0;
		foreach(long num in dict.Values)
			ans += (num * (num - 1)) / 2;
		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 37704
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<tuple>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define tii tuple<int,int>
#define tiii tuple<int,int,int>
#define mt make_tuple
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV 1000007
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
ll labs(ll l){
  if(l < 0)return -l;
  return l;
}
int main(){
  ll n,k; cin >> n >> k;
  vector<ll> vx;
  vector<ll> vy;
  rep(i,n){
    ll x,y; cin >> x >> y;
    vx.pb(x); vy.pb(y);
  }
  ll ans = LLINF;
  rep(i,n){
  rep(j,n){
  rep(kk,n){
  rep(lt,n){
    int cnt = 0;
    rep(m,n){
      if(vx[m] <= vx[i] && vx[m] >= vx[j] && vy[m] <= vy[kk] && vy[m] >= vy[lt])
        cnt++;
    }
    if(vx[i]-vx[j] != 0 && vy[kk]-vy[lt] != 0 && cnt >= k)ans = min(ans,(vx[i]-vx[j] )*(vy[kk]-vy[lt]));
  }
  }
  }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def comb(n, k, p):
    if n<0 or k<0 or n<k:
        return 0
    if n==0 or k==0:
        return 1
    a, b, c = 1, 1, 1
    for i in range(1, n+1):
        a = (a*i)%p
    for i in range(1, k+1):
        b = (b*i)%p
    for i in range(1, n-k+1):
        c = (c*i)%p
    return a*pow(b, p-2, p)*pow(c, p-2, p)%p
X,Y = map(int,input().split())
if (X + Y) % 3 != 0:
    print(0)
else:
    n = int((X+Y)/3)
    p = max(X,Y)
    q = min(X,Y)
    if p > 2 * q:
        print(0)
    else:
        a = 2*n - p
        b = comb(n,a,10**9 + 7)
        print(b)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<cstring>
#include<vector>
using namespace std;

int tot;
map<string,int> mp;
string s,s1,s2;
vector<int> station;
const int maxn = 10010;
const int maxm = 10010;
const int inf = 1000000000;
bool vis[maxn];
int que[maxn];
int d[maxn],d2[maxn];
bool use[maxn];
int n,m,C;
struct EE
{
    int to,ne,w;
}e[maxm * 2];
int L,head[maxn];
void adde(int u,int v,int w)
{
    //cout<<u<<' '<<v<<' '<<w<<endl;
    e[L].to = v;
    e[L].w = w;
    e[L].ne = head[u];
    head[u] = L++;
}
void spfa(int t)
{
    int l,r;
    l = r = 0;
    for (int i = 1; i <= tot; i++)
        vis[i] = false;
    que[r++] = t;
    vis[t] = true;
    while (l != r) {
        int u = que[l++];
        vis[u] = false;
        l %= maxn;
        for (int i = head[u]; i != -1; i = e[i].ne) {
            int v = e[i].to;
            if (d2[v] > d2[u] + e[i].w) {
                d2[v] = d2[u] + e[i].w;
                if (!vis[v]) {
                    que[r++] = v;
                    r %= maxn;
                    vis[v] = true;
                }
            }
        }
    }
}
void work()
{
    for (int i = 1; i <= tot; i++) {
        d2[i] = inf;
    }
    int t,tp;
    tp = inf;
    for (int j = 0; j < station.size(); j++)
    if (!use[j] && d[station[j]] < tp) {
        t = j;
        tp = d[station[j]];
    }
    //cout<<d[station[0]]<<endl;
    if (tp == inf) return;
    //cout<<t<<endl;
    use[t] = true;
    t = station[t];
    d2[t] = 0;
    spfa(t);
    //cout<<C<<endl;
    //for (int j = 1; j <= tot; j++)
    //   cout<<j<<' '<<d2[j]<<endl;
    //cout<<t<<endl;
    for (int j = 1; j <= tot; j++)
    if (d2[j] <= C * 10)
        d[j] = min(d[j],d2[j] + d[t]);
}
int main()
{
    while (scanf("%d%d%d",&n,&m,&C) != EOF) {
        if (n == 0 && m == 0) break;
        L = 0;
        memset(head,-1,sizeof(head));
        mp.clear();
        tot = 0;
        cin>>s1>>s2;
        mp[s1] = ++tot;
        mp[s2] = ++tot;
        for (int i = 0; i < n; i++) {
            cin>>s1>>s2;
            if (mp.find(s1) == mp.end()) {
                mp[s1] = ++tot;
            }
            if (mp.find(s2) == mp.end()) {
                mp[s2] = ++tot;
            }
            int d;
            scanf("%d",&d);
            adde(mp[s1],mp[s2],d);
            adde(mp[s2],mp[s1],d);
        }
        station.clear();
        station.push_back(1);
        for (int i = 0; i < m; i++) {
            cin>>s1;
            station.push_back(mp[s1]);
        }
        for (int i = 0; i <= tot; i++)
            d[i] = inf;
        d[1] = 0;
        for (int i = 0; i < station.size(); i++)
            use[i] = false;
        for (int i = 0; i <= m; i++) {
            work();
        }
        if (d[2] == inf)
            printf("-1\n");
        else
            printf("%d\n",d[2]);
    }
    return 0;
}

Measured memory_bytes: 2164
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int gcd(int a,int b){
    if(b > a){
        swap(a,b);
    }
    bool flag = true;
    int gcdl;
    while(flag){
        if(a%b == 0){
            flag = false;
            gcdl = b;
        }
        else{
            swap(a,b);
            b = b % a;
        }
    }
    return gcdl;
}
int main(){
    int n,x;
    cin >> n >> x;
    int a[n];
    for(int i = 0;i<n;i++){
        cin >> a[i];
        a[i] = abs(a[i] - x);
    }
    if(n == 1){
        cout << a[0] << endl;
    }
    else{
        int ans = gcd(a[0],a[1]);
        for(int i = 2;i<n;i++){
            ans = gcd(ans,a[i]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 640
import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object Main extends App {
    val abn = readLine.split(" ").map(_.toLong)
    val a = abn(0)
    val b = abn(1)
    val n = abn(2)
    def f(a:Long,b:Long,x:Long): Long = {
        (a*x/b)-a*(x/b)
    }
    if(n>=b-1) print(f(a,b,b-1));
    else print(f(a,b,n));
}

Measured memory_bytes: 54548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  string t;
  
  cin >> s >> t;
  
  int num=0;
  for(int i=0; i<3; i++){
    if(s[i]==t[i]){
      num++;
    }
  }
  
  cout << num << endl;
  
}


Measured memory_bytes: 3632
a,b = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(set(prime_factorize(gcd(a,b))))+1)

Measured memory_bytes: 3064
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

def l_s(L):
    return "".join(map(str, L))

import sys
from itertools import groupby as gb

S = input()
K = INT()
g1 = []

if len(set(S)) == 1:
    print(len(S) * K // 2)
    sys.exit()

for _, s in gb(S):
    g1.append(list(s))

tmp = l_s(g1[0]) + l_s(g1[len(g1) - 1])
g2 = []

for _, s in gb(tmp):
    g2.append(list(s))
    
ans = len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2

for i in range(1, len(g1) - 1):
    ans += (len(g1[i]) // 2) * K

for i in range(len(g2)):
    ans += (len(g2[i]) // 2) * (K - 1)
    
print(ans)

Measured memory_bytes: 62128
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s,t;
    cin >> s >> t;
    intl idx = -1;
    rep(i,s.length() - t.length() + 1){
        bool f = true;
        rep(j,t.length()){
            if((s[i + j] != t[j])&&(s[i + j] != '?'))f = false;
        }
        if(f)idx = i;
    }
    string ans = "UNRESTORABLE";
    if(idx != -1){
        ans = s;
        rep(i,t.length()){
            ans[idx + i] = t[i];
        }
        rep(i,s.length()){
            if(ans[i] == '?')ans[i] = 'a';
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from math import sqrt
from collections import defaultdict
def main():
    n = int(input())
    n2 = int(sqrt(n) + 1)
    d1 = defaultdict(int)

    for i1 in range(1, n2):
        for i2 in range(1, n2):
            for i3 in range(1, n2):
                #p = (i1 + i2) ** 2 - (i1 * i2) + i3 * (i1 + i2 + i3)
                p = i1 ** 2 + i2 ** 2 + i3 ** 2 + i1 * i2 + i2 * i3 + i1 * i3
                d1[p] += 1

    for j1 in range(1, n + 1):
        print(d1[j1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 11796
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a>9||b>9){
    System.out.println(-1);
    }else{
    System.out.println(a*b);
    }
  }
}

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

int main(){
  ll N,D;
  cin >> N >> D;
  vector<P> a(N);
  rep(i,N){
    ll x,y;
	cin >> x >> y;
    a.at(i)=make_pair(x,y);
  }
  int cnt=0;
  rep(i,N){
    ll x,y;
    tie(x,y)=a.at(i);
	if(D*D>=x*x+y*y)
      cnt++;
  }
  cout << cnt <<endl;
}

Measured memory_bytes: 6376
#include <cstdio>
#define LL long long  
using namespace std;
const int mod=19260817;
const int base=31;
const int N=305;
char a[N][N],st[N],copy[N][N];
int hashA[N],hashB[N],hashC[N];
LL ksm(LL a,LL k)
{
	LL ans=1;
	for (;k;k>>=1,a=a*a%mod)
	  if (k&1) ans=ans*a%mod;
	return ans;
}
int main()
{
	int n;scanf("%d",&n);int ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%s",st+1);
		for (int j=1;j<=n;j++) a[i][j]=st[j];
	}
	LL inv=ksm(base,mod-2);
	LL what=ksm(base,n-1);
    for (int A=0;A<n;A++)
    {
    	for (int i=1;i<=n;i++)
    	  for (int j=1;j<=n;j++) 
    	    copy[(i+A-1+n)%n+1][j]=a[i][j],hashA[i]=0,hashB[i]=0;
    	    
    	for (int i=1;i<=n;i++)
	      for (int j=1;j<=n;j++) 
	      {
	      	hashB[i]=(hashB[i]*base%mod+copy[j][i])%mod;
			hashA[i]=(hashA[i]*base%mod+copy[i][j])%mod;
		  }
		    
		for (int B=1;B<=n;B++)
		{
			bool fff=1;
			for (int i=1;i<=n;i++)
		      if (hashA[i]!=hashB[i]) {fff=0;break;} 
			if (fff) ans++;
			for (int i=1;i<=n;i++)
			  hashA[i]=((hashA[i]-copy[i][n-B+1]+mod)*inv%mod+copy[i][n-B+1]*what%mod)%mod;
			int t=hashB[n];
			for (int i=n;i>=2;i--)
			  hashB[i]=hashB[i-1];
			hashB[1]=t; 
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
#include <iostream>;
#include <vector>;
using namespace std;
int main() {
 int a,b,c,i; string name;
 cin >> a;
 c = a % 10;
 a = (a - c)/10;
 b = a % 10;
 a = (a - b)/10;
 vector<int> d(3);
 vector<int> e(3);
 d[0] = c;
 d[1] = b;
 d[2] = a;
 i = 0;
  while (2 * i < 5) {
   e[i] = d[i];
   if (d[i] == 1) {
    e[i] = 9;
   }
   if (d[i] == 9) {
    e[i] = 1;
   }
   i = i + 1;
 }
 a = e[0] + 10 * e[1] + 100 * e[2];
 cout << a;
 return 0; 
} 

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	ans := a[0]
	for i := 1; i < n; i++ {
		ans = gcd(ans, a[i])
	}
	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}


Measured memory_bytes: 3200
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define SIZE 524288
class segtree
{
public:
	int seg[SIZE * 2];
	void init()
	{
		fill(seg, seg + SIZE * 2, -1);
	}
	void update(int a, int b)
	{
		a += SIZE;
		seg[a] = max(seg[a], b);
		for (;;)
		{
			a /= 2;
			if (a == 0)break;
			seg[a] = max(seg[a * 2], seg[a * 2 + 1]);
		}
	}
	int get(int beg, int end, int node, int lb, int ub)
	{
		if (ub < beg || end < lb)return -1;
		if (beg <= lb&&ub <= end)return seg[node];
		return max(get(beg, end, node * 2, lb, (lb + ub) / 2), get(beg, end, node * 2 + 1, (lb + ub) / 2 + 1, ub));
	}
};
segtree tree;
int d[505050];
vector<int>pat[505050];
int ans[505050];
int pt = 0;
void dfs(int node)
{
	sort(pat[node].begin(), pat[node].end());
	for (int i = 0; i < pat[node].size(); i++)dfs(pat[node][i]);
	ans[node] = pt++;
}
int main()
{
	int num, gen;
	scanf("%d%d", &num, &gen);
	gen--;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		z--;
		d[z] = i;
	}
	tree.init();
	for (int i = num - 1; i >= 0; i--)
	{
		int r = tree.get(d[i] - gen, d[i], 1, 0, SIZE - 1);
		if (r != -1)pat[d[num - 1 - r]].push_back(d[i]);
		else pat[num].push_back(d[i]);
		tree.update(d[i], num - 1 - i);
	}
	dfs(num);
	for (int i = 0; i < num; i++)printf("%d\n", ans[i] + 1);
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }

LL n, a[100000];
vector<int> g[100000];

LL dfs(int i, int p) {
	vector<LL> v;
	LL sum = 0;
	for(auto && e: g[i]) {
		if(e == p) { continue; }
		LL r = dfs(e, i);
		// cout << e + 1 << ": " << r << endl;
		if(r == -1) { return -1; }
		v.PB(r);
		sum += r;
	}
	sort(RALL(v));
	
	if(v.empty()) { return a[i]; }
	
	LL ma = sum;
	LL mi = max(v[0], ce(sum, 2));
	
	return (inII(a[i], mi, ma) ? ma - 2 * (ma - a[i]) : -1);
}

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	inc(i, n - 1) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].PB(y);
		g[y].PB(x);
	}
	
	inc(i, n) {
		cout << (dfs(i, -1) == (g[i].size() == 1 ? a[i] : 0) ? "YES" : "NO") << endl;
		break;
	}
	
	return 0;
}


Measured memory_bytes: 18560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
using pint = pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll x[n];
    rep(i,n) cin>>x[i];
    ll ans=0;
    rep(i,n-1){
        ans+=min(a*(x[i+1]-x[i]),b);
    }
    cout<<ans<<"\n";
}

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

using namespace std;

int t[5];

int n[5];

int money;

int main(void)
{
	for (int i = 1; i <= 4;i++)
	{
		cin >> t[i] >> n[i];
	}

	

	for (int i = 1; i <= 4; i++)
	{
		if (t[i]==1)
		{
			cout << 6000 * n[i] << endl;
		}
		else if (t[i] == 2)
		{
			cout << 4000 * n[i] << endl;
		}
		else if (t[i] == 3)
		{
			cout << 3000 * n[i] << endl;
		}
		else if (t[i] == 4)
		{
			cout << 2000 * n[i] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3064
def solve(a, b, k):
    num = 0
    for i in range(100, 0, -1):
        if a % i == 0 and b % i == 0:
            num += 1
        if num == k:
            return i


def main():
    a, b, k = map(int, input().split())

    ans = solve(a, b, k)
    print(ans)


main()

Measured memory_bytes: 3060