akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define WHITE 0
#define GRAY 1
#define BLACK 2

static const int N=100;

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
   color[u] = GRAY;
   d[u] = ++tt;
   rep(v, n) {
      if (M[u][v] == 0) continue;

      if(color[v] == WHITE) {
         dfs_visit(v);
      }
   }
   color[u] = BLACK;
   f[u] = ++tt;
}

void dfs() {
   int u;
   for(u = 0; u < n; u ++) {
      color[u] = WHITE;
   }

   for(u = 0; u < n; u ++) {
      if(color[u] == WHITE) dfs_visit(u);
   }

   for(u =0; u<n;u++) {
      printf("%d %d %d\n", u+1, d[u], f[u]);
   }
}

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

   // graphを0で初期化
   for(int i = 0; i < n; i ++) {
      for(int j = 0; j < n; j ++) {
         M[i][j] = 0;
      }
   }

   // 隣接リストを隣接行列に変換
   for(int i = 0; i < n; i ++) {
      scanf("%d %d", &u, &k);
      u--;
      for(int j = 0; j < k; j++) {
         scanf("%d", &v);
         v--;
         M[u][v] = 1;
      }
   }

   dfs();
   return 0;
}



Measured memory_bytes: 3224
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

void solve(){
   cin>>n;

   for (int i = 0; i <= 55000; ++i)
   {
      if ((int)(i * 1.08) == n){
         cout<<i;
         return ;
      }
   }

   cout<<":(";
}

int32_t main(){_
   
   int t = 1;
//   cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	int n = s.l_ength();
	vector<int> ans(n);
	fill_n( ans.begin(), n, 0 );
	int lcnt = 0, rcnt = 0;
	for( int i = 0; i < n; ++i ){
		char c = s[i];
		if( c == 'R' ){
			++rcnt;
		}
		if( c == 'L' ){
			ans[i] += (rcnt/2);
			ans[i-1] += (rcnt - rcnt/2);
			rcnt = 0;
		}
	}
	for( int i = n-1; i >= 0; --i ){
		char c = s[i];
		if( c == 'L' ){
			++lcnt;
		}
		if( c == 'R' ){
			ans[i] += (lcnt/2);
			ans[i+1] += (lcnt - lcnt/2);
			lcnt = 0;
		}
	}
	for( int i = 0; i < n; ++i ){
		cout << ans[i];
		if( i != n-1 ) cout << ' ';
	}
	cout << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

ll dp[3007][3007];
ll a[3007];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	for (ll i = 0; i < 3007; i++) {
		for (ll j = 0; j < 3007; j++) {
			dp[i][j] = LLONG_MIN;
		}
	}

	for (int i = 0; i < n; i++) {
		dp[i][i] = a[i];
	}

	for (int len = 2; len <= n; len++) {
		for (int i = 0; i + len - 1 < n; i++) {
			int j = i + len - 1;
			dp[i][j] = max({ dp[i][j], a[i] - dp[i + 1][j], a[j] - dp[i][j - 1] });
		}
	}

	cout << dp[0][n - 1] << endl;

	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];
    
    DESC(A);
    ll m = A[0]/2;
    REP(i,1,N) m = MIN(m,abs(A[i]-A[0]/2));
    ll p = 0;
    REP(i,1,N) {
        if(abs(A[i] - A[0] / 2) == m) {
            p = i;
            break;
        }
    }
    PS(A[0]); PR(A[p]);

    return 0;
}

/*



*/

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int head[maxn],lazy[maxn],v[maxn];
int size=0;
int n,q;
struct edge{
	int to,next;
}e[maxn<<1];
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
inline void addedge(int u,int v){
	e[++size].to=v;e[size].next=head[u];head[u]=size;
}
void dfs(int u,int fa){
	v[u]+=lazy[u];
	for(int i=head[u];i;i=e[i].next){
		int to=e[i].to;
		if(to==fa)continue;
		v[to]+=v[u];
		dfs(to,u);
	}
}
int main(){
	n=read(),q=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		addedge(u,v);
		addedge(v,u);
	}
	for(int i=1;i<=q;i++){
		int u=read(),x=read();
		lazy[u]+=x;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	printf("%d ",v[i]);
	return 0;
} 

Measured memory_bytes: 17024
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()
 
n=ii()
a=lmi()
suma=sum(a)
counter=[0]*(10**5+5)
for i in a:
  counter[i]+=1
#print(counter)
q=ii()
 
for i in range(q):
  b,c=mi()
  suma+=(c-b)*counter[b]
  
  counter[c]+=counter[b]
  counter[b]=0
  #print(counter)
  print(suma)

Measured memory_bytes: 84572
#include<cstdio>
#include<cstring>
using namespace std;
#define N 45
long long dp[N][N][N],f[N][N][N][N],n;
char s[N][N];
long long calc(int a,int b,int c,int d)
{
	if(f[a][b][c][d]!=-1)return f[a][b][c][d];
	long long as=0;
	for(int i=a;i!=(b==n*2?1:b+1);i=i==n*2?1:i+1)
	for(int j=c;j!=(d==n*2?1:d+1);j=j==n*2?1:j+1)
	as+=dp[a][b][i]*dp[c][d][j]*(s[i][j]=='1');
	return f[a][b][c][d]=as;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n*2;i++)scanf("%s",s[i]+1);
	memset(f,-1,sizeof(f));
	for(int i=1;i<=n*2;i++)dp[i][i][i]=1;
	for(int l=2;l<n*2;l++)
	for(int i=1;i<=n*2;i++)
	{
		int j=(i+l-1)%(2*n)+1;
		for(int k=i;k!=(j==n*2?1:j+1);k=k==n*2?1:k+1)
		for(int s=i==n*2?1:i+1;s!=(k==n*2?1:k+1);s=s==n*2?1:s+1)
		for(int t=j==1?n*2:j-1;t!=(k==1?n*2:k-1);t=t==1?n*2:t-1)
		dp[i][j][k]=(dp[i][j][k]+dp[s][t][k]*calc(i,s==1?n*2:s-1,t==n*2?1:t+1,j));
	}
	long long as=0;
	for(int i=2;i<=n*2;i++)as+=dp[i==n*2?1:i+1][i-1][1]*(s[1][i]=='1');
	printf("%lld\n",as);
}//

Measured memory_bytes: 32896
unittest
{
	assert( [ "5 3", "1 2 2 4 5" ].parse.expand.solve == "7.000000" );
	assert( [ "4 1", "6 6 6 6" ].parse.expand.solve == "3.500000" );
	assert( [ "10 4", "17 13 13 12 15 20 10 13 17 11" ].parse.expand.solve == "32.000000" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], ps );
}

auto solve( long k, long[] ps )
{
	// 最初のk個の期待値を計算
	auto e = 0.0L;
	foreach( p; ps[ 0 .. k ] )
	{
		e += ( 1 + p ) / 2.0L;
	}
	
	// 一つずつずらしながら期待値の最大を検索
	auto ans = e;
	foreach( i; k .. ps.length.signed )
	{
		auto ep = ( 1 + ps[ i ] ) / 2.0L;
		auto em = ( 1 + ps[ i - k ] ) / 2.0L;
		e += ep - em;
		ans = max( ans, e );
	}
	return format( "%0.6f", ans );
}


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

int N,X[1<<18],Y[1<<18];
char D[1<<18];

void Rotate(){
  for (int i=1;i<=N;i++){
    int cx=Y[i],cy=200000-X[i],cz;
    if(D[i]=='U') cz='R';
    if(D[i]=='R') cz='D';
    if(D[i]=='D') cz='L';
    if(D[i]=='L') cz='U';
    X[i]=cx; Y[i]=cy; D[i]=cz;
  }
}

vector<pair<int, char>> V1[1<<19];
vector<pair<int, char>> V2[1<<19];

//'U'と'R'の飛行機について
int solve_01(){
  int Answer = (1<<24);
  for(int i=0;i<=500000;i++) V1[i].clear();
  for(int i=1;i<=N;i++){
    if(!(D[i]=='R'||D[i]=='U'))continue;
    V1[X[i]+Y[i]].push_back(make_pair(X[i],D[i]));
  }
  for(int i=0;i<=500000;i++){
    sort(V1[i].begin(),V1[i].end());
    for(int j=0;j<(int)V1[i].size()-1;j++){
      if(!(V1[i][j].second=='R' && V1[i][j+1].second=='U'))continue;
      Answer=min(Answer,V1[i][j+1].first-V1[i][j].first);
    }
  }
  return Answer*10;
}

//'L'と'R'の飛行機について
int solve_02(){
  int Answer = (1<<24);
  for (int i=0;i<500000;i++) V2[i].clear();
  for (int i=1;i<=N;i++){
    if(!(D[i]=='L'||D[i]=='R')) continue;
    V2[Y[i]].push_back(make_pair(X[i],D[i]));
  }
  for (int i=0;i<=500000;i++){
    sort(V2[i].begin(),V2[i].end());
    for(int j=0;j<(int)V2[i].size()-1;j++){
      if(!(V2[i][j].second=='R' && V2[i][j+1].second=='L')) continue;
      Answer = min(Answer,V2[i][j+1].first-V2[i][j].first);
    }
  }
  return Answer*5;
}

int main(){
  cin >> N;
  for(int i=1;i<=N;i++) cin >> X[i] >> Y[i] >> D[i];
  
  int FinalAns = (1<<24);
  for (int t=0;t<4;t++){
    int val1=solve_01(); FinalAns=min(FinalAns,val1);
    int val2=solve_02(); FinalAns=min(FinalAns,val2);
    Rotate();
  }
  if (FinalAns==(1<<24)) cout << "SAFE" << endl;
  else  cout << FinalAns << endl;
  return 0;
}

Measured memory_bytes: 42668
import java.util.*;
import java.util.Map.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}


	public void run() {
		Scanner sc = new Scanner(System.in);
		char c[] = sc.next().toCharArray();
		int n = c.length;

		int l;
		int r;
		if(n%2==0) {
			l=n/2-1;
			r=n/2;
		}else {
			l=n/2;
			r=n/2;
		}
		char base = c[l];
		while(r<n) {
			if(c[l] != c[r] || c[l] != base) {
				break;
			}
			base = c[l];
			l--;
			r++;
		}
		System.out.println(r);
		sc.close();
	}
}


Measured memory_bytes: 39788
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
int main()
{
	int n;
	cin>>n;
	rep3(i,1,n+1)
	{
		int ans=0;
		for(int j=1;j*j<=i;j++)
		{
			rep3(k,1,j+1)
			{
				rep3(l,1,k+1)
				{
					if((j+k)*(j+k)+(k+l)*(k+l)+(j+l)*(j+l)==2*i)
					{
						if(j==k&&k==l) ans++;
						if(j==k&&k!=l||k==l&&j!=k||j==l&&j!=k) ans+=3;
						if(j!=k&&j!=l&&k!=l) ans+=6;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin >> s;

  ll n = s.size();
  char p = s[0];
  char pp = s[0];
  ll b = -1;
  ll e = -1;
  REP1(i, n){
    if(p == s[i]){
      b = i;
      e = i+1;
      break;
    }
    p = s[i];

    if(i == 1)
      continue;


    if(pp == s[i]){
      b = i-1;
      e = i+1;
      break;
    }
    pp = s[i-1];
  }

  cout << b << ' ' << e << endl;
}


Measured memory_bytes: 512
#include <iostream>

using ll = long long;
int main(int argc, char ** argv)
{
  //
  std::string s;
  std::cin >> s;
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (*(s.c_str() + i) == 'A') {
      ans++;
    }
  }
  if ((ans == 0) || (ans == 3)) {
    std::puts("No");
  } else {
    std::puts("Yes");
  }
  return 0;
}


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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

#define uniq(v) (v).erase(unique(ALL((v))), (v).end());

// area of (0, 0)(a, b)(c, d)
double area(double a, double b, double c, double d){
    return abs(a * d - b * c) / 2.0;
}

const int PREC = 10;
#define coutf(val) cout << fixed << setprecision(PREC) << (val) << endl;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    make2(int, N, K);

    vector<int> Ps(N);
    REP(i, N) {
        make(int, P);

        Ps.at(i) = P;
    }

    sort(ALL(Ps));

    int ans  =0;

    REP(i, K) {
        ans += Ps.at(i);
    }

    cout << ans << endl;
}


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

int main(){
  int n, r, t;
  cin >> n >> r >> t;
  int p[110];
  int now[110] = {};
  int old[110] = {};
  int drink[1010] = {};
  int ans = 0;
  for(int i = 0;i < n;i++) cin >> p[i];

  for(int i = 0;i < t;i++){
    for(int j = 0;j < n;j++){
      old[j] = now[j];
      now[j] = (now[j] + p[j]) % r;
      if(drink[now[j]] == 0){
        ans++;
      }else{
        drink[now[j]]--;
      }
    }
    if(i > 0){
      for(int j = 0;j < n;j++) drink[now[j]]++;
    }
  }

  cout << ans << endl;
  return 0;
}






Measured memory_bytes: 3112
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
l.sort()
ll=[i for i in range(1,n+1)]
x=[]
for i in range(1,n+1):
    z=list(itertools.combinations(l,i))
    zz=list(itertools.combinations(ll,i))
    for j in range(len(z)):
        x.append([sum(z[j]),(i-1)*10,list(zz[j])])
x.sort()
#print(x)
A=[];B=[];C=[]
for i in range(len(x)):
    A.append([x[i][1]+abs(a-x[i][0]),x[i][2]])
    B.append([x[i][1]+abs(b-x[i][0]),x[i][2]])
    C.append([x[i][1]+abs(c-x[i][0]),x[i][2]])
A.sort();B.sort();C.sort()
#print(A)
#print(B)
#print(C)
m=len(A)
ans=float('inf')
for i in range(m):
    for j in range(m):
        for k in range(m):
            if len(A[i][1]+B[j][1]+C[k][1])>=9:
                break
            elif len(A[i][1]+B[j][1]+C[k][1])==len((set(A[i][1]+B[j][1]+C[k][1]))):
                ans=min(ans,A[i][0]+B[j][0]+C[k][0])
print(ans)
                
    

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) cin >> d[i];
  
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ans += d[i] * d[j];
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

s = input()
if s[1] == 'B':
    print("ARC")
else:
    print("ABC")

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
int main(){
   double  a,b,x;
  cin>>a>>b>>x;
  cout << fixed << setprecision(10);
  if(x>a*a*b/2){
    float t=a*a;
     float  l=2*b-2*x/t;
     float  x=atan(l/a)*180/3.141592654;
    cout<<x<<endl;
  }else{
     float  t=a*b;
     float  l=2*x/t;
     float  x=atan(l/b)*180/3.141592654;
    cout<<90-x<<endl;
  }
}

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


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

int main(void){
    // Your code here!
    int N, W, H; cin >> N >> W >> H;
    vector<int> Wimos(100005);
    vector<int> Himos(100005);
    
    for (int i = 0; i < N; i++) {
        int w, h, d; cin >> w >> h >> d;
        Wimos[max(0, w-d)]++;
        Wimos[min(W+1, w+d)]--;
        Himos[max(0, h-d)]++;
        Himos[min(H+1, h+d)]--;
    }
    for (int w = 1; w <= W; w++) {
        Wimos[w] += Wimos[w-1];
    }
    for (int h = 1; h <= H; h++) {
        Himos[h] += Himos[h-1];
    }
    
    int flagW = 1;
    for (int w = 0; w < W; w++) {
        if (!Wimos[w]) flagW = 0;
    }
    int flagH = 1;
    for (int h = 0; h < H; h++) {
        if (!Himos[h]) flagH = 0;
    }
    
    if (flagW || flagH) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
pii works[125252];

int main(){
    scanf("%d%d",&n,&m);
    REP(i,n){
        int a,b;
        scanf("%d%d",&a,&b);
        works[i] = pii(a,b);
    }
    sort(works, works+n);
    multiset<int> M;
    ll ans = 0;
    int it = 0;
    FOR(day,1,m+1){
        while(it<n && works[it].first <= day){
            M.insert(works[it].second);
            it++;
        }
        if(M.size()>0){
            int add = *M.rbegin();
            M.erase(M.find(add));
            ans += add;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> vec(n,0);

  for (int i = 0; i < m; i++) {
    int a,b;
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 3596
n,m = map(int,input().split())
*hl, = map(int,input().split())
ansl = [1]*n
for _ in [0]*m:
  a,b = map(int,input().split())
  if hl[a-1] > hl[b-1]:
    ansl[b-1] = 0
  elif hl[a-1] < hl[b-1]:
    ansl[a-1] = 0
  else:
    ansl[a-1] = 0
    ansl[b-1] = 0
print(sum(ansl))

Measured memory_bytes: 19996
n,m = map(int,input().split())
broke = [ 0 for i in range(n+1) ]
for i in range(m):
  s = int(input())
  broke[s] = 1
dp = [ 0 for i in range(n+1) ]
dp[0] = 1
for i in range(n+1):
    if broke[i] == 1:
        continue
    else:
        if i-1 >= 0:
            dp[i] += dp[i-1]
        if i-2 >= 0:
            dp[i] += dp[i-2]

print(dp[n] % (10**9+7))


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

void solve(std::istream& ist, std::ostream& ost)
{
    /* ------- 宣言と入力 ------- */

    string S;

    ist >> S;

    /* ------- 計算 ------- */

    if (S == "AAA" || S == "BBB")
    {
        ost << "No" << endl;
    }
    else
    {
        ost << "Yes" << endl;
    }
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 256
#if 0
2019.07.24

假设最终答案为 x ，那么其他的数其实可以分为三种：x ，小于 x 和大于 x 。
只需要关注与 x 的大小，把小于 x 的全设为 -INF ，大于 x 的全设为 INF ，得出的结果一定仍是 x 。

但这仍然难以处理，考虑枚举一个值 x ，把所有数分为两种：小于等于 x (0) 和大于 x (1) 。
如此将原数列转换为 01 串，若最后剩下的是 0 ，那么答案一定小于 x ，否则答案一定大于 x 。
那么 x 的值可以二分，接下来问题转换为 01 串上求最后剩下的数。

首先，如果两个相等的值相邻，那么在之后的操作中这两个位置的值始终不变。
那么如果中间的值 a[mid] 与 a[mid - 1] 或 a[mid + 1] 相等，即中间的值是 xx?  或 ?xx 形式，最后的结果一定是 a[mid] ，即 x。
否则 a[mid - 1] 到 a[mid + 1] 一定是 xyx 形式。
那么考虑 a[mid - 2] 到 a[mid + 2] ，若为 xxyx? 形式，一次操作后转换为 xx? 形式，最后结果一定是 x 。
?xyxx 形式同理，否则一定是 xyxyx 形式。

以此类推，从中间向两边找到第一个相邻且相等的 a[i] = a[i + 1] ，那么 a[i] 即最后的结果。
如果不存在此 a[i] ，那么就是 0101...01010 的形式，最终结果是 a[n] 。
#endif
#include <cstdio>
#include <algorithm>
#include <climits>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() {
	int c = getchar(), x = 0;
	while(c < '0' or c > '9') c = getchar();
	while(c >= '0' and c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

const int maxn = 200005;
int a[maxn];
bool b[maxn];

bool check(int x, int n) {
	// debug("check %d\n", x);
	for(int i = 1; i <= n; i++)
		b[i] = a[i] > x;
	int mid = (1 + n) >> 1;
	for(int i = 0; i < mid; i ++) {
		if(b[mid + i] == b[mid + i + 1])
			return b[mid + i];
		if(b[mid - i] == b[mid - i - 1])
			return b[mid - i];
	}
	return b[n];
}

int main() {
	int n = input() * 2 - 1, min = INT_MAX, max = 0;
	for(int i = 1;  i <= n; i ++) {
		a[i] = input();
		min = std::min(a[i], min);
		max = std::max(a[i], max);
	}
	int l = min, r = max;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid, n))
			l = mid + 1;
		else
			r = mid;
	}
	printf("%d\n", l);
}



Measured memory_bytes: 1152
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
    double x, y;

    Point(double x = 0.0, double y = 0.0): x(x), y(y) {};

    Point operator + (Point &p) {return Point(x + p.x, y + p.y);}
    Point operator - (Point &p) {return Point(x - p.x, y - p.y);}
    Point operator * (double k) {return Point(x * k, y * k);}
    Point operator / (double k) {return Point(x / k, y / k);}

    double norm(void) {return x * x + y * y;}
    double abs(void) {return sqrt(norm());}

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    double dot(Point a) {
        return x * a.x + y * a.y;
    }

    double cross(Point a) {
        return x * a.y - y * a.x;
    }
};

struct Segment {
    Point p1, p2;
};


Point project(Segment s, Point p) {
    Point base = s.p2 - s.p1;
    double r = base.dot(p - s.p1) / base.norm();
    return base * r + s.p1;
}

Point reflect(Segment s, Point p) {
    return (project(s, p) - p) * 2.0 + p;
}

int main(void) {
    int x1, x2, y1, y2, q, px, py;
    Segment s;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    s.p1 = Point(x1, y1); s.p2 = Point(x2, y2);

    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d", &px, &py);
        Point ans = Point(reflect(s, Point(px, py)));
        printf("%.10f %.10f\n", ans.x, ans.y);
    }

    return 0;
}

Measured memory_bytes: 1072
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct BIT{
    vector<ll> bt;
    size_t n,m;
    explicit BIT(size_t n):n(n),m(1){
        while(m<=n) m<<=1u;
        m>>=1u;
        bt.resize(n+1);
    }
    ll sum(ll i){//sum of [1,i](1-index)
        if(!i) return 0;
        ll tmp{};
        for(size_t k=i;k;k-=k&-k) tmp+=bt[k];
        return tmp;
    }
    void ad(ll i,ll x){//add to i(1-index)
        for(size_t k=i;k<=n;k+=k&-k) bt[k]+=x;
    }
    ll lb(ll k){//if sum(i)<k and sum(i) >= k, return i
        ll x=0;
        for(size_t i=m;i>0;i>>=1u){
            if(x+i<=n&&bt[x+i]<k) {
                k-=bt[x+i];
                x+=i;
            }
        }
        return x+1;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> p(n);
    for(auto&lr:p) cin>>lr.first>>lr.second;
    sort(p.begin(),p.end(),[](auto x,auto y){
        return x.second-x.first<y.second-y.first;
    });
    BIT bt(m+1);
    int s{},t{n},tmp;
    Fr(d,m){
        while(s<n&&p[s].second-p[s].first+1<d){
            --t;
            bt.ad(p[s].first,1);
            bt.ad(p[s].second+1,-1);
            ++s;
        }
        tmp=0;
        for(int i=d;i<=m;i+=d) tmp+=bt.sum(i);
        cout<<t+tmp<<endl;
    }
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[100100];
vector<int> p, m;

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
        if (A[i] >= 0)p.push_back(A[i]);
        else m.push_back(A[i]);
    }
    if (p.size() == 0) {
        sort(m.begin(), m.end());
        p.push_back(m[m.size() - 1]);
        m.pop_back();
    } else if (m.size() == 0) {
        sort(p.begin(), p.end(), greater<int>());
        m.push_back(p[p.size() - 1]);
        p.pop_back();
    }
    int ans = 0;
    rep(i, p.size()) {
        ans += p[i];
    }
    rep(i, m.size()) {
        ans -= m[i];
    }
    cout << ans << endl;
    if (p.size() == 1) {
        cout << p[0] << " " << m[0] << endl;
        int pre = p[0] - m[0];
        for (int i = 1; i < m.size(); ++i) {
            cout << pre << " " << m[i] << endl;
            pre -= m[i];
        }
    } else {
        cout << m[0] << " " << p[0] << endl;
        int pre = m[0] - p[0];
        for (int i = 1; i < p.size() - 1; ++i) {
            cout << pre << " " << p[i] << endl;
            pre -= p[i];
        }
        cout << p[p.size() - 1] << " " << pre << endl;
        pre = p[p.size() - 1] - pre;
        for (int i = 1; i < m.size(); ++i) {
            cout << pre << " " << m[i] << endl;
            pre -= m[i];
        }
    }

    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main(void){
    int N, X;
    cin >> N >> X;
    int array[N];
    for(int i = 0; i < N; i++){
        cin >> array[i];
    }
    int nowPlace = 0;
    int counter = 1;
    for(int i = 0; i < N; i++){
        nowPlace += array[i];
        if(nowPlace > X){
            break;
        } else {
            counter++;
        }
    }
    
    cout << counter << endl;
    
}


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

A,B = [],[]
for i in range(N): A.append(input())
for j in range(M): B.append(input())
    
isok = False
for h in range(0,N-M+1):
    for w in range(0,N-M+1):
        #始点を合わせたら照合開始
        search = True #照合を仮定(ダメなら-1に変更)
        for j in range(M):
            if A[h+j][w:w+M] != B[j]:
                search = False
                break
        if search:
            isok = True
            break
        #照合ここまで
    if search:break
        
if isok:
    print("Yes")
else:
    print("No")

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

int main() {
  int N;
  cin >> N;
  vector <int> vec (N) ;
  
  for (int i = 0;i<N; i++) cin >> vec.at(i);
  sort (vec.begin(),vec.end());
  
  bool match = false;
  
  for (int i = 0; i < N-1; i ++){
    if (vec.at(i) == vec.at(i+1)) {
      match = true;
      break;
    }
  }
  if (match) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        while (true) {
            int N, X; cin >> N >> X;
            if (N == 0 && X == 0) return;
            int ans = 0;
            for (int a = 1; a <= N; a++) {
                for (int b = a + 1; b <= N; b++) {
                    int c = X - a - b;
                    if (c <= b || N < c) continue;
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

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

int cnt(ll a){
    int res = 0;
    while(a % 2 == 0){
        a /= 2;
        res++;
    }
    return res;
}

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt2(n);
    rep(i,n) cnt2[i] = cnt(a[i]);
    rep(i,n) {
        if(cnt2[i] != cnt2[0]){
            cout << 0 << endl;
            return 0;
        }
    }
    ll mini = a[0]/2;
    FOR(i,1,n){
        mini = lcm(mini, a[i]/2);
        if(mini > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll d = mini*2;
    cout << (m-mini)/d + 1 << endl;
}


Measured memory_bytes: 1408
import sys
import math
from functools import reduce
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())

x = list(map(int, input().split()))

x.append(X)
x.sort()

diff = []

for i in range(1, len(x)):
    diff.append(x[i]-x[0])

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(diff))

Measured memory_bytes: 92488
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    vector<ll> x(n), y(n), h(n);

    int ok;

    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] > 0)
        {
            ok = i;
        }
    }

    ll cx, cy;

    for (cx = 0; cx <= 100; cx++)
    {
        for (cy = 0; cy <= 100; cy++)
        {
            ll H = h[ok] + abs(x[ok] - cx) + abs(y[ok] - cy);
            bool flag = true;

            for (int i = 0; i < n; i++)
            {
                if (H - abs(x[i] - cx) - abs(y[i] - cy) != h[i] && h[i] > 0)
                {
                    flag = false;
                }

                if (h[i] == 0 && H - abs(x[i] - cx) - abs(y[i] - cy) > 0)
                {
                    flag = false;
                }
            }

            if (flag)
            {
                printf("%lld %lld %lld\n", cx, cy, H);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
main :: IO ()
main = do
    [a,b,x] <- map read . words <$> getLine :: IO [Double]
    print $
        if a * a * b / 2 <= x
            then let y = b - (x * 2 / (a * a) - b)
                  in (atan (y / a) * 180 / pi)
            else let y = 2 * x / b / a
                  in 90 - (atan (y / b) * 180 / pi)


Measured memory_bytes: 508
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World";
    } else{
        int a, b;
        cin >> a >> b;
        cout << a + b;
    }
}

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

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



signed main(){

	int N, M;
	vector<int> x[3], t;

	cin >> N >> M;
	for(int i=0;i<N;i++){
		int a,b,c;
		cin>>a>>b>>c;
		x[0].push_back(a);
		x[1].push_back(b);
		x[2].push_back(c);
	}
	int ans=-INF;
	for(int n=0;n<8;n++){
		t.clear();
		for(int i=0;i<N;i++){
			int tmp=0;
			for(int bit=0;bit<3;bit++){
				if((n&(1<<bit))==0)
					tmp+=x[bit][i];
				else
					tmp-=x[bit][i];				
			}
			t.push_back(tmp);
		}
		sort(t.begin(),t.end(),greater<int>());
		int sum=0;
		for(int i=0; i<M; i++)
			sum+=t[i];
		ans = max(ans, sum);
	}
	cout << ans << endl;

	return 0;
}


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

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

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

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

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

int n;
int g[105][105];
ll ans;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n)rep(j, n) cin >> g[i][j];
    rep(i, n)rep2(j, i + 1, n) {
        ans += min(g[i][j], g[j][i]);
    }
    cout << ans << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> a(n), b(m);
  rep(i,n) {
    int x, y;
    cin >> x >> y;
    a[i]=make_pair(x,y);
  }
  rep(i,m) {
    int x, y;
    cin >> x >> y;
    b[i]=make_pair(x,y);
  }
  vector<int> DIS(n,1000000000), ans(n);
  rep(i,n) {
    rep(j,m) {
      int dis = abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second);
      if(dis<DIS[i]) {
        DIS[i]=dis;
        ans[i]=j+1;
      }
    }
  }

  rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, c, k = map(int, input().split())
    T = sorted(list(int(input()) for _ in range(n)))
    res = 0
    cnt = 0
    dep = T[0] + k
    for i in range(n):
        if cnt == c or T[i] > dep:
            res += 1
            cnt = 1
            dep = T[i] + k
        else:
            cnt += 1

    print(res + 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 51160
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

const int N=2e5+5;
int n,l[N],r[N],a[N],id[N]; ll ans=0;

ll count(int l,int m,int r) {
	return (ll)(r-m)*(m-l);
}

int main() {
//	file_put();
	
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",&a[i]),id[a[i]]=i,l[i]=i-1,r[i]=i+1;
	per(i,1,n+1) ans+=(ll)i*count(l[id[i]],id[i],r[id[i]]),r[l[id[i]]]=r[id[i]],l[r[id[i]]]=l[id[i]];
	printf("%lld\n",ans);
	
	return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int par[100000]; //parent
int rnk[100000]; //depth

				 //init with n elements
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rnk[i] = 0;
	}
}
//find a root of the tree
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//merge the sets contains x,y
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}

//the set contains x and y or not
bool same(int x, int y) {
	return find(x) == find(y);
}

int main() {
	cin.sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int,int>>e(M);
	rep(i, M) {
		cin >> e[i].first >> e[i].second;
		e[i].first--; e[i].second--;
	}
	int ans = 0;
	rep(i, M) {
		init(N);
		rep(j, M) {
			if (i != j)unite(e[j].first, e[j].second);
		}
		rep(j, N) {
			if (!same(0, j)) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m = 0; cin >> n;
    long long s = 0;
    while (n--) {
        int a; cin >> a;
        s += max(0, m - a);
        m = max(m, a);
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3612
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,i;
	i=0;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	g=a*1+b*5+c*10+d*50+e*100+f*500;
	if(g>=1000) i=1;
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long N,M,L;
char S[100005],T[100005];
long long getmin(long long a,long long b){
	long long m=a,n=b,r;
	if(m<n){
		long long temp=m;
		m=n;
		n=temp;
	}
	r=m%n;
	while(r){
		m=n;
		n=r;
		r=m%n; 
	}
	return a*b/n;
}
int main()
{
	cin>>N>>M;
	scanf("%s%s",S,T);
	long long num=N*M;
	long long x1=num/N;
	long long x2=num/M;
	long long i1=strlen(S);
	long long j1=strlen(T);
	long long j=0,i=0;
	for(j=0;j<j1;j++){
		while(j*x2>=i*x1&&i<i1){
			if(i*x1==j*x2){
				if(S[i]==T[j]){
					break;
				}
				else{
					printf("-1\n");
					return 0;
				}
			}
			i++;
		}
	}
	num=getmin(N,M);
	printf("%lld\n",num);
	return 0;
}

Measured memory_bytes: 384
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main {
  def isHamming(num:Int):Boolean = {
    var n = num
    while(n%2==0) n = n/2
    while(n%3==0) n = n/3
    while(n%5==0) n = n/5

    if(n==1) true
    else false
  }

  def main(args:Array[String]) = {
    var s = "0"
    val b = new ArrayBuffer[String]
    while({s=readLine.trim;s}!="0") {
      val n = s.split(" ").map(_.toInt)
      b+=(n(0) to n(1)).count(i=>isHamming(i)).toString
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 91032
#include <stdio.h>

int	main()
{
	long long X, sum;

	scanf("%lld\n", &X);
			// printf("%lld\n", X);
	sum = 0;
	for (long long i = 100; i < X; i *= 1.01)
	{
		// printf("%d\n", i);
		sum++;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
int main(void){
    int n,y,i;
    scanf("%d\n",&n);
    int cards[4][14] = {{}};
    char x;
    
    for(i=0; i<n; i++){
        scanf("%c %d\n",&x,&y);
        if(x=='S')
        cards[0][y] = 1;
        else if(x=='H')
        cards[1][y] = 1;
        else if(x=='C')
        cards[2][y] = 1;
        else if(x=='D')
        cards[3][y] = 1;
    }
    for(i=0; i<4; i++){
        for(y=1; y<14; y++){
            if(cards[i][y]==0){
                if(i==0) printf("S ");
                else if(i==1) printf("H ");
                else if(i==2) printf("C ");
                else if(i==3) printf("D ");
                printf("%d\n",y);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}
struct Data{
    ll l,r,pm;
    bool operator<(const Data& a) const {
        if(pm == a.pm){
            if(pm == 1)return r < a.r;
            else return l>a.l;
        }
        else{
            return pm > a.pm;
        }
    }
};

int main(){
    ll N;
    cin>>N;
    vector<Data> data;
    vector<string> S(N);
    rep(i,0,N){
        cin>>S[i];
    }
    rep(i,0,N){
        ll l=0,r=0;
        rep(j,0,S[i].size()){
            if(S[i][j] == '('){
                l++;
            }
            else{
                if(l == 0){
                    r++;
                }
                else l--;
            }
        }
        //cout<<l<<" "<<r;
        ll s;
        if(r<l)s = 1;
        else if(r == l)s = 0;
        else s = -1;
        Data tmp;
        tmp.l = l;
        tmp.r = r;
        tmp.pm = s;
        data.PB(tmp);
    }
    sort(all(data));
    ll sum_l = 0;
    bool ans = true;
    rep(i,0,N){
        //cout<<data[i].l<<" "<<data[i].r<<" "<<data[i].pm<<endl;
        if(data[i].r <= sum_l){
            sum_l += (data[i].l - data[i].r);
            //cout<<data[i].r<<endl;
        }
        else ans = false;
    }
    rep(i,0,N){
        //cout<<data[i].l<<" "<<data[i].r<<" "<<data[i].pm<<endl;
    }
    if(sum_l != 0)ans = false;
    YN(ans);
    return 0;
}

Measured memory_bytes: 58956
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	a := make([]string, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Strings(a)
	for _, s := range a {
		fmt.Print(s)
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll A[14][14],C[14];
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n,m,x;
    string s,s1;
    cin>>s>>s1;
    s1.erase(s1.end()-1);
    if(s==s1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>

int main(void){
    while(1){
      int h,w;
      scanf("%d%d",&h,&w);
      if(h==0&&w==0)break;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("#");
        }printf("\n");
      }printf("\n");
    }return 0;
}




Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N + 1), b(N + 1), c(N + 1);
	for (int i = 1; i <= N; ++i) { cin >> a[i]; }
	for (int i = 1; i <= N; ++i) { cin >> b[i]; }
	for (int i = 1; i <= N - 1; ++i) { cin >> c[i]; }

	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		ans += b[a[i]];
		if (i == N) { continue; }
		if (a[i] + 1 == a[i + 1]) {
			ans += c[a[i]];
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256