akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))
#define int long long
using namespace std;

const int N = 20;
const int row[4] = {0, -1, 0, 1};
const int col[4] = {-1, 0, 1, 0};

int h, w;
int vis[N][N];
int cost[N][N][N][N];
string s[N];

int can (int x, int y) {
  if (x < 0 || x >= h || y < 0 || y >= w) return 0;
  if (s[x][y] == '#') return 0;
  return 1;
}

void shortest_path (int beg_row, int beg_col) {
  memset (vis, 0, sizeof vis);
  queue <pair <int, int>> q;
  queue <int> deep;
  q.push({beg_row, beg_col});
  deep.push(0);
  while (!q.empty()) {
    int cur_row = q.front().first;
    int cur_col = q.front().second;
    int cur_level = deep.front();
    deep.pop(); q.pop(); 
    vis[cur_row][cur_col] = 1;
    assert (cost[beg_row][beg_col][cur_row][cur_col] == INT_MAX);
    cost[beg_row][beg_col][cur_row][cur_col] = cur_level;
    for (int i = 0; i < 4; i++) {
      int tar_row = row[i] + cur_row;
      int tar_col = col[i] + cur_col;
      if (can (tar_row, tar_col) && vis[tar_row][tar_col] == 0) {
        q.push({tar_row, tar_col});
        deep.push (cur_level + 1);
        vis[tar_row][tar_col] = 1;
      }
    }
  }
}

signed main () {
  boost();
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int ii = 0; ii < N; ii++) {
        for (int jj = 0; jj < N; jj++) {
          cost[i][j][ii][jj] = INT_MAX;
        }
      }
    }
  }
  vector <pair <int, int>> v;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      v.push_back ({i, j});
      shortest_path (i, j);
    }
  }
  int res = 0;
  int n = (int)v.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      res = max (res, cost[v[i].first][v[i].second][v[j].first][v[j].second]);
    }
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 1536
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  for(int i=1; i<=1000; i++) {
    if(i*100<=x&&x<=i*105) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

ll n,z,w;
ll a[2000];

int main(){
  cin >> n>>z>>w;
  REP(i,n) cin >> a[i];
  if(n==1){
    z = a[0];
    cout << abs(z-w) << endl;
    return 0;
  }
  cout << max(abs(a[n-1]-w),abs(a[n-2]-a[n-1])) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
	ll n,a[200010];
	cin >> n;
	ll sum=0;
	FOR(i,n){
		cin >>a[i];
		sum+=a[i];
	}
	ll ans=202020202020,cnt=0;
	chmin(ans,abs(sum-cnt-cnt));
	FOR(i,n){
		cnt+=a[i];
		chmin(ans,abs(sum-cnt-cnt));
	}

cout << ans << endl;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int max_h = 10005;
int max_n = 1005;
int n;
vector<int> a(max_n);
vector<int> b(max_n);

vector<int> memo(max_h, -1);

long long mahou(int h) {
  long long magic = 10e+10;
  if (h <= 0) return 0;
  if (memo[h] != -1) return memo[h];
  for (int i = 0; i < n; i++) {
    magic = min(magic, (b.at(i) + mahou(h - a.at(i))));
  }
  return memo[h] = magic;
}

int main() {
  int h;
  cin >> h >> n;

  for (int i = 0; i < n; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  long long ans = 0;
  ans = mahou(h);
  cout << ans;
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,m,k,ans,a,b;
    	string s,t;
    	cin>>a>>b>>k;
    	if(a>=k)
    	{
    		a=a-k;
			k=0;
		}
		else
		{
			k=k-a;
			a=0;
		}
		if(b>=k)
    	{
    		b=b-k;
			k=0;
		}
		else
		{
			b=0;
		}
		cout<<a<<" "<<b;
    } 
	return 0;
}

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

int distance(int x1, int y1, int x2, int y2){
	return abs((x1-x2)) + abs((y1-y2));
}

int main(){
	using namespace std;
	int n,a,b,c,d,sum=300;
	cin >> n;
	cin >> a >> b;
	cin >> c >> d;
	a--;b--;c--;d--;

	for(int width = n; width >= 1; width--){
		int AtoB,CtoD,total;
		AtoB = distance(a/width, a%width, b/width, b%width);
		CtoD = distance(c/width, c%width, d/width, d%width);
		if(sum > AtoB + CtoD) sum = AtoB + CtoD;
	}
	cout << sum << endl;
}

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

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int fnGcd(int nOne, int nOtr)
{
  if (nOtr == 0)
    return nOne;
  else
    return fnGcd(nOtr, nOne % nOtr);
}

int fnMaxGcd(const vector<int>& cnrvnNum)
{
  vector<int> vnLeftGcd(cnrvnNum.size());
  vector<int> vnRigtGcd(cnrvnNum.size());
  int nMaxGcd = 0;

  vnLeftGcd[0] = cnrvnNum[0];
  
  for (int i = 1; i < cnrvnNum.size(); i++)
    vnLeftGcd[i] = fnGcd(vnLeftGcd[i - 1], cnrvnNum[i]);
  
  vnRigtGcd[cnrvnNum.size() - 1] = cnrvnNum[cnrvnNum.size() - 1];

  for (int i = cnrvnNum.size() - 2; i >= 0; i--)
    vnRigtGcd[i] = fnGcd(vnRigtGcd[i + 1], cnrvnNum[i]);

  for (int i = 0; i < cnrvnNum.size(); i++)
    if (i == 0)
      nMaxGcd = max(nMaxGcd, vnRigtGcd[i + 1] );
    else if (i == cnrvnNum.size() - 1)
      nMaxGcd = max(nMaxGcd, vnLeftGcd[i - 1] );
    else
      nMaxGcd = max(nMaxGcd, fnGcd(vnLeftGcd[i - 1], vnRigtGcd[i + 1] ));
  
  return nMaxGcd;
}
 
int main()
{
  vector<int> vnNum;

  fnInput(vnNum);
  cout << fnMaxGcd(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 4236
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <complex>
#define rep(i, b) for(int i = 0; i < (b); i++)
#define repi(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(u) (u).begin(), (u).end()
#define INF 100000000

using namespace std;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	reverse(ALL(s));
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 1172
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;
  ll n=s.size();
  ll k;cin>>k;
  ll dp[110][4][2];
  rep(i,n){
    rep(j,4){
      rep(k,2)dp[i][j][k]=0;
    }
  }
  dp[0][1][0]=s[0]-'0'-1;
  dp[0][1][1]=1;
  for(ll i=1;i<n;i++){
    for(ll j=1;j<4;j++){
      if(s[i]=='0'){
        dp[i][j][1]+=dp[i-1][j][1];
      }
      else {
        dp[i][j][1]+=dp[i-1][j-1][1];
        dp[i][j][0]+=(s[i]-'0'-1)*dp[i-1][j-1][1];
        dp[i][j][0]+=dp[i-1][j][1];
      }
      dp[i][j][0]+=9*dp[i-1][j-1][0];
      dp[i][j][0]+=dp[i-1][j][0];
    }
    dp[i][1][0]+=9;
  }
  ll ans=0;
  
  ans+=dp[n-1][k][0];
  ans+=dp[n-1][k][1];
  
  cout<<ans<<endl;
  //rep(i,4){
    //rep(j,4){
      //rep(t,2)cout<<dp[i][j][t]<<" ";
    //}
    //cout<<endl;
  //}
}
  


Measured memory_bytes: 256
n=input()

if n[0]=="1":
  ans="9"
  
else:
  ans="1"
  
if n[1]=="1":
  ans+="9"
  
else:
  ans+="1"
  
if n[2]=="1":
  ans+="9"
  
else:
  ans+="1"
  
print(ans)

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

int main()
{
	string s;
	cin >> s;
	int counter = 0;
	if (s[0] == '1') ++counter;
	if (s[1] == '1') ++counter;
	if (s[2] == '1') ++counter;
	cout << counter << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	long long int cnt[200005];
	for (i = 0; i <= n; i++)
		cnt[i] = 0;
	long long int ans = 0;
	for (i = 0; i < n; i++)
	{
		if (i - a[i] >= 0 && i - a[i] <= n)
			ans += cnt[i - a[i]];
		if (a[i] + i <= n)
			cnt[i + a[i]]++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cout << v << " ";  \
  }                    \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char c[3][3];
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  REP(i, 3) REP(j, 3) cin >> c[i][j];
  REP(i, 3) cout << c[i][i];
  cout << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N,T,S;
int A[3000];int B[3000];
int DP[3001][3000];
int ans=0;
int main()
{
	scanf("%d%d%d",&N,&T,&S);
	for(int i=0;i<N;i++)scanf("%d%d",&A[i],&B[i]);
	for(int i=0;i<=T;i++){
		int ma=0;
		for(int j=0;j<N;j++){
			if(j!=0)ma=max(ma,DP[i][j-1]);
			if(i+B[j]>T)continue;
			if(i+B[j]>S&&i<S){
				DP[S][j]=max(DP[S][j],DP[i][j]);
			}
			else{
				DP[i+B[j]][j]=max(DP[i+B[j]][j],A[j]+ma);
				//if(i==9&&j==1)printf("%d:%d\n",i+B[j],ma);
				
				//if(i==9)printf("%d:%d\n",j,ma);
			}
		}
	}
	for(int i=0;i<=T;i++){
		for(int j=0;j<N;j++){
			//printf("%d,%d:%d\n",i,j,DP[i][j]);
			ans=max(ans,DP[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 36372
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
const int C=1<<16, D=17;

int pw[D], dg[C], lmost[C], n, F[D];
ll dp[C], dp2[C], a[D][D];

ll sum(int c, int b){
	ll s=0;
	for (;b>0;b=(b^pw[lmost[b]]))	{
		s+=a[c][lmost[b]];
	}
	return s;
}

int main(){
	int i, j, s=2, act=1, z, b, x, y, m;
	pw[0]=1, dg[0]=0, lmost[0]=-1;
	
	for (i=1;i<D;i++)	pw[i]=pw[i-1]*2;
	
	for (i=1;i<C;i++){
		lmost[i]=lmost[i/2]+1;
		
		if (i-s<0)	dg[i]=act, s=2, act++;
		else dg[i]=dg[i-s], s+=2;
	}
	
	
	scanf ("%d", &n);
	for (i=0;i<n;i++){
		for (j=0;j<n;j++){
			scanf ("%lld", &a[i][j]);
		}
	}
	
	for (i=1;i<pw[n];i++)	dp[i]=dp[i^pw[lmost[i]]]+sum(lmost[i], i^pw[lmost[i]]);
	
	for (i=1;i<pw[n];i++){
		z=i, x=i;
		for (j=0;z>0;j++,z=(z^pw[lmost[z]]))	F[j]=lmost[z];
		m=j;
		dp2[i]=max(dp2[i], dp[x]);
		for (j=0;j<pw[m]-1;j++){
			x^=pw[F[dg[j]]];
			y=(i^x);
			
			dp2[i]=max(dp2[i], dp[x]+dp2[y]);
		}
	}
	
	printf ("%lld", dp2[pw[n]-1]);
	
return 0;}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF INT_MAX
const int maxn=5e5+10;
int L[maxn/2+2],R[maxn/2+2];
int cnt;
void merge(int A[],int n,int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1]=R[n2]=INF;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        cnt++;//记录比较次数
        if(L[i]<=R[j]) A[k]=L[i++];
        else A[k]=R[j++];
    }
}
void mergeSort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }

}
int main()
{
    int A[maxn],n;
    cnt=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    mergeSort(A,n,0,n);
    for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<A[i];
    }cout<<endl;
    cout<<cnt<<endl;
}


Measured memory_bytes: 6932
#include <cstdio>
#include <cstdlib>
#include <cmath>
const static double EPS = 1e-5;

double cube( double x ) {
  return x * x * x;
}

int main() {

  while( 1 ) {
    int q;
    scanf( "%d", &q );
    if( q == -1 ) { break; }

    double x;
    for(
        x = q / 2.0;
        fabs( cube( x ) - q ) >= q * EPS;
        x = x - ( cube( x ) - q ) / ( 3 * x * x )
       );

    printf( "%.6f\n", x );

  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1060
while n = gets.to_i
  break if n == 0
  day = 31.times.map{ [] }
  res = -1
  n.times do |i|
    gets.split.map(&:to_i)[1..-1].each{ |d| day[d] <<i }
  end
  pce = n.times.map{ |i| 1<<i }
  day.each_with_index do |d, i|
    cur = pce.each_with_object([]).with_index{|(p, arr), i| arr << p if d.include?(i)}.reduce(0){ |p, c| c|p }
    if cur == (1<<n) - 1
      res = i
      break
    end
    pce.each_with_index{ |p, i| pce[i] = cur if d.include?(i) }
  end
  p res
end

Measured memory_bytes: 8992
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <iostream>
using namespace std;

void split(const char* input,int in_result[100]){
  string str{input};
  istringstream stream(input);
  string tmp;
  
  for(int i = 0; getline(stream, tmp, ' '); i++)
    in_result[i] = atoi(tmp.c_str()); 
}


int main(){
  int parson_num; 
  int game_num;

  scanf("%d",&parson_num);
  scanf("%d",&game_num);
  getchar();
 
  int write_names[game_num][parson_num]; 
  char tmp[10 * game_num + game_num];

  fgets(tmp,sizeof(tmp),stdin);
  int targets[100] = {}; 
  split(tmp,targets);

  for(int i = 0; i < game_num; i++){
    fgets(tmp,sizeof(tmp),stdin);
    split(tmp,write_names[i]);
  }

  int points[parson_num] = {};

  for(int i = 0; i < game_num; i++){
    for(int j = 0; j < parson_num; j++){
      if(write_names[i][j] == targets[i]) points[j]++;
      else points[targets[i] - 1]++;
    }
  }

  for(int i:points) printf("%d\n",i);
}     

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int d(int n) {
  if(n == 0) return 1;
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  vi s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  rep(i, 1000) {
    if(d(i) != n) continue;
    bool ok = true;
    rep(j, m) if(to_string(i)[s[j] - 1] - '0' != c[j]) ok = false;
    if(ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int tot = 0;
	
	int bi = 0;
	rep(i, n) {
		bool ok = false;
		if (s[i] == 'a' && tot < a + b) {
			ok = true;
			tot++;
		} else if (s[i] == 'b' && tot < a + b && bi < b) {
			bi++;
			ok = true;
			tot++;
		}
		if (ok) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 848
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
struct _ListNode
{
    struct _ListNode *next;
    char *str;
};

typedef struct _ListNode ListNode;

ListNode *new_node(char *str);
void delete_node(ListNode *node);
ListNode *add_word(ListNode *node, char *str);
bool search_word(ListNode *node, char *str);
void show_list(ListNode *node);
void word_ai(char head, char *buf);
char last_char(char *str);

int main()
{
    int i;
    char outbuf[8];
    char inbuf[4];
    ListNode *head = NULL;

    printf("?aaaaaa\n"); fflush(stdout);
    while( 1 ) {
        scanf("%s", inbuf);

        if (inbuf[0] != 'a' || search_word(head, inbuf)) { break; }
        head = add_word(head, inbuf);
        
        word_ai(last_char(inbuf), outbuf);
        printf("?%s\n", outbuf); fflush(stdout);
    }
    printf ("!OUT\n");

    return 0;
}


ListNode * new_node(char *str)
{
    int len = strlen(str);
    ListNode *node = (ListNode *) malloc(sizeof(ListNode));
    node->next = NULL;
    node->str = (char *) malloc(sizeof(char) * (len + 1));
    strcpy(node->str, str);
    return node;
}

void delete_node(ListNode *node)
{
    free(node->str);
    free(node);
}

ListNode *add_word(ListNode *node, char *str)
{
    ListNode *newhead = new_node(str);
    newhead->next = node;
    return newhead;
}

bool search_word(ListNode *node, char *str)
{
    for(; node != NULL; node = node->next)
    {
        if (strcmp(str, node->str) == 0){
            return true;
        }
    }
    return false;
}

void show_list(ListNode *node)
{
    for(; node != NULL; node = node->next)
    {
        printf("%s\n", node->str);
    }
}

void word_ai(char head, char *buf)
{
    static int cnt = 0;
    buf[0] = head;
    buf[1] = 'a' + (cnt % 26);
    buf[2] = 'a' + (cnt / 26);
    buf[3] = 'a';
    buf[4] = '\0';
    cnt++;
}

char last_char(char *str)
{
    while (*(str + 1)) { str++; }
    return *str;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	rep(i, m){
		int x;
		cin >> x;
		n -= x;
	}

	if(n < 0) cout << -1;
	else cout << n;
	
	return 0;
}

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

int bmm(int a,int b){
	if(a==0)
		return b;
	if(b==0)
		return a;
		
	if(a<b)
		swap(a,b);
		
	return bmm(a%b,b);
}

int main(){	
	int n,k;
	cin>>n>>k;
	
	int b;
	int x1;
	cin>>x1;
	b=x1;
	
	int max=x1;
	for(int i=1;i<n;i++){
		int xi;
		cin>>xi;
		b=bmm(b,xi);
		
		if(xi>max)
			max=xi;
	}
	
	if(k%b == 0 && k<=max)
		cout<<"POSSIBLE";
	else 
		cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 256
import math
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())


def factor(n, f_dict):
    """素因数分解してdictionaryを返す"""
    num = n
    for i in range(2, int(math.sqrt((n)))+1):
        while num % i == 0:
            num = int(num / i)
            fact_dict[i] += 1
        if num == 1:
            return fact_dict
    fact_dict[num] += 1
    return fact_dict


fact_dict = defaultdict(lambda: 0)
for n in range(2, N+1):
    fact_dict = factor(n, fact_dict)


g_2 = []
g_4 = []
g_14 = []
g_24 = []
g_74 = []
for k, v in fact_dict.items():
    if v >= 74:
        g_74.append(k)
    if v >= 24:
        g_24.append(k)
    if v >= 14:
        g_14.append(k)
    if v >= 4:
        g_4.append(k)
    if v >= 2:
        g_2.append(k)

len_2 = len(g_2)
len_4 = len(g_4)
len_14 = len(g_14)
len_24 = len(g_24)
len_74 = len(g_74)

print(len_74+len_24*(len_2-1)+len_14*(len_4-1)+len_4*(len_4-1)//2*(len_2-2))


Measured memory_bytes: 3316
import bisect
import itertools
import sys

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]


def calc(a, b, x):
    return min(abs(a-x), abs(b-x)) + abs(a-b)


for i in range(len(x)):
    s_RL = most_simRL(s, x[i])
    t_RL = most_simRL(t, x[i])
    ans = sys.maxsize
    for st in itertools.product(s_RL, t_RL):
        distance = calc(st[0], st[1], x[i])
        if ans > distance:
            ans = distance
    print(ans)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int main(){

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

    string s;
    cin >> s;

    vector<int> cnt(3, 0);

    rep(i, s.size()){
        if(s[i] == 'a') ++cnt[0];
        if(s[i] == 'b') ++cnt[1];
        if(s[i] == 'c') ++cnt[2];
    }
    for(int i = 0; i < 3; ++i){
        for(int j = i+1; j < 3; ++j){
            if(abs(cnt[j]-cnt[i]) > 1){
                NO();
                return 0;
            }
        }
    }
    YES();

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	ll num1 = (ll)A * (N - 1) + B;
	ll num2 = (ll)B * (N - 1) + A;
	if (A > B) cout << 0 << endl;
	else if (N == 1) {
		if (A == B) cout << 1 << endl;
		else cout << 0 << endl;
	}
	else cout << num2 - num1 + 1 << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

map<ll, ll> primeFactor(ll n) {
	map<ll, ll> ret;

  for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			n /= i;
			ret[i]++;
		}
	}

	if (n != 1) ret.insert({ n,1 });

	return ret;
}

int main() {
	int n;
	cin >> n;
  
	map<ll,ll> factpf;
	rep1(i, n) {
		map<ll,ll> pf = primeFactor(i);
		for (auto pe : pf) {
			factpf[pe.first] += pe.second;
		}
	}

	ll ans = 1;
	for(auto pe : factpf) { 
	  ans *= (pe.second+1) % MOD;
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int n,a[5];
	scanf("%d",&n);
	a[0]=n%10;
	a[1]=n/10%10;;
	a[2]=n/100%10;
	a[3]=n/1000;
	sort(a,a+4);
	if(a[0]==a[1]&&a[1]==a[2])printf("Yes\n");
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x[10000],y[10000],i=0,j,k=0,a;
	while(k==0){
		i++;
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0 && y[i]==0){
			k=1;
		}
	}
	for(j=1;j<=i-1;j++){
		if(x[j]>y[j]){
			a=y[j];
			y[j]=x[j];
			x[j]=a;
		}
		printf("%d %d\n",x[j],y[j]);
	}
	return 0;
}

Measured memory_bytes: 1748
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

int n, ans=0x3f3f3f3f;

int doit(int n)
{
	int sum=0;
	while(n!=0)
	{sum+=n%10;
	n/=10;
	}
	
	return sum;
}

int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n/2; i++)
	{
		int temp=0;
		temp+=doit(i);
		temp+=doit(n-i);
		ans=min(ans, temp);
	}
	printf("%d\n", ans);	
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N,K; cin>>N>>K;
	vector<ll> A(N);
	rep(i,N) cin>>A[i];
	if(N==1){
		if(A[0]==K) cout<<"POSSIBLE";
		else cout<<"IMPOSSIBLE";
	}
	else{
		ll GCD=gcd(A[0],A[1]);
		ll MAX=max(A[0],A[1]);
		for(int i=2;i<=N-1;i++){
			GCD=gcd(GCD,A[i]);
			MAX=max(MAX,A[i]);
		}
		if(K%GCD==0 && K<=MAX) cout<<"POSSIBLE";
		else cout<<"IMPOSSIBLE";
	}
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);

	//0121
	static class SevenPuzzle {
		String puzzle;
		int[] dir = {1, -1, 4, -4};

		void print_min_movedNum() {
			HashMap<String, Integer> map = new HashMap<String, Integer>();
			Queue<String> que = new LinkedList<String>();
			que.offer("01234567");
			map.put("01234567", 0);

			while(!que.isEmpty()) {
				String npuzzle = que.poll();
				int ind = npuzzle.indexOf('0');
				for(int i=0; i<4; i++) {
					if(ind % 4 == 0 && i == 1) continue;
					if(ind % 4 == 3 && i == 0) continue;
					if(!check(ind + dir[i])) continue;
					swap(npuzzle, ind, i);
					if(map.containsKey(puzzle)) continue;
					que.offer(puzzle);
					map.remove(puzzle);
					map.put(puzzle, new Integer(map.get(npuzzle) + 1));
				}
			}

			while(sc.hasNext()) {
				StringBuffer sb = new StringBuffer();
				for(int i=0; i<8; i++) {sb.append(sc.nextInt());}
				System.out.println(map.get(new String(sb)));
			}
		}

		boolean check(int n) {return n >= 0 && n < 8;}

		void swap(String npuzzle, int ind, int i) {
			StringBuffer sb = new StringBuffer(npuzzle);
			char tmp = sb.charAt(ind);
			sb.setCharAt(ind, sb.charAt(ind + dir[i]));
			sb.setCharAt(ind + dir[i], tmp);
			puzzle = new String(sb);
		}
	}

	public static void main(String[] args) {
		// 0121
		SevenPuzzle sp = new SevenPuzzle();
		sp.print_min_movedNum();
	}
}

Measured memory_bytes: 15000
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int a, b, c, d, e, f;

void solve() {
    double d_max = -INF;
    int w_ans = 0, s_ans = 0;
    REP(i, f / 100 + 1)REP(j, f / 100 + 1)REP(k, f / c + 1)REP(l, f / d + 1) {
                    double w = 100 * a * i + 100 * b * j, s = c * k + d * l;
                    if (w + s <= f && s / w <= double(e) / 100) {
                        if (s / (s + w) > d_max) {
                            d_max = s / (s + w);
                            w_ans = (int) w, s_ans = (int) s;
                        }
                    }
                }
    printf("%d %d", w_ans + s_ans, s_ans);
}

int main() {
    cin >> a >> b >> c >> d >> e >> f;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[10000],b[10000],n1,n2;
int main()
{
  int i=0,key,cnt=0,j;
  scanf("%d",&n1);
  for(i=0;i<n1;i++)
    {
      scanf("%d",&a[i]);
    }
  scanf("%d",&n2);
  for(i=0;i<n2;i++)
    {
      scanf("%d",&b[i]);
    }
  for(i=0;i<n2;i++)
    {
      a[n1] = b[i];
      j=0;
      while(a[j]!=a[n1])
	{
	  j++;
	}
      if(j==n1)continue;
      else
	{
	  cnt++;
	  continue;
	}
    }
  printf("%d\n",cnt);
  return 0;
}





Measured memory_bytes: 2044
n=int(input())
s=list(input())
cnt=0
for i in range (10):
  i=str(i)
  for j in range (10):
    j=str(j)
    for k in range (10):
      k=str(k)
      if s.count(i)!=0:
        a=s.index(i)
        x=s[(a+1):]
        if x.count(j)!=0:
          b=x.index(j)
          y=x[(b+1):]
          if y.count(k)!=0:
            cnt+=1
 
print(cnt)     

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  std::cout << (n + 1) / 2 << "\n";
}


Measured memory_bytes: 256
# merge_sort
# 1. divide
# 2. solve
# 3. conquer

n = gets.to_i
@arr = gets.split.map(&:to_i)
@count = 0
@L = []
@R = []
SENTINEL = 20000000000.freeze

def merge(n, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  n1.times do |i|
    @L[i] = @arr[left + i]
  end
  
  n2.times do |i|
    @R[i] = @arr[mid + i]
  end
  
  @L[n1] = SENTINEL
  @R[n2] = SENTINEL
  
  i = 0
  j = 0
  (left...right).each do |k|
    @count += 1
    
    if @L[i] <= @R[j]
      @arr[k] = @L[i]
      i += 1
    else
      @arr[k] = @R[j]
      j += 1
    end
  end
end

def merge_sort(n, left, right)
  if left+1 < right
    mid = (left + right) / 2
    merge_sort(n, left, mid)
    merge_sort(n, mid, right)
    merge(n, left, mid, right)
  end
end

merge_sort(n, 0, n)

@arr.each_with_index do |v, idx|
  print " " if idx > 0
  print v
end

print "\n"
puts @count


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int d,g;
    cin >> d >> g;
    vi p(d),c(d);
    rp(i,d){
        cin >> p[i] >> c[i];
    }
    int Min=INT_MAX;
    rp(bit,(1<<d)){
        int cnt=0,point=0;
        rp(i,d){
            if(bit&(1<<i)){
                cnt += p[i];
                point += 100*(i+1)*p[i]+c[i];
            }
        }
        if(point<g){
            rp(i,d){
                if(!(bit&(1<<(d-1-i)))){
                    rp(j,p[d-1-i]){
                        cnt++;
                        point += 100*(d-i);
                        if(j==p[d-1-i]-1&&point<g){
                            point += c[d-1-i];
                        }
                        if(point>=g){
                            goto End;
                        }
                    }
                }
            }
        }
    End:
        ;
        if(point>=g){
            Min = min(Min,cnt);
        }

    }
    cout << Min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;
int main()
{
    int F,L,Z,K;
    while(scanf("%d %d %d",&F,&L,&K)!=EOF)
    {
        int temp=F;
        for(int i=0; i<K; i++)
        {
            if(temp>L)
                break;
            printf("%d\n",temp++);
        }
        Z=L-K+1;
        if(temp<Z)
            temp=Z;
        for(int i=0; i<K; i++)
        {
            if(temp>L)
                break;
            printf("%d\n",temp++);
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    sc.nextLine();
   	String d[] = sc.nextLine().split(" ", 0);
    int sum =0;
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int a =Integer.parseInt(d[i]);
        int b =Integer.parseInt(d[j]);
        sum+=a*b;
      }
    }
    
    System.out.println(sum);
    
  }
}

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

int main(){
  int M, N;
  cin >> M >> N;
  string s, t;
  cin >> s >> t;
  for (auto& si: s) {
    if (si == 'I') {
      si = '1';
    } else {
      si = '0';
    }
  }
  for (auto& ti: t) {
    if (ti == 'I') {
      ti = '1';
    } else {
      ti = '0';
    }
  }
  vector<vector<vector<int>>> dp(M+1,vector<vector<int>>(N+1,vector<int>(2,-1)));
  for(int i = 0; i <= M; ++i){
    for(int j = 0; j <= N; ++j){
      for(int k = 0; k < 2; ++k){
        if(s[i] == '1') dp[i+1][j][1] = max(dp[i+1][j][1],1);
        if(t[j] == '1') dp[i][j+1][1] = max(dp[i][j+1][1],1);
        if(i+1 <= M and k != s[i]-'0')
          dp[i+1][j][1-k] = max(dp[i+1][j][1-k],dp[i][j][k]+1);
        if(j+1 <= N and k != t[j]-'0')
          dp[i][j+1][1-k] = max(dp[i][j+1][1-k],dp[i][j][k]+1);
      }
    }
  }
  int ans = 0;
  for(int i = 0; i <= M; ++i){
    for(int j = 0; j <= N; ++j){
      ans = max(ans,dp[i][j][1]);
      // fprintf(stderr,"i=%d, j=%d, k=%d, dp=%d\n",i,j,0,dp[i][j][0]);
      // fprintf(stderr,"i=%d, j=%d, k=%d, dp=%d\n",i,j,1,dp[i][j][1]);
    }
  }
  if(ans%2 == 0 and ans > 0) --ans;
  cout << ans << endl;
}



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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, k;
  cin >> n >> k;

  vll a(n + 1);
  ll nl = 0;
  ll nh = 0;
  REP(i, n + 1) {
    cin >> a[i];
  }

  if (nh > 0) {
    cout << nl << endl;
    return 0;
  }

#if 0
  vvi ldp(n + 2, vi(k + 1));
  vvi rdp(n + 2, vi(k + 1));
#else
  using vc = vector<char>;
  using vvc = vector<vc>;
  vvc ldp(n + 2, vc(k + 1));
  vvc rdp(n + 2, vc(k + 1));
#endif

  ldp[0][0] = 1;
  rdp[n + 1][0] = 1;

  REP(i, n + 1) {
    rep(j, k) {
      ldp[i][j] |= ldp[i - 1][j];
      if (j + a[i] < k) {
        ldp[i][j + a[i]] |= ldp[i - 1][j];
      } else {
        ldp[i][k] = ldp[i - 1][j];
      }
    }
  }

  for (ll i = n; i >= 1; i--) {
    rep(j, k) {
      rdp[i][j] |= rdp[i + 1][j];
      if (j + a[i] < k) {
        rdp[i][j + a[i]] |= rdp[i + 1][j];
      } else {
        rdp[i][k] = rdp[i + 1][j];
      }
    }
  }

  ll ans = n;

  REP(i, n + 1) {
    vll l, r;
    rep(j, k + 1) {
      if (ldp[i - 1][j]) {
        l.push_back(j);
      }
      if (rdp[i + 1][j]) {
        r.push_back(j);
      }
    }

    // (k - a[i]) <= (l[i] + r[j]) < k
    // となるl, rの組を探す
    for (auto val : l) {
      ll tl = k - a[i] - val;
      ll tr = k - val;

      auto itr = lower_bound(all(r), tl);
      if (itr != r.end() && *itr < tr) {
        ans--;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 52856
import math

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

distance = math.sqrt(d * d)

cnt = 0

for i in range(n):
    x,y = map(int,input().split())
    x2 = x * x
    y2 = y * y
    result = math.sqrt(x2 + y2)

    if distance >= result:
        cnt += 1

print(cnt)

Measured memory_bytes: 9168
#include <stdio.h>
int main ()
{
  int a,b,c,x,y=0;
  1<=a<=10000;
  1<=b<=10000;
  1<=c<=10000;
  a<=b;
  scanf("%d %d %d",&a, &b, &c);
  for(x=a; x <=b; x++){
    if(c%x==0)
      y++ ;
    else if(b==x)break;
  }
  printf("%d\n",y);
  
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

long long N;
long long U[220000];
long long V[220000];

int main(void){

    cin >> N;

    for (int i = 1;i <= N - 1;i++) {
        cin >> U[i] >> V[i];
    }

    long long A[N+1];
    for (int i = 1;i <= N;i++) {
        A[i] = 0;
    }

    long long Delv = 0;

    for (int i = 1;i <= N - 1;i++) {
        if(U[i] < V[i]){
            Delv += N + 1 - V[i];
            A[U[i]] += N + 1 - V[i];
        } else {
            Delv += N + 1 - U[i];
            A[V[i]] += N + 1 - U[i];
        }
    }

    long long ans = 0;

    for (int i = 1;i <= N;i++){
        ans += (N + 1 - i) * (N + 2 - i) / 2 - Delv;
        Delv -= A[i];
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> dishes(N);
  vector<int> s(N);
  vector<int> p(N-1);

  for (int i=0; i<N; ++i) {
    cin >> dishes[i];
  }
  for (int i=0; i<N; ++i) {
    cin >> s[i];
  }
  for (int i=0; i<N-1; ++i) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i=0; i<N; ++i) {
    ans += s[i];
    if (i==N-1) continue;
    if (dishes[i] + 1 == dishes[i+1]) {
      ans += p[dishes[i]-1];
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
int point (int a,int b,int aa,int bb);

int point (int a, int b, int aa, int bb){
    int x;
    if(a+b==1){
        if(a-b==-1){
            x=2;
        }else{
            x=5-2;
        }
    }else if(a+b==2){
        if(a-b==2){
            x=1;
        }else{
            x=5-1;
        }
    }else{
        if(a-b==-1){
            x=0;
        }else{
            x=5-0;
        }
    }
    if(aa+bb==1){
        x=5-x;
    }
    
    return x;
}

int main(void){
    int Input[6];
    int Num;
    int InNumA,InNumB;
    int A,B;
    int AA,BB;
    int a,b,i;
    
    for(a=0;a<6;a++){
        scanf("%d",&Input[a]);
    }
    scanf("%d",&Num);
    for(i=0;i<Num;i++){
        scanf("%d %d",&InNumA,&InNumB);
        for(a=0;a<6;a++){
            if(Input[a]==InNumA){
                for(b=0;b<6;b++){
                    if(Input[b]==InNumB){
                        if(a>2){
                            A=5-a;
                            AA=1;
                        }else{
                            A=a;
                            AA=0;
                        }
                        if(b>2){
                            B=5-b;
                            BB=1;
                        }else{
                            B=b;
                            BB=0;
                        }
                        printf("%d\n",Input[point(A,B,AA,BB)]);
                        break;
                    }
                }
                break;
            }
        }
    }
}


Measured memory_bytes: 2144
N,M=map(int,input().split())
A=[]
B=[True]*(N+1)
DP=[0]*(N+1)
DP[0]=1
for i in range(M):
  A.append(int(input()))
for i in range(M):
  B[A[i]]=False
#print(B)

for i in range(1,N+1):
  if B[i]==False:
    DP[i]=0
  else:
    if i==1:
      DP[i]=DP[i-1]
    else:
      DP[i]=DP[i-1]+DP[i-2]
if DP[N]==0:
  print(0)
else:
  print(DP[N]%1000000007)

Measured memory_bytes: 460788
#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 yakusuu(int x) {
  int res = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      if (x == i * i) {
        res += 1;
      } else {
        res += 2;
      }
    }
  }
  return res;
}


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

  ll ans = 0;
  for (int c = 1; c < n; c++) {
    int ab = n - c;
    ans += yakusuu(ab);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    vector<ll> a;
    REP(i, n) {
        ll tmp; cin >> tmp;
        a.push_back(tmp);
    }
    sort(ALL(a));
    if (a.size() == 2) {
        cout << a[1] << " " << a[0] << endl;
    } else {
        ll mx = a[a.size()-1];
        ll mid = mx / 2;
        ll res = -1;
        ll res_diff = 1e10;
        if (mx % 2 == 0) {
            REP(i, n) {
                if (a[i] == mx) {
                    continue;
                }
                ll diff = abs(a[i] - mid);
                if (diff < res_diff) {
                    res = a[i];
                    res_diff = diff;
                }
            }
            cout << mx << " " << res << endl;
        } else {
            REP(i, n) {
                if (a[i] == mx) {
                    continue;
                }
                ll diff = min(abs(a[i] - mid), abs(a[i] - mid - 1));
                if (diff < res_diff) {
                    res = a[i];
                    res_diff = diff;
                }
            }
            cout << mx << " " << res << endl;
        }
        return 0;
    }
}

Measured memory_bytes: 4324