akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back
typedef pair<LL, LL> P;
typedef pair<LL, P> PP;

char a[505][505], b[505][505], maze[505][505];
int h, w;

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> maze[i][j];
			a[i][j] = b[i][j] = '.';
		}
	}

	for (int i = 1; i < h-1; i++) {
		for (int j = 0; j < w; j++) {
			if (i % 2 == 0) {
				if(j!=w-1)a[i][j] = '#';
			}
			else {
				if(j!=0)b[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < h; i++) {
		a[i][0] = '#';
		b[i][w - 1] = '#';
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (maze[i][j] == '#') {
				if (i % 2 == 0)b[i][j] = '#';
				else a[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << a[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << b[i][j];
		}
		cout << endl;
	}
	//system("pause");
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 10, mod = 1e9 + 7;
const ll inf = 1e18;

void solve(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int j = 0;
    for(int i = k; i < n; i++){
        if(a[i] > a[j]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
        j++;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


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

int main(){
	int m,n;
	const double pi = 3.14159265358979;
	const double EPS = 1e-10;

	while( cin >> m , m ){
		int v, angleA=0, angleB=0;
		vector<int> a,b;

		for(int i=0 ; i < m-1 ; i++ ){
			cin >> v;
			a.push_back( v );
			angleA += v;
		}
		cin >> n;
		for(int i=0 ; i < n-1 ; i++ ){
			cin >> v;
			b.push_back( v );
			angleB += v;
		}

		a.push_back( 360 - angleA );
		b.push_back( 360 - angleB );
		double sa=0.0, sb=0.0;
		for(int i=0 ; i < a.size() ; i++ ){
			sa += sin( a[i]*pi/180.0 );
		}
		for(int i=0 ; i < b.size() ; i++ ){
			sb += sin( b[i]*pi/180.0 );
		}

		if( fabs(sa-sb) < EPS )
			cout << 0 << endl;
		else if( sa > sb )
			cout << 1 << endl;
		else 
			cout << 2 << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    int A , B;
    cin >> A >> B;
    string S;
    cin >> S;
    int N = S.size();
    for(int i = 0; i < A; i++){
        if(!(S.at(i) >= '0' && S.at(i) <= '9')){
            cout << "No" << endl;
            return 0;
        }
    }
    if(S.at(A) != '-'){
        cout << "No" << endl;
        return 0;
    }
    for(int i = A + 1; i < N; i++){
        if(!(S.at(i) >= '0' && S.at(i) <= '9')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        string S = Console.ReadLine();
        int K = cin.Int();

        var hash = new HashSet<string>();
        for (int i = 1; i <= 5; i++) {
            for (int j = 0; j <= S.Length - i; j++) {
                hash.Add(S.Substring(j, i));
            }
        }

        var hoge = hash.ToList().OrderBy(x=>x).ToList();
        Console.WriteLine(hoge[K - 1]);
        Console.ReadLine();
    }
}

Measured memory_bytes: 15328
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
string itos(int a){
	string s="";
	while(a){
		s=(char)(a%10+'0')+s;
		a/=10;
	}
	return s;
}
int main(){
	string s;
	int n;
	while(cin>>s>>n,n){
		map<string,int>out;
		int co=1;
		while(n!=s.size())s="0"+s;
		out[s]=co;
		while(1){
			co++;
			int tmp[10]={0};
			rep(i,s.size())tmp[s[i]-'0']++;
			int ma=0,mi=0;
			rep(i,10)rep(j,tmp[i])mi=mi*10+i;
			for(int i=9;i>=0;i--)rep(j,tmp[i])ma=ma*10+i;
			int after=ma-mi;
			s=itos(after);
			while(n!=s.size())s="0"+s;
			if(out[s]){
				cout<<out[s]-1<<" "<<atoi(&s[0])<<" "<<co-out[s]<<endl;
				break;
			}
			out[s]=co;
		}
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for(int i=0;i<(int)n;i++)
#define fore(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MAX_N=105;
const int MAX_K=2e5+10;
int n,k;
int arr[MAX_N];
int dp[MAX_K];
int main()
{

#ifdef LOCAL
    //freopen("output/input.txt", "r", stdin);
    //freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
#endif
    cin>>n>>k;
    forn(i,n)cin>>arr[i];
    for(int j=0;j<=k;j++){
        if(dp[j]==0){
            for(int i=0;i<n;i++){
                dp[j+arr[i]]=1;
            }
        }
    }
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())

    nextGame = [deque()] + [deque(map(int, input().split())) for _ in range(N)]

    canPlay = [[False] * (N + 1) for _ in range(N + 1)]
    days = [0] * (N + 1)

    que = deque([i for i in range(1, N + 1)])

    while que:
        now = que.pop()
        if not nextGame[now]:
            continue
        enemy = nextGame[now].popleft()
        canPlay[now][enemy] = True

        if canPlay[now][enemy] and canPlay[enemy][now]:
            days[now] = days[enemy] = max(days[now], days[enemy]) + 1
            que.append(now)
            que.append(enemy)

    for a in nextGame:
        if a:
            print('-1')
            return

    ans = max(days)
    print(ans)


sol()

Measured memory_bytes: 44008
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;
lli n;
vector<lli>a;
vector<lli>b;
lli ans = 0;
int main(){
    cin >> n;
    a=vector<lli>(n);b=vector<lli>(n);
    for(lli i = 0;i < n;i++) cin >> a[i] >> b[i];
    lli t = 0;
    for(lli i = n-1;i >= 0;i--){
        if((a[i]+t)%b[i]) t += b[i] - ((a[i]+t)%b[i]);
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,k;cin>>n>>k;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  sort(all(h));
  int ans=1e9;
  rep(i,n-k+1){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];

  scanf("%s",s);
  n = strlen(s);
  rep(i,n){
    if(s[i]=='0'){
      a[0]++;
    }else{
      a[1]++;
    }
  }
  printf("%d",min(a[0],a[1])*2);

  return 0;
}



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

int main(void)
{
    string S;
    cin >> S;
    for(int i{int(S.size()-1)}; i>0; --i){
        if(i%2!=0)
            continue;
        else{
            if(S.substr(0,i/2)==S.substr(i/2,i/2)){
                cout << i << endl;
                return(0);
            }
        }
    }
}


Measured memory_bytes: 256
N,K = map(int, input().split())
S = list(input())
a = S.pop(K-1)
if a =="A":
    a = 'a'
elif a =="B":
    a = 'b'
elif a =="C":
    a = 'c'
S.insert(K-1,a)
ans =''
for i in range(N):
    ans += S[i]

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int h, w;
  string a[100];
  int yy[100] = {0};
  int xx[100] = {0};
  cin >> h >> w;
  rep(0, h) { cin >> a[i]; }

  for (int y = 0; y < h; ++y) {
    string s = a[y];
    for (int x = 0; x < w; ++x) {
      if (s[x] == '#') {
        yy[y]++;
        xx[x]++;
      }
    }
  }

  for (int y = 0; y < h; ++y) {
    if (yy[y] == 0) {
      continue;
    }
    for (int x = 0; x < w; ++x) {
      if (xx[x] == 0) {
        continue;
      }
      cout << a[y][x];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

bool is_ok(ll n, vll &h, ll a, ll b, ll cnt) {
  ll x = 0;
  for (ll i = 0; i < n; i++) {
    if (h[i] > cnt * b) {
      x += ceil((double)(h[i] - cnt * b) / (a - b));
    }
  }
  return (x <= cnt);
}

//二分探索
ll binary_search(ll min, ll max, ll n, vll &h, ll a, ll b) {
  //cout << min << " " << max << endl;
  if (min == max) { //main関数から呼び出した時点でmin == maxである場合の処理
    if (is_ok(n, h, a, b, max)) return max;
    else {
      //適宜処理
    }
  }

  if (min + 1 == max) { //解近傍の処理
    if (is_ok(n, h, a, b, max)) return max;
    if (is_ok(n, h, a, b, min)) return min;
  }

  ll nn = (min + max) / 2;
  if (is_ok(n, h, a, b, nn)) return binary_search(min, nn, n, h, a, b);
  else return binary_search(nn, max, n, h, a, b);
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  vll h(n);
  for (ll i = 0; i < n; i++) cin >> h[i];
  sort(all(h));

  ll min = 1;
  if (h[n - 1] <= a) {
    if (n == 1) {
      cout << 1 << endl;
      return 0;
    }
    else if (h[n - 2] <= b) {
      cout << 1 << endl;
      return 0;
    }
  }
  ll max = ceil((double)h[n - 1] / b);

  cout << binary_search(min, max, n, h, a, b) << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
/*
int asc(int a, int b)
{
	if (a < b) {
		return -1;
	} else if (a > b) {
		return 1;
	} else {
		return 0;
	}
}
*/

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

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);

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

	qsort(x, m, sizeof(int), desc);	
/*	for (i = 0; i < m; i++) {
		for (j = i + 1; j < m; j++) {
			if (x[i] < x[j]) {
				int tmp = x[i];
				x[i] = x[j];
				x[j] = tmp;
			}
		}
	}//xを降順にソーティング
*/
	int y[m-1];
	for (i = 0; i < m - 1; i++) {
		y[i] = x[i] - x[i+1];
	}//要素間の差を求める

	qsort(y, m-1, sizeof(int), desc);
/*	for (i = 0; i < m - 1; i++) {
		for (j = i + 1; j < m - 1; j++) {
			if (y[i] < y[j]) {
				int tmp = y[i];
				y[i] = y[j];
				y[j] = tmp;
			}
		}
	}//差を降順にソーティング
*/
	int sum = 0;
	for (i = 0; i < m - 1; i++) {
		if (i <= n - 2) {
			;
		} else {
			sum += y[i];
		}
	}

	printf("%d\n", sum);

	return 0;
}



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

#define mod 1000000007
#define int long long

int power(int a,int b)
{
    int ans=1;

    while(b>0)
    {
        if(b&1)
        {
            ans*=a;
            ans%=mod;
            //cerr<<a<<endl;
        }
        a*=a;
        a%=mod;
        b/=2;
    }

    return ans;
}

int fact(int a)
{
    if(a==0)
        return 1;
    int tr =a*fact(a-1);
    tr%=mod;
    return tr;
}
 
int32_t main()
{
    int s;
    cin>>s;

    int tr=0;
    for(int len=1;len<=(s/3);len++)
    {
        int ans=1;
        int tot=s-len*3;

        int up=tot+len-1;
        int down=len-1;
        ans*=fact(up);
        int td=fact(down)*fact(up-down);
        td%=mod;

        ans*=power(td,mod-2);
        ans%=mod;
        tr+=ans;
        tr%=mod;
        //cerr<<ans<<" "<<td<<" "<<up<<" "<<down<<" "<<pow(td,mod-2)<<endl;
    }

    cout<<tr;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[1111111], c, g[20];
int main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	g[0] = 1; c = 0;
	while(true) {
		g[c + 1] = g[c] * 3 + 1;
		if(g[++c] >= n) break;
	}
	int ret = 0;
	for(int i = c - 1; i >= 0; i--) {
		for(int j = g[i]; j < n; j++) {
			int v = a[j], w = j - g[i];
			while(w >= 0 && a[w] > v) {
				a[w + g[i]] = a[w];
				w -= g[i];
				ret++;
			}
			a[w + g[i]] = v;
		}
	}
	cout << c << endl;
	for(int i = c - 1; i >= 0; i--) {
		if(i) cout << g[i] << ' ';
		else cout << g[i] << endl;
	}
	cout << ret << endl;
	for(int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

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

int main()
{
  long long x,y,ans;
  scanf("%lld%lld",&x,&y);
  if(y>0){
    if(y<x){
      ans=2+(x-y);
    }
    else if(0<=x){
      ans=y-x;
    }
    else if(-x<=y){
      ans=1+(y-(-x));
    }
    else{
      ans=((-x)-y)+1;
    }
  }
  else if(y<0){
    if(-x<=y){
      ans=1+(y-(-x));
    }
    else if(0<=x){
      ans=1+(-y-x);
    }
    else if(x<=y){
      ans=y-x;
    }
    else{
      ans=2+(x-y);
    }
  }
  else{
    if(x>0){
      ans=x+1;
    }
    else{
      ans=-x;
    }
  }
  printf("%lld\n",ans);
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        // String s = sc.next();
        long[] min = new long[n + 1];
        long[] max = new long[n + 1];

        for (int i = 1; i <= n; i++) {
            min[i] = min[i - 1] + i;
        }
        max[0] = n;
        for (int i = 1; i <= n; i++) {
            max[i] = max[i - 1] + (n - i);
        }

        long ans = 0;

        for (int i = k - 1; i <= n; i++) {
            ans += max[i] - min[i] + 1;
        }

        System.out.println(ans % 1000000007);
        sc.close();
    }

}

Measured memory_bytes: 38608
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;

typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int N;
int main(){
	cin>>N;
	vector<ll> A;
	A.pb(0);
	ll sum=0;
	
	for(int i=0;i<N;i++){
		ll hoge;
		cin>>hoge;
		sum+=hoge;
		A.pb(sum);
	}
	sort(A.begin(),A.end());
	//rep(i,N+1)cout<<A[i]<<endl;
	ll ans=0;
	ll cnt=1;
	for(int i=1;i<A.size();i++){
		if(A[i]==A[i-1])cnt++;
		else{
			ans=ans+(cnt*(cnt-1))/2;
			cnt=1;
		}
	}
	ans=ans+(cnt*(cnt-1))/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
#B
import collections

s = str(input())
t = str(input())
sd = list(s)
td = list(t)
sd.sort()
td.sort(reverse=True)
a = ''
b = ''
for c in sd:
    a += c
for c in td:
    b += c
if sd < td:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
c = list(c.items())
num = 0
nc2 = dict()
n_1c2 = dict()
for i in range(len(c)):
    nc2[c[i][0]] = c[i][1] * (c[i][1]-1) // 2
    num += c[i][1] * (c[i][1]-1) // 2
    n_1c2[c[i][0]] = (c[i][1]-1)*(c[i][1]-2) // 2
for i in range(n):
    tar = a[i]
    print(num-nc2[tar]+n_1c2[tar])



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

int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = k ; i < n; i++) {
    if(a[i - k] <a[i]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    }
return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

bool pal(string s, int a, int b) {
    a--;
    b--;
    int i = a;
    int j = b;
    while (i < j) {
        if (s[i] != s[j]) return false;
        i++;
        j--;
    }
    return true;
}

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

    string s;
    cin >> s;
    int n = s.size();
    if (pal(s, 1, n) && pal(s, 1, (n - 1) / 2) && pal(s, (n + 3) / 2, n)) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,a[110000],d[110000]={},c[110000]={};
  cin >> n >> m;
  rep(i,m)cin >> a[i];
  rep(i,m)c[a[i]-1]++;
  if(c[0]==0)d[0]=1;
  if(c[1]==0)d[1]=1+d[0];
  FOR(i,2,n)if(c[i]==0)d[i]=(d[i-1]+d[i-2])%MOD;
  printf("%lld",(d[n-1]+MOD)%MOD);
}

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

int main()
{
    // 入力の受け取り
    string s;
    getline(cin, s);

    // 各条件のチェック
    bool isEasy = true;
    int Limit = s.size();
    for(int i=0; i<Limit; i++){
        char check = s.at(i);

        if((i + 1) % 2 != 0){
            if((check != 'R') && (check != 'U') && (check != 'D')){
                isEasy = false;
                break;
            }
        }
        else{
            if((check != 'L') && (check != 'U') && (check != 'D')){
                isEasy = false;
                break;
            }
        }
    }

    // 結果
    string res;
    res = isEasy ? "Yes" : "No";
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
n, k, q = map(int,input().split())
a = [int(input()) for i in range(q)]

p = np.array([0]*n)
for i in range(q):
    p[a[i]-1] += 1

ans = (p-q+k > 0)
for i in ans:
    if i:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 18304
int main(void){
  int a,n;
  
  scanf("%d",&n); 
  for(int i=0; i<n; i++){
    scanf("%d",&a);
    if(a%2 == 0 && a%3 && a%5){
      puts("DENIED");
      return 0;
    }
  }
  
  puts("APPROVED");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
//
int main(){
  int C[3][3];
  FOR(i,0,3){
    FOR(j,0,3){
      cin>>C[i][j];
    }
  }
  if(C[0][0]-C[0][1]==C[1][0]-C[1][1]&&C[1][0]-C[1][1]==C[2][0]-C[2][1]&&C[0][1]-C[0][2]==C[1][1]-C[1][2]&&C[1][1]-C[1][2]==C[2][1]-C[2][2]){
    if(C[0][0]-C[1][0]==C[0][1]-C[1][1]&&C[0][1]-C[1][1]==C[0][2]-C[1][2]&&C[1][0]-C[2][0]==C[1][1]-C[2][1]&&C[1][1]-C[2][1]==C[1][2]-C[2][2]){
      Yes(1);
      return 0;
    }
  }
  Yes(0);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  // vector<ll> dp(N, 1LL << 60);
  // vector<ll> h(K);

  ll dp[100100];
  ll h[100100];

  for (int i = 0; i < N; ++i) cin >> h[i];
  for (int i = 0; i < 100100; ++i) dp[i] = 1LL<<60;

  dp[0] = 0;

  for (ll i = 0; i < N - 1; i++) {
    for (ll j = 1; j <= K; j++) {
      if (i + j >= N) continue;

      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }

  // for (ll i = 0; i < N; i++) {
  //   cout << dp[i] << endl;
  // }

  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int N,a[110] ;
  cin >> N;
  cinf(N,a) ;
  
  sort(a,a + N,greater<int>()) ;
  int Alice=0 ;
  int Bob=0 ;
  for(int i=0;i<N;i++){
    if(i %2 == 0)
      Alice +=a[i] ;
    else
      Bob += a[i] ;
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    cin >> n;
    LL a;
    LL b;
    LL keta_a;
    LL keta_b;
    LL ans=MAX;
    LL idx;
    for(LL i=1; i*i<=n; i++){
        a=i;
        if(n%i!=0){
            continue;
        }
        b=n/i;
        keta_a=0;
        keta_b=0;
        while(a>0){
            keta_a++;
            a/=10;
        }
         while(b>0){
            keta_b++;
            b/=10;
        }
        ans=min(ans, max(keta_a, keta_b));
    }

    cout << ans << endl;    


    return 0;
}

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


int main()
{
	int n,a,b,c;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b>>c;
		
		if(a*a == b * b + c * c){
      		cout << "YES" << endl;
    	} else if(b*b == a * a + c * c){
    	  		cout << "YES" << endl;
    	} else if(c*c == b * b + a * a){
     	 cout << "YES" << endl;
    	} else {cout <<"NO" << endl;} 
	}
	return 0;
}

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;
int p[N];
void solve(){
	int n;
	cin >> n;
	int ans = 0;
	fr(i, 1, n){
		cin >> p[i];
	}
	fr(i, 1, n - 1){
		if(p[i] == i && p[i + 1] == i + 1){
			ans++;
			swap(p[i], p[i + 1]);
		}
	}
	fr(i, 1, n){
		ans += (p[i] == i);
	}
	cout << ans;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length) sort(array, array + length, greater<>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    int N, K;
    cin >> N >> K;
    
    //入力数がN個の場合
    int array[N];
    for (int i = 0; i < N; i++)
    {
        cin >> array[i];
    }

    // 累積和を求める
    double cumulative_sum[N + 1];   // 1-origin
    double temp_sum = 0;
    for (int i = 0; i < N; i++)
    {
        // 1〜Pまでの連続数値の和
        int dice_val_sum = array[i] * (array[i] + 1) / 2;

        // 1つのサイコロの期待値
        double e_val = (double)dice_val_sum / array[i];

        // 累積和
        temp_sum += e_val;

        cumulative_sum[i + 1] = temp_sum;
        //printf("%f\n", temp_sum);
    }

    double e_max = -1;
    for (int i = 0; i < N - (K - 1); i++)
    {
        double temp_num = cumulative_sum[i + K] - cumulative_sum[i];    // i〜(i+K)の範囲の値の和
        //printf("%f - %f = %f\n", cumulative_sum[i + K], cumulative_sum[i], temp_num);
        e_max = max(e_max, temp_num);
    }

    // 結果出力
    printf("%f\n", e_max);
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] ts, vs;
    double[] elapsedTs;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        ts = new int[n];
        vs = new int[n];
        for (int i = 0; i < n; i++) {
            ts[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            vs[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        elapsedTs = new double[n + 1];
        for (int i = 1; i <= n; i++) {
            elapsedTs[i] = elapsedTs[i - 1] + ts[i - 1];
        }
        double prevMaximumVelocity = 0.0;
        double area = 0.0;
        for (int i = 1; i <= 2* elapsedTs[n]; i++) {
            double maximumVelocity = maximumVelocity((double)i / 2, elapsedTs[n]);
            area += (maximumVelocity + prevMaximumVelocity) / 4;
            prevMaximumVelocity = maximumVelocity;
        }
        System.out.printf("%4f\n", area);
    }

    double maximumVelocity(double elapsedTime, double totalTime) {
        double[] constraints = new double[n + 2];
        constraints[n] = elapsedTime;
        constraints[n + 1] = totalTime - elapsedTime;
        for (int i = 0; i < n; i++) {
            if (elapsedTime < elapsedTs[i]) {
                constraints[i] = vs[i] + elapsedTs[i] - elapsedTime;
            } else if (elapsedTime > elapsedTs[i + 1]) {
                constraints[i] = vs[i] + elapsedTime - elapsedTs[i + 1];
            } else {
                constraints[i] = vs[i];
            }
        }
        double ret = Double.MAX_VALUE;
        for (int i = 0; i < constraints.length; i++) {
            ret = Math.min(ret, constraints[i]);
        }
        return ret;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    ull n, m;
    cin >> n >> m;
    vector<int> L(m);
    vector<int> R(m);
    rep(i, 0, m-1) cin >> L[i] >> R[i];
    cout << endl;
    decltype(L)::iterator l = max_element(L.begin(), L.end());
    decltype(R)::iterator r = min_element(R.begin(), R.end());
  
    if (*r - *l < 0) {
        cout << 0 << endl;
    } else {
        cout << *r - *l + 1 << endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int P[10];

int main(){
  int N;
  cin >> N;
  int sum = 0;
  int max = 0;
  for(int i=0; i<N; i++) {
    cin >> P[i];
    sum += P[i];
    if(P[i] > max)
      max = P[i];
  }
  cout << sum - max / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { -1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9;

string c[71];
int w, h;

string d[71][71];

int str_compare(string s1, string s2){

	if (s1.size() > s2.size())return 1;
	if (s1.size() < s2.size())return 0;

	while (s1.size() != 1 && s1[0] == '0'){
		s1 = s1.substr(1, s1.size() - 1);
	}
	while (s2.size() != 1 && s2[0] == '0'){
		s2 = s2.substr(1, s2.size() - 1);
	}

	if (s1.size() > s2.size())return 1;
	if (s1.size() < s2.size())return 0;

	if (s1.size() == s2.size()){
		if (s1 > s2)return 1;
		if (s1 < s2)return 0;
		if (s1 == s2)return -1;
	}
}

void func(int y,int x){

	
	rep(i, 2){
		int ty = y + dy[i], tx = x + dx[i];
		if (cheak(tx, ty, w, h) && (c[ty][tx] >= '0' && c[ty][tx] <= '9')){

			string t = (c[ty][tx]) + d[y][x];
			if (str_compare(d[ty][tx],t ) == 0){
				d[ty][tx] = t;
				func(ty, tx);
			}

		}
	}
}

int main()
{
	while (cin >> w >> h && (w || h)){
		rep(y, h){
			cin >> c[y];
			rep(x,w)
			if (c[y][x] >= '0' && c[y][x] <= '9')d[y][x] = c[y][x];
		}
		for (int y = h - 1; y >= 0; y--)
		for (int x = w - 1; x >= 0; x--)if (c[y][x] >= '0' && c[y][x] <= '9'){
			func(y, x);
		}

		string ans = "0";

		rep(y, h)rep(x, w)if (c[y][x] >= '0' && c[y][x] <= '9') {

			while (d[y][x].size() != 1 && d[y][x][0] == '0'){
				d[y][x] = d[y][x].substr(1, d[y][x].size() - 1);
			}

			if (str_compare(ans, d[y][x]) == 0){
				ans = d[y][x];
			}
		}

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

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


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string weather[3] = {"Sunny", "Cloudy", "Rainy"};
    string input;
    
    cin >> input;
    
    for(int i = 0; i < sizeof(weather)/sizeof(weather[0]); i++){
        if(weather[i] == input){
            if(i + 1 > 2) i = 0;
            else i++;
            printf("%s", weather[i].c_str());
            break;
        }
    }
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
using namespace std;
int s[10] = {63,6,91,79,102,109,125,39,127,111};
int main() {
	int n, m;
	while (cin >> n, 0 <= n) {
		bitset<7> b(0);
        while (n--) {
			cin >> m;
			cout << (b^=s[m]) << endl;
			b = s[m];
		}
	}
}

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

int main() {
	int n;
	while(cin >> n, n != 0) {
		vector<int> v(n);
		for(int i = 0; i < n; ++i) {
			cin >> v[i];
		}
		
		sort(v.begin(), v.end());
		
		int ans = 0;
		
		for(int i = 1; i < n - 1; ++i) {
			ans += v[i];
		}
		
		cout << ans / (n - 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int data[100000];
	int n=0;
	cin>>n;
	int i=0;
	for(i=0;i<n;i++){
		cin>>data[i];
	}
	sort(data,data+n);
	int prev=data[0];
	int count=1;
	for(int i=1;i<n;i++){
		if(data[i]!=prev){
			count++;
			prev=data[i];
		}else{
			prev=-1;
			count--;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

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

    int N,X,x;
    vector<int> Xi,defX;
    bool flag  = true;
    cin >> N >> X;
    Xi.push_back(X);
    REP(i,N){
        cin >> x;
        Xi.push_back(x);
    }
    VSORT(Xi);
    REPP(i,1,N+1){
        defX.push_back(Xi[i]-Xi[i-1]);
    }
    int D = *min_element(ALL(defX));
    vector<int> D_list;
    D_list.push_back(D);
    REPP(i,1,D/2+1){
        if(D%i == 0) D_list.push_back(i);
    }
    VSORT(D_list);
    reverse(ALL(D_list));
    REP(i,D_list.size()){
        flag = true;
        REP(j,SZ(defX)){
            if(defX[j]%D_list[i] != 0){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << D_list[i] << endl;
            break;
        }
    }
    

    

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a % d != 0 && c % b != 0) {
        if(c/b <= a/d) cout << "Yes";
        else cout << "No";
    }
    else if(a % d == 0 && c % b != 0) {
        if(c/b < a/d) cout << "Yes";
        else cout << "No";
    }
    else if(a % d != 0 && c % b == 0) {
        if(c/b <= a/d + 1) cout << "Yes";
        else cout << "No";
    }
    else {
        if(c/b <= a/d) cout << "Yes";
        else cout << "No";
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll a;

    cin >> a;

    cout << a+a*a+a*a*a << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    int n,ans;
    scanf("%d",&n);
    ans=(360*n)/gcd(360,n);
    printf("%d",ans/n);
    return 0;
}

Measured memory_bytes: 1724
def p(S):
    D={}
    for i in range(len(S)):
        a=S[i]
        if a in D:
            D[a].add(i)
        else:
            D[a]={i}
    return D
S=input()
T=input()

A=sorted(p(S).values())
B=sorted(p(T).values())

if A==B:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 64604
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll locate(ll a,vector<ll> b){
    for(ll i=0;i<b.size();i++){
        if(a<b[i])return b[i];
    }
    return 0;
}

int main() {
    
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vector<vector<ll>> A(10,vector<ll>(0));
    for(ll i=0;i<N;i++){
        A[S[i]-'0'].push_back(i);
    }
    
    ll count=0;
    for(int i=0;i<=9;i++){
        if(!A[i].size())continue;
        for(int j=0;j<=9;j++){
            ll con = locate(A[i][0], A[j]);
            if(!con)continue;
            for(int k=0;k<=9;k++){
                if(locate(con, A[k]))count++;
            }
        }
        
    }
    cout << count << endl;
    
}

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

int n;
int a[200001];
int b[200001];

int main()
{
	scanf("%d", &n);
	ll ans = 0;
	bool as = 1;
	bool le = 0; ll lev = 0;
	for(int i=1; i<=n; ++i){
		scanf("%d%d",a+i,b+i);
		if(a[i] != b[i]) as = 0;
		if(a[i] <= b[i]){
			ans += a[i];
		} else {
			ans += a[i];
			if(le) lev = min(lev, ll(b[i]));
			else le=1, lev=b[i];
		}
	}
	if(as){
		puts("0");
		return 0;
	}
	if(le) ans -= lev;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
int ans[maxn],d[maxn],a,n;
main(){
    scanf("%d",&n);
    d[0]=d[n+1]=0;
    for(int i=1;i<=n;i++) 
    {
    	scanf("%d",&d[i]);
		a+=abs(d[i-1]-d[i]);
	}
	ans[1]=a=a+abs(d[n])-abs(d[1])+abs(d[2])-abs(d[1]-d[2]);
    //int cache=0;
    for(int i=2;i<=n;i++)
		ans[i] = a = a + abs(d[i-2]-d[i-1]) + abs(d[i+1]-d[i-1]) - abs(d[i-2]-d[i]) - abs(d[i+1]-d[i]);
    for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}

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

long long runrun(long long a,long long b){
  if(a==0){return 1;}
  if(b<=1){return 0;}
  long long mon=1,mmon;
  for(int i=0;i<a;++i){
    mon*=2,mon+=3;
  }
  mmon=(mon-3)/2;
  if(mmon+1>=b){return runrun(a-1,b-1);}
  return ((long long)1<<a)+(b==2+mmon ? 0 : runrun(a-1,b-2-mmon));
}

int main(){
  long long a,b;
  cin>>a>>b;
  cout<<runrun(a,b)<<endl;
}


Measured memory_bytes: 256