akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<int>edge[2005];
int n,k;
int dp[2005][2005],sub[2005];
int t[2][2];
void rec(int v,int u){
	sub[v] = 1;
	for(int i=0;i<edge[v].size();i++){
		if(edge[v][i] != u){
			rec(edge[v][i],v);
			sub[v] += sub[edge[v][i]];
		}
	}
	dp[v][0] = sub[v]-1;
	for(int maxx=1;maxx<=k;maxx++){
		int cur = 0,nxt= 1;
		t[cur][0] = 0; t[cur][1] = 1000000;
		t[nxt][0] = 1000000; t[nxt][1] = 1000000;
		for(int i=0;i<edge[v].size();i++){
			if(edge[v][i] == u) continue;
			t[nxt][0] = t[nxt][1] = 1000000;
			t[nxt][1] = min(t[nxt][1],min(t[cur][0],t[cur][1])+(k-maxx-1>=0?dp[edge[v][i]][min(maxx-1,k-maxx-1)]:sub[edge[v][i]]));
			t[nxt][1] = min(t[nxt][1],t[cur][0]+dp[edge[v][i]][maxx-1]);
			t[nxt][0] = min(t[nxt][0],t[cur][0]+(k-maxx-1>=0?dp[edge[v][i]][min(maxx-1,k-maxx-1)]:sub[edge[v][i]]));
			swap(cur,nxt);
		}
		dp[v][maxx] = min(t[cur][0],t[cur][1]);
		dp[v][maxx] = min(dp[v][maxx],dp[v][maxx-1]);
	}
}
int main()
{
	cin >> n >> k;
	for(int i=1;i<n;i++){
		int a,b; cin >> a >> b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	rec(1,-1);
	int ret = 100000000;
	for(int i=1;i<=n;i++){
		ret = min(ret,dp[i][k]+n-sub[i]);
	}
	cout << ret << endl;
}

Measured memory_bytes: 16256
void main()
{
    long n = rdElem;

    long[][] list = new long[][](10, 10);
    foreach (i; 1 .. n+1)
    {
        long f = i.to!string[0] - '0';
        long b = i % 10;
        ++list[f][b];
    }

    long result;
    foreach (i; 0 .. 10)
    {
        foreach (j; 0 .. 10)
        {
            result += list[i][j] * list[j][i];
        }
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9+7;
ll fact[210200];
ll invfact[210200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll powMod(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return powMod(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

double dp[3010][3010];
int main(){
    int N;
    cin >> N;
    double p[3101];
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }

    for(int i = 0; i < 3010; i++){
        fill(dp[i], dp[i]+3010, 0.0);
    }
    dp[0][0] = 1.0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= i; j++){
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
            dp[i+1][j+1] += dp[i][j] * p[i];
        }
    }

    double res = 0;
    for(int i = N; i >= N / 2 + 1; i--){
        res += dp[N][i];
    }
    printf("%.11f\n", res);


    return 0;
}


Measured memory_bytes: 72064
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);

		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int A = Integer.parseInt(tokens[1]);
		int B = Integer.parseInt(tokens[2]);
		int result = 0;
		for (int i = 1; i <= N; ++i) {
			int conv = conv(i);
			if (conv >= A && conv <= B) {
				result += i;
			}
		}
		System.out.println(result);
	}

	static int conv(int val) {
		String s = Integer.toString(val);
		int result = 0;
		for (int i = 0; i < s.length(); ++i) {
			result += Integer.parseInt(s.substring(i, i + 1));
		}
		return result;
	}
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
//少数点表示
//cout <<std::fixed << std::setprecision(14)

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

    int a,b,t;
    cin >> a>> b >> t;
    int ans=0;
    ans=t/a*b;
    cout << ans;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = a + b;

        if(ans >= 24){
            System.out.println(ans - 24);
        } else {
            System.out.println(ans);
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


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

char nyuryoku[12][12];

void fun(int y,int x,char masume){
	if((x<0)||(12<=x)||(y<0)||(12<=y)){
		return;
	}
	if(masume!=nyuryoku[y][x])
		return;
	else
		nyuryoku[y][x]='+';
	fun(y+1,x,masume);
	fun(y-1,x,masume);
	fun(y,x+1,masume);
	fun(y,x-1,masume);
}

int main(){
	while(cin >> nyuryoku[0][0]){
		for(int j=1;j<12;j++)
			cin >> nyuryoku[0][j];
		for(int i=1;i<12;i++){
			for(int j=0;j<12;j++){
				cin >> nyuryoku[i][j];
			}
		}
		int count=0;
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(nyuryoku[i][j]!='+'){
					if(nyuryoku[i][j]=='1')
						count++;
					fun(i,j,nyuryoku[i][j]);
				}
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 3020
#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 a,b;cin>>a>>b;
  string s;cin>>s;
  bool ans=true;
  rep(i,a+b+1){
    if(i==a){
      if(s[i]!='-')ans=false;
    }
    else {
      if(s[i]=='-')ans=false;
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3612
// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x,a,b) for(int x=a;x<=b;x++)
#define FORD(x,a,b) for(int x=a;x>=b;x--)
#define maxn 100005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x,y) memset(x,y,sizeof(x))
#define task "Knapsack"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)

using namespace std;
int n,lim,w[maxn],v[maxn];
ll ans;
ll dp[maxn];
int main()
{
//    #ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
//    freopen(task".inp","r",stdin);
//    freopen(task".out","w",stdout);
//    #endif
    cin >> n >> lim;
    for(int i=1; i<=n; ++i) cin >> w[i] >> v[i];
    fill(dp+1,dp+lim+1,0);
    for(int j=1; j<=n; ++j)
    {
        for(int i=lim; i>=1; --i)
        {
            if(i - w[j] < 0) continue;
            dp[i] = max(dp[i], dp[i-w[j]] + v[j]);
            ans = max(ans, dp[i]);
        }
    }
    cout << ans;

}


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

typedef long long ll;

ll f(int n)
{
	if (n <= 5)
		return (ll)0;

	ll ans = 0;

	int x = 1, y = 1, z = 1;
	// int MAX = sqrt(n - 2);

	for (x; x * x < n; x++)
	{
		y = 1;
		z = 1;
		if (x *x + y * y + z * z + x * y + y * z + z * x  > n)
			break;
		for (y = 1; y * y < n; y++)
		{
			z = 1;
			if (x *x + y * y + z * z + x * y + y * z + z * x  > n)
				break;
			for (z = 1; z * z < n; z++)
			{
				if (x *x + y * y + z * z + x * y + y * z + z * x  > n)
					break;

				if (x *x + y * y + z * z + x * y + y * z + z * x == n)
				{
					// cout << x << ", " << y << ", " << z << "\n";
					ans++;
				}
			}
		}
	}
	return ans;
}

void solve()
{
	int n;
	cin >> n;
	
	// cout << f(11);

	for (int i = 1; i <= n; i++)
		cout << f(i) << "\n";

}

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

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

	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}	
	return 0;
}




Measured memory_bytes: 3564
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
a_sort = sorted(AB,key=lambda x: x[0],reverse=True)
a_max = a_sort[0][0]

tmp = []
for a,b in AB:
    if b > a_max:
        tmp.append(b)

tmp.sort(reverse=True)

cnt = 0
for i in tmp:
    H -= i
    cnt += 1
    if H <= 0:
        print(cnt)
        exit()

print(H // a_max + cnt if H % a_max == 0 else H // a_max + 1 + cnt)

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

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

  int tmp = 0, ans = 0;
  for (int i = 0; i < s.size(); i ++) {
    if (s.at(i) == 'I') {
      tmp ++;
    } else {
      tmp --;
    }
    if (tmp >= ans) {
      ans = tmp;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

th = inputs[0][1]
lst = inputs[1]

# body
if $debugFlag
end

ans = 0
lst.each do |a_i|
  ans += 1 if a_i >= th
end

puts ans


Measured memory_bytes: 8204
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Long> list = new ArrayList<Long>();
		list.add((long)2);
		list.add((long)1);
		
		for(int i = 2; i <= N; i++) {
			list.add(list.get(i - 2) + list.get(i - 1));
		}
		
		System.out.println(list.get(list.size() - 1));
		
		scan.close();
	}

}


Measured memory_bytes: 23764
N=int(input())
X=input()

D={}
for i in range(1,N+1):
    Nun=i+0
    cnt=0
    while Nun!=0:
        if Nun in D:
            cnt+=D[Nun]
            Nun=0
        S=str(bin(Nun))
        One=S.count("1")
        if One==0:
            break
        else:
            Nun=Nun%One
            cnt+=1
    D[i]=cnt
D[0]=0
#print(D)

One=X.count("1")
#print(One)

if One==0:
    for i in range(N):
        print(1)
elif One==1:
    for i in range(N-1):
        if X[i]=="1":
            print(0)
        else:
            print(1)
    if X[-1]=="0":
        print(2)
    else:
        print(0)
else:
    Num10=0
    for i in range(N):
        if X[i]=="1":
            Num10+=pow(2,N-1-i,One-1)
    Num10%=(One-1)
    #print(Num10,Num10)
    Num01=0
    for i in range(N):
        if X[i]=="1":
            Num01+=pow(2,N-1-i,One+1)
    Num01%=(One+1)
    #print(Num01)
    for i in range(N):
        if X[i]=="1":
            A=Num10-pow(2,N-1-i,One-1)
            #print(A)
            if A==0:
                print(1)
            elif A%(One-1)==0:
                print(1)
            else:
                A%=(One-1)
                print(1+D[A])
            #print(A)
        else:
            A=Num01+pow(2,N-1-i,One+1)
            if A%(One+1)==0:
                print(1)
            else:
                A%=(One+1)
                print(D[A]+1)

Measured memory_bytes: 103460
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(){
    int N;
    scanf("%d", &N);
    char s[N];
    scanf("%s", &s);
    int i, num = 0;

    for(i=0; i<N-1; i++ ){
        if (s[i] != s[i+1]){
            num++;
        }
    }

    num++;

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


    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

string s1[3]={".aa","b..","b.."};
string s2[4]={"aacd","bbcd","cdaa","cdbb"};
string s3[5]={".bcdd","fbc..","f.mnn","ppm.t","uuwwt"};
string s4[6]={"bbddff","hhjjl.","...qls","...qxs","z...xc","zdd..c"};
string s7[7]={".xxyyzz","xbbdd..","xh....m","yh....m","y....xy","z....xy","z.aabb."};

signed main(){

	int n;
	cin>>n;
	if(n==2 || n==7){
		if(n==7){
			r(i,n)cout<<s7[i]<<endl;
		}
		else cout<<-1<<endl;
		return 0;
	}
	string s[n];
	string t="";
	r(i,n)t+=".";
	r(i,n)s[i]=t;
	r(i,335){
		if(i*3==n){
			int cnt=0;
			r(c,i){
				r(a,3){
					r(b,3){
						s[cnt+a][cnt+b] = s1[a][b];
					}
				}
				cnt+=3;
			}
			r(a,n)cout<<s[a]<<endl;
			return 0;
		}
	}
	r(i,3)
	r(j,255){
		r(k,255){
			if(i*6+j*4+k*5==n){
				int cnt=0;
				r(c,j){
					r(a,4){
						r(b,4){
							s[cnt+a][cnt+b] = s2[a][b];
						}
					}
					cnt+=4;
				}
				r(c,k){
					r(a,5){
						r(b,5){
							s[cnt+a][cnt+b] = s3[a][b];
						}
					}
					cnt+=5;
				}
				r(c,i){
					r(a,6){
						r(b,6){
							s[cnt+a][cnt+b] = s4[a][b];
						}
					}
					cnt+=6;
				}
				r(a,n)cout<<s[a]<<endl;
				return 0;
			}
		}
	}
	
}


Measured memory_bytes: 2304
x,k,d=map(int,input().split())
x=abs(x)
sa=x//d
ans=x
pbk,mbk=0,0
bk1,bk2,bk3=1,1,1
mansbk,pansbk=0,0
if sa>=k:
  ans=x-d*k
else:
  ans=x-d*sa
  k=k-sa
  for i in range(k):
    mansbk=abs(ans-d)
    pansbk=abs(ans+d)
    if mansbk!=pansbk:
      ans=min(mansbk,pansbk)
      if bk3!=1:
        bk1=min(mansbk,pansbk)
        bk2=max(mansbk,pansbk)
        ans=mbk if (k-i)%2==0 else bk1
        break
      else:
        bk3=max(mansbk,pansbk) 
    else:
      ans=0 if (k-i)%2==0 else d
      break
    pbk=max(mansbk,pansbk)
    mbk=min(mansbk,pansbk)
print(ans)

Measured memory_bytes: 9152
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*5+(j))

int64 calc(const int *a,int n){
  int64 *dp=(int64 *)calloc(5*2,sizeof(int64));
  int now=0;
  for(int i=0;i<n;i++){
    int next=now^1;
    int v=a[i];
    if(v>0){
      dp[POS(next,0)]=dp[POS(now,0)]+v;
      dp[POS(next,1)]=MIN(dp[POS(now,0)],dp[POS(now,1)])+(v&1);
      dp[POS(next,2)]=MIN(dp[POS(now,0)],MIN(dp[POS(now,1)],dp[POS(now,2)]))+((v+1)&1);
      dp[POS(next,3)]=MIN(dp[POS(now,0)],MIN(dp[POS(now,1)],MIN(dp[POS(now,2)],dp[POS(now,3)])))+(v&1);
      dp[POS(next,4)]=MIN(dp[POS(now,0)],MIN(dp[POS(now,1)],MIN(dp[POS(now,2)],MIN(dp[POS(now,3)],dp[POS(now,4)]))))+v;
    } else {
      dp[POS(next,0)]=dp[POS(now,0)]+v;
      dp[POS(next,1)]=MIN(dp[POS(now,0)],dp[POS(now,1)])+2;
      dp[POS(next,2)]=MIN(dp[POS(now,0)],MIN(dp[POS(now,1)],dp[POS(now,2)]))+1;
      dp[POS(next,3)]=MIN(dp[POS(now,0)],MIN(dp[POS(now,1)],MIN(dp[POS(now,2)],dp[POS(now,3)])))+2;
      dp[POS(next,4)]=MIN(dp[POS(now,0)],MIN(dp[POS(now,1)],MIN(dp[POS(now,2)],MIN(dp[POS(now,3)],dp[POS(now,4)]))))+v;
    }
    now=next;
  }
  int64 res=dp[POS(now,0)];
  for(int i=1;i<5;i++) res=MIN(res,dp[POS(now,i)]);
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  printf("%lld\n",calc(a,n));
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  cin >> N;
  vi A(N);
  vi clr(8,0);
  rep(i,N){
    cin >> A[i];
    int a = A[i]/400;
    if(a>=8) clr[8]++;
    else clr[a]++;
  }
  int mn = 0;
  rep(i,8){if(clr[i]>0) mn++;}
  int mx = mn + clr[8];
  if(mn == 0) mn++;
  cout << mn << " "<< mx << endl;
  return 0;
}


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

using namespace std;

int gcd(int a, int b){
  int tmp=max(a, b);
  for(int i=tmp;i!=1;i--){
    if(a%i==0 && b%i==0){
      return i;
    }
  }
  return 1;
}

int main(){
  int n;
  cin >> n;
  long long ans=0;
  vector<int> v;
  for(int a=1;a<=n;a++){
    for(int b=1;b<=n;b++){
      //cout << gcd(a,b) << endl;
      int tmp=gcd(a,b);
      if( tmp == 1 ){
        ans+=n;
      }
      else{
        v.push_back( tmp );
      }
      // for(int c=1;c<=n;c++){
      //   //cout << a << " " << b << " " << c << " " << gcd(a, b, c) << endl;
      //   cout << gcd(a, b, c) << endl;
      //   ans += gcd(a, b, c);
      // }
    }
  }
  for(int c=1;c<=n;c++){
    for(int i=0;i<v.size();i++){
      ans+= gcd(c,v.at(i));
    }
  }
  // cout << v.size() << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int i, j, n, s1=0,s2=0, ans=0, tmp;
  cin >> n;
  int w[n];
  for(i=0; i<n; i++){
    cin >> w[i];
    s2+=w[i];
  }
  ans=s2;
  for(i=0; i<n-1; i++){
    s1+=w[i];
    s2-=w[i];
    tmp=abs(s1-s2);
    if(tmp<ans) ans=tmp;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        MyReader reader = new MyReader();
        int[] ab = reader.readInts(" ");
        int a = ab[0];
        int b = ab[1];
        System.out.println(problem169a(a, b));
    }

    private static int problem169a(int a, int b) {
        return a * b;
    }

    private static class MyReader {
        private final BufferedReader br;
        private MyReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        private String readString() throws IOException {
            return br.readLine();
        }

        private int readInt() throws IOException {
            return Integer.parseInt(readString());
        }

        private String[] readStrings(String regex) throws IOException {
            return readString().split(regex);
        }

        private int[] readInts(String regex) throws IOException {
            String[] strings = readStrings(regex);
            int[] ints = new int[strings.length];
            for (int i = 0; i < ints.length; i++) {
                ints[i] = Integer.parseInt(strings[i]);
            }
            return ints;
        }
    }
}

Measured memory_bytes: 25260
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

const int INF = 100100100;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 892
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	a := make([]int, N)
	b := make([]int, N)
	c := make([]int, M)
	d := make([]int, M)
	for i := 0; i < N; i++ {
		a[i], b[i] = getInt(), getInt()
	}
	for i := 0; i < M; i++ {
		c[i], d[i] = getInt(), getInt()
	}
	for i := 0; i < N; i++ {
		min := math.MaxInt64
		pos := 0
		for j := 0; j < M; j++ {
			diff := asub(a[i], c[j]) + asub(b[i], d[j])
			//out(a[i], b[i], c[i], d[i], "diff", diff, min, pos)
			if diff < min {
				min = diff
				pos = j
				//out("min", min, j)
			}
		}
		out(pos + 1)
	}
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        int k,p;
        cin>>k>>p;
        int ans=k%p;
        if(ans==0)ans=p;
        cout<<ans<<endl;
    }
    return 0;
}


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

// 1-indexed, 200000頂点以下で統一
#define MAX_SIZE 200000
vector<int> v[MAX_SIZE+1];


// 木vで点startから最も遠い頂点の(距離, 座標)を返す関数
pair<int, int> dfs(int start){
    pair<int, int> ans(0, start);
    vector<int> dist(MAX_SIZE+1,-1); // -1は未探訪
    stack<int> s;

    dist[start] = 0;
    s.push(start);

    // 木なのでsが空になるまで回せば全ての辺と頂点を巡る
    while(! s.empty()){
        int t = s.top();
        s.pop();
        for(auto x: v[t]){
            if(dist[x] == -1){
                dist[x] = dist[t] + 1;
                s.push(x);
                pair<int, int> xPair(dist[x], x);
                if(ans < xPair) ans = xPair;
            }
        }
    }
    return ans;
}


int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N - 1; ++i) {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int diameter = dfs(dfs(1).second).first; // 任意の頂点から2回dfsをすれば直径が求められる

    if(diameter % 3 == 1){
        cout << "Second";
    }else{
        cout << "First";
    }
    return 0;
}

Measured memory_bytes: 13556
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef tuple<int,int,string> T;
//少数点表示
//cout <<std::fixed << std::setprecision(14)

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

    string s;
    int q;
    cin >> s;
    cin >> q;
    string ketu="";
    string kasira="";
    bool hanten=false;   
    rep(i,q){
        int a,b;
        string t;
        cin >> a;
        if(a==1){
            hanten=!hanten;
        }
        if(a==2){
            cin >> b >> t;
            if(b==1){
                if(!hanten){
                    kasira=t+kasira;
                }else{
                    ketu=ketu+t;
                }
            }
            if(b==2){
                if(!hanten){
                    ketu=ketu+t;
                }else{
                    kasira=t+kasira;
                }
            }
            
        }
    }
    if(!hanten){
        cout <<kasira+s+ketu;
    }else{
        s=kasira+s+ketu;
        reverse(s.begin(),s.end());
        cout << s;
    }
}

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

int main() {
    string s;
    cin >> s;

    int n = s.size();

    int p = s[0] == 'g' ? 0 : -1;
    for (int i = 2; i < n; i += 2) {
        if (s[i - 1] == 'g' && s[i] == 'g') {
            p++;
        } else if (s[i - 1] == 'p' && s[i] == 'p') {
            p--;
        }
    }
    if (n % 2 == 0) {
        p += s[n - 1] == 'g' ? 1 : 0;
    }

    cout << p << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main()
{
	int n;
	int a = -1;
	int b = -1;
	int count = 0;
	
	std::cin >> n;
	std::vector<int> P;
	std::vector<int> Q;
	std::vector<int> V;

	for (int i = 0; i < n; i++)
	{
		int p;
		std::cin >> p;
		P.push_back(p);
		V.push_back(i + 1);
	}
	for (int i = 0; i < n; i++)
	{
		int p, q;
		std::cin >> q;
		Q.push_back(q);
	
	}

	do
	{
		if (V == P)
			a = count;
		if (V == Q)
			b = count;
		if (a != -1 && b != -1)
			break;
		count++;
	}while (std::next_permutation(V.begin(), V.end()));
	std::cout << abs(a - b) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    ll k;cin>>k;
    vector<ll>a(n),b(m);
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];a[i]+=a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>b[i];b[i]+=b[i-1];
    }
    int mx=0;
    for(int i=0;i<n;i++){
        ll x=k-a[i];
        if(x<0)break;
        auto u=upper_bound(b.begin(),b.end(),x);
        if(mx<i+1+(u-b.begin()))mx=i+1+(u-b.begin());
    }
    for(int i=0;i<m;i++){
        ll x=k-b[i];
        if(x<0)break;
        auto u=upper_bound(a.begin(),a.end(),x);
        if(mx<i+1+(u-a.begin()))mx=i+1+(u-a.begin());
    }
       
    cout<<mx;
 
    return 0;
}

Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+18;

ll a;
ll b;
ll c;
ll d;
ll n;
map<ll, ll> mp;

ll f (ll x) {
    if (x==0) return 0;
    if (x==1) return d;
    if (mp.count(x)) return mp[x];
    ll l2 = x - x%2;
    ll r2 = ((x-1)/2 + 1)*2;
    ll l3 = x - x%3;
    ll r3 = ((x-1)/3+1)*3;
    ll l5 = x - x%5;
    ll r5 = ((x-1)/5+1)*5;
    ll res = INF;
    if (d<=INF/x) res = d*x;
    res = min(res, abs(l2-x)*d+a+f(l2/2));
    res = min(res, abs(r2-x)*d+a+f(r2/2));
    res = min(res, abs(l3-x)*d+b+f(l3/3));
    res = min(res, abs(r3-x)*d+b+f(r3/3));
    res = min(res, abs(l5-x)*d+c+f(l5/5));
    res = min(res, abs(r5-x)*d+c+f(r5/5));
    mp[x] = res;
    return res;
}

int main(){
    int t;
    cin >> t;
    rep(i, t) {
        cin >> n >> a >> b >> c >> d;
        mp.clear();
        ll ans = f(n);
        cout << ans << endl;
        
    }
    
    
    return 0;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
  {
  ios_base::sync_with_stdio(0); 
  
  LL a, b, c, k;
  cin >> a >> b >> c >> k;

  LL res = 0;
  if(k < a)
    {
    res += k;
    }
  else
    {
    res += a;
    k -= a;

    debug(res, a, b, k);
    if(k >= b)
      {
      k -= b;

      res -= k;
      }
    }
  cout << res << endl;
  }


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

signed main(void)
{
	double a, b, ans;
	cin >> a >> b;
	ans = (a * b) / (a + b);
	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}


Measured memory_bytes: 384
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    A,B,C = input().split()

    print('YES') if A[-1] == B[0] and B[-1] == C[0] else print('NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 10340
#include<iostream>
#include<math.h>
using namespace std;

int main(){
 int a, b, c;
 cin>>a>>b>>c;
 int sum=a+b+c, m=max(max(a,b),c);
 while(1){
  if((m*3-sum)%2==0)break;
  m++;
 }cout<<(m*3-sum)/2<<"\n";
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (n); i++)
#define ALL(c) (c).begin(),(c).end()

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

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

const ll MOD = 998244353;
const int MN = 200010;

template<class T>
class BIT{
    T bit[MN];
    int n;
public:
    BIT(){
        n = MN;
        memset(bit, 0, sizeof(bit));
    }
    T sum(int i){
        ++i;
        T s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, T x){
        ++i;
        while(i < n){
            bit[i] += x;
            i += i & -i;
        }
    }
};

int num[MN][4];
ll p2[MN];

void init(){
    p2[0] = 1;
    for(int i = 1; i < MN; ++i) p2[i] = p2[i - 1] * 2 % MOD;
}

int main() {
    init();
    int N;
    cin >> N;
    vector<pii> vec(N);
    vi xs, ys;
    
    rep(i, N) {
        int x, y;
        scanf("%d %d", &x, &y);
        vec[i] = mp(x, y);
        xs.pb(x); ys.pb(y);
    }
    
    sort(ALL(xs)); sort(ALL(ys));
    rep(i, N) {
        int x = vec[i].fi, y = vec[i].se;
        x = lower_bound(ALL(xs), x) - xs.begin();
        y = lower_bound(ALL(ys), y) - ys.begin();
        vec[i] = mp(x, y);
    }
    
    sort(ALL(vec));
    rep(t, 2){
        BIT<int> T;
        rep(i, N) {
            int a = T.sum(vec[i].se - 1), b = i - T.sum(vec[i].se);
            if(t == 0){
                num[i][0] = a;
                num[i][1] = b;
            }else{
                num[N - 1 - i][2] = a;
                num[N - 1 - i][3] = b;
            }
            T.add(vec[i].se, 1);
        }
        reverse(ALL(vec));
    }
    
    ll ans = 0;
    rep(i, N) {
        ll a = (p2[num[i][0]] + p2[num[i][3]] - 1) % MOD;
        ll b = (p2[num[i][1]] + p2[num[i][2]] - 1) % MOD;
        ll v = (p2[N] - a * b) % MOD;
        if (v < 0) v += MOD;
        ans = (ans + v) % MOD;
    }
    
    printf("%llu", ans);
    return 0;
}

Measured memory_bytes: 9068
#include<cstdio>

int main(int argc, char const *argv[])
{
    double a, b, c, d, e, f;
    while(scanf("%lf %lf %lf %lf %lf %lf", &a,&b,&c,&d,&e,&f) != EOF){
        double x = (e*c-b*f)/(a*e-b*d);
        double y = (-d*c+a*f)/(a*e-b*d);
        if(x==0) x=0;
        if(y==0) y=0;
        printf("%.3lf %.3lf\n", x, y);
    }
    return 0;
}



Measured memory_bytes: 2608
using System;
using System.Linq;
using System.Collections.Generic;
 
class P
{
    static void Main()
    {
        int[] NT = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long sec = 0;
        int[] T = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int lastsec = T[0];
        for (int i = 1; i < NT[0]; i++)
        {
            int a = T[i];
            sec += Math.Min(NT[1], a - lastsec);
            lastsec = a;
        }
        sec += NT[1];
        Console.WriteLine(sec);
    }
}

Measured memory_bytes: 28768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
   int N;
   cin >> N ;
 
   vector<int> T(N);
   for (int i = 0; i < N; i++) {
     cin >> T.at(i);
   } 
  
   int M;
   cin >> M;
  // int型の2次元配列(M×2要素の)の宣言
  vector<vector<int>> P(M, vector<int>(2));
 
  // 入力 (2重ループを用いる)
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> P.at(i).at(j);
    }
  }
  
  for (int i = 0; i < M; i++) {
    int total = 0; //合計
    int count = 0; // カウンタ変数
    while (count < N) {
      if (count == P.at(i).at(0)-1) {
        total += P.at(i).at(1);        
      }
      else {
        total += T.at(count);  
      }
      count++;
    } 
    
    cout << total << endl;   
  } 
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{

 int a;
 while(cin>>a)
 {
     cout<<48-a<<endl;
 }

    return 0;
}


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

using namespace std;

const int INF=10e7;

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

    int taste=0, min_t=INF;
    for (int i=1;i<=N;i++) {
        int t = L+i-1;
        taste += t;

        if (abs(min_t) > abs(t)) {
            min_t = t;
        }
    }

    cout << taste - min_t << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

int n;
ll x;
vector<ll> a(51), p(51);

ll f(ll n, ll x) {
  // 1つ目のn-1のバーガーに届いていない場合
  if (n == 0) {
    return (x <= 0 ? 0 : 1);
  // 1つ目のn-1のバーガーに届いている場合
  } else if (x <= 1+a[n-1]) {
    return f(n-1, x-1);
  // 2つ目のn-1のバーガーに届いている場合
  } else {
    return p[n-1]+1 + f(n-1, x-2-a[n-1]);
  }
}

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

  cin >> n >> x;

  a[0] = 1;
  p[0] = 1;
  rep(i, n) {
    a[i+1] = a[i]*2+3;
    p[i+1] = p[i]*2+1;
  }

  cout << f(n, x) << endl;
}


Measured memory_bytes: 256
#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
const int N = 3009;
int coin[N];
ll dp[N][N][3];
int mod = 998244353 ;
int main() {
    int n,s;
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        scanf("%d",&coin[i]);
    }
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=s;j++){
            dp[i][j][0]+=dp[i-1][j][0];
            dp[i][j][1]+=dp[i-1][j][0]+dp[i-1][j][1];
            dp[i][j][2]+=dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j][2];
            
            dp[i][j][0]%=mod;
            dp[i][j][1]%=mod;
            dp[i][j][2]%=mod;
            if(j+coin[i]<=s){
                dp[i][j+coin[i]][1] += dp[i - 1][j][0] + dp[i - 1][j][1];
                dp[i][j+coin[i]][2] += dp[i - 1][j][0] + dp[i - 1][j][1];
            }
        }
        
    }
    cout<<dp[n][s][2]<<"\n";
}


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

public class Main {
	private BufferedReader br;
	private int len;
	private StringTokenizer st;
	private String aa,bb,cc;
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		new Main().start();
	}
	private void start() throws IOException{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=new StringTokenizer(br.readLine());
		aa=st.nextToken();
		bb=st.nextToken();
		cc=st.nextToken();
		if(aa.charAt(aa.length()-1)==bb.charAt(0) && bb.charAt(bb.length()-1)==cc.charAt(0)){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21204
fun main(args: Array<String>) {
    val mod = 998244353L
    val n = readLine()!!.toInt()
    val dList = readLine()!!.split(" ").map { it.toInt() }
    if (dList[0] != 0 || dList.count { it == 0 } != 1) {
        println(0)
        return
    }
    val distCnt = IntArray(n)
    val maxDist = dList.max()!!
    dList.forEach { distCnt[it]++ }
    var ans = 1L
    for (i in 1..maxDist) {
        for (k in 1..distCnt[i]) {
            ans *= distCnt[i - 1].toLong()
            ans %= mod
        }
    }
    println(ans)
}

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

bool bits[1<<20] = {0}; 
int lb = 1, bitcnt = 0;

bool inc(int i) {
  if (bits[0] or i < lb - 1 or (i == lb - 1 and bitcnt > lb - 1)) return false;
  while (bits[i] == 1) bits[i] = 0, lb -= lb == i, --i, --bitcnt;
  bits[i] = 1, ++bitcnt;
  while (bits[lb]) ++lb;
  return true;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int Q; cin >> Q;
  for (int x; Q; --Q) {
    cin >> x, cout << (inc(min(x, (1<<20) - 1)) ? "Yes" : "No") << '\n';
    //for (int i = 0; i < 10; ++i) cout << bits[i] << " \n"[i == 9];
    //cout << lb << '\n';
  }
}



Measured memory_bytes: 3732
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#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())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;
int n;
void  countingSort(int A[],int B[],int k){
    int C[k];
    for(int i = 0; i < k+1;i++) C[i]=0;

    for(int i = 0; i < n;i++){
        C[A[i]]++;
    }

    for(int i = 1; i < k;i++){
        C[i]+=C[i-1];
    }

    for(int i = n-1; i >= 0 ;i--){
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
    }
}


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int A[n];
    int B[n];
    int _max = 0;
    for(int i = 0; i < n;i++){
        cin >> A[i];
        _max = max(_max,A[i]);
    }

    countingSort(A,B,max(_max,n)+1);

    for(int i = 0; i < n;i++){
        if(i){
           cout << " "; 
        }
        cout << B[i];
    }
    cout << endl;
    

    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int h,w,n;
    Scd3(h,w,n);
    int x,y;
    multimap<int,int> c;
    multimap<int,int> d;

    Rep(i,n){
        Scd2(x,y);
        if( x >= y ){
            c.insert(make_pair(x-y,x));
            d.insert(make_pair(x-y,x));
        }
    }

    int ans = h+1;
    int mx = h;
    int pre = 1;
    Rep(i,w+h+1){
        mx = h+1;
        while( c.find(i) != c.end() ){
            auto it = c.find(i);
            //printf ("!%d,%d\n", it->first , it->second);
            mx = min(mx,it->second);
            c.erase(it);
        }
        //printf ("%d -> %d\n", i , mx );

        i++;
        while( d.find(i) != d.end() ){
            auto it = d.find(i);
            if( mx >= it->second ){
                //printf ("!!%d\n", it->second);
                ans = min(ans,it->second);
            }
            d.erase(it);
        }
        i--;
    }
    printf ("%d\n", ans-1);

    return 0;
}



Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <algorithm>

#define dbg if(0)
using namespace std;
#define ll long long

int main(){
    int n;
    string ans;
    cin >>n;
    if (n<105)cout <<"0"<<endl;
    else if (n<135)cout <<"1"<<endl;
    else if (n<165)cout <<"2"<<endl;
    else if (n<189)cout <<"3"<<endl;
    else if (n<195)cout <<"4"<<endl;
    else cout <<"5"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	string S;
	cin >> S;
	map<char, int>mp;
	int n = S.size();
	for (int i = 0; i < S.size(); i++) {
		mp[S[i]]++;
	}
	if (n == 1) {
		cout << "YES" << endl;
	}
	else if (n == 2) {
		if (S != "aa"&&S != "bb"&&S != "cc") {
			cout << "YES" << endl;
		}
		else cout << "NO" << endl;
	}
	else {
		if (n % 3 == 0) {
			if (mp['a'] == n / 3 && mp['b'] == n / 3 && mp['c'] == n / 3) {
				cout << "YES" << endl;
			}
			else cout << "NO" << endl;
		}
		else if (n % 3 == 2) {
			if (mp['a'] == n / 3 + 1 && mp['b'] == n / 3 + 1 && mp['c'] == n / 3) {
				cout << "YES" << endl;
			}
			else if (mp['a'] == n / 3 && mp['b'] == n / 3 + 1 && mp['c'] == n / 3 + 1) {
				cout << "YES" << endl;
			}
			else if (mp['a'] == n / 3 + 1 && mp['b'] == n / 3 && mp['c'] == n / 3 + 1) {
				cout << "YES" << endl;
			}
			else cout << "NO" << endl;
		}
		else {
			if (mp['a'] == n / 3 + 1 && mp['b'] == n / 3 && mp['c'] == n / 3) {
				cout << "YES" << endl;
			}
			else if (mp['a'] == n / 3 && mp['b'] == n / 3 + 1 && mp['c'] == n / 3) {
				cout << "YES" << endl;
			}
			else if (mp['a'] == n / 3 && mp['b'] == n / 3 && mp['c'] == n / 3 + 1) {
				cout << "YES" << endl;
			}
			else cout << "NO" << endl;
		}

	}
}


Measured memory_bytes: 512
n = int(input())
ta = input().split()
t = int(ta[0])
a = int(ta[1])
hlist = [int(h) for h in input().split()]


minsub = 999999999999999999999999999999999999999
minidx = None
for i, h in enumerate(hlist):
    temp = t - h * 0.006
    if abs(a - temp) < minsub:
        minsub = abs(a - temp)
        minidx = i


print(minidx + 1)


Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int N;
int *A;

int main(int argc, char *argv[]) {
	int sr;
	int i;
	int ret;
	int em, em_s, ei;
	int emax(int *, int *, int *);

	sr=scanf("%d", &N);

	A = malloc(sizeof(int)*N);
	for (i=0; i<N; i++) {
		sr=scanf("%d", A+i);
	}

	em = emax(A, &em_s, &ei);

	for (i=0; i<N; i++) {
		if (i==ei) {
			printf("%d\n", em_s);
		} else {
			printf("%d\n", em);
		}
	}

}

int emax(int *A, int *em_s, int *ei) {
	int mn;
	int k;

	mn=0;
	for (k=0; k<N; k++) {
		if (mn<*(A+k)) {
			*em_s=mn;
			mn = *(A+k);
			*ei = k;
		} else {
			if (*em_s<*(A+k)) {
				*em_s = *(A+k);
			}
		}
	}
	return mn;
}


Measured memory_bytes: 2304