akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll C=0;
ll T[107],T1[107],T2[107];
vector<vector<ll>> V(107);

void dfs(int X){
    T[X]=1;
    C++;
    T1[X]=C;
    rep(i,V[X].size()){
        if(T[V[X][i]]==0){
            dfs(V[X][i]);
        }
    }
    C++;
    T2[X]=C;
}
 
int main(){
    ll N,A,B,C;
    cin >> N;
    rep(i,N){
        cin >> A >> B;
        rep(j,B){
            cin >> C;
            V[A].push_back(C);
        }
    }
    rep(i,N){
        if(T[i+1]==0){
            dfs(i+1);
        }
    }
    rep(i,N){
        cout << i+1 <<" "<< T1[i+1] << " " << T2[i+1] << endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  int zero = 0;
  int one = 0;
  int moreThanTwo = 0;
  for(int i=0; i<n; i++){
    int cnt = 0;
    int num;
    cin >> num;
    while(num % 2 == 0){
      num /= 2;
      cnt++;
    }
    if(cnt == 0) zero++;
    if(cnt == 1) one++;
    if(cnt >= 2) moreThanTwo++;
  }
  if(one == 0){
  	if(zero-1 <= moreThanTwo) cout << "Yes" << endl;
  	else cout << "No" << endl;
  }else{
    if(zero <= moreThanTwo) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
loop do
	nums = gets.chomp.split(" ").map(&:to_i)
	break if nums == [0,0]
	for h in (0...nums[0]) do
		for w in (0...nums[1]) do
			if (h.odd? && w.odd?) || (h.even? && w.even?)
				print "#"
			elsif 
				print "."
			end
		end
		puts
	end
	puts
end

Measured memory_bytes: 8776
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.util.PriorityQueue;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 int[][] dp=new int[(1<<15)+1][5];
 dp[0][0]=1;
 for(int i=1;i*i<=1<<15;i++){
  for(int j=1;j<=4;j++){
   for(int k=i*i;k<=1<<15;k++){
    dp[k][j]+=dp[k-i*i][j-1];
   }
  }
 }
 for(;;){
  int n=ir.nextInt();
  if(n==0) return;
  int tot=0;
  for(int i=1;i<=4;i++) tot+=dp[n][i];
  out.println(tot);
 }
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {

 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
 
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

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

 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }

 public long[] nextLongArray(int n){
  long[] a=new long[n];
  for(int i=0;i<n;i++) a[i]=nextLong();
  return a;
 }

 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 26288
#include <bits/stdc++.h>
using namespace std;
const int N=3005;

int a,b,c,d,e,f;
bool flag[N][N];
pair<int,int> ans;

void rec(int mass, int sugar){
	if (flag[mass][sugar]){
		return;
	}
	flag[mass][sugar]++;
	if (sugar*100<=(mass-sugar)*e){
		if (sugar*ans.first>=ans.second*mass){
			ans={mass,sugar};
		}
	}
	if (mass+100*a<=f){
		rec(mass+100*a,sugar);
	}
	if (mass+100*b<=f){
		rec(mass+100*b,sugar);
	}
	if (mass+c<=f){
		rec(mass+c,sugar+c);
	}
	if (mass+d<=f){
		rec(mass+d,sugar+d);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b >> c >> d >> e >> f;
	rec(0,0);
	cout << ans.first << " " << ans.second << "\n";
}

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

namespace ABC109C_cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var vs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var x = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var xa = x.Select(p => Math.Abs(p - vs[1])).ToArray();
            var tmp = xa[0];
            for (int i = 0; i < vs[0]; i++)
            {
                tmp = gcd(tmp, xa[i]);
            }
            Console.WriteLine(tmp);
        }
        static int gcd(int a, int b)
        {
            if (a > b)
            {
                return gcd(b, a);
            }
            while (b != 0)
            {
                var rem = a % b;
                a = b;
                b = rem;
            }
            return a;
        }
    }
}


Measured memory_bytes: 20704
#include <iostream>
#include <climits>
using namespace std;
int main()
{
	int n,k;
	cin >> n >> k;
	int heights[n];
	for(int i = 0;i < n;++i)
		cin >> heights[i];
	int dp[n];
	dp[0] = 0;
	for(int i = 1;i < n;++i)
	{
		dp[i] = INT_MAX;
		for(int j = 1;j <= k;++j)
		{
			if(i - j >= 0)
				dp[i] = min(dp[i],abs(heights[i] - heights[i-j]) + dp[i-j]);
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;

ll minv[4000001];
ll C[4000001];
int N,K;

ll dp[2001][2001];
ll back(ll i, ll j){
    ll &ret = dp[i][j];
    if(ret) return ret;
    if(i==0&&j==0) return ret=1;

    if(i) ret += back(i-1,j);
    if(j>i) ret += back(i,j-1)*C[i+j*(K-1)-1]%MOD;
    return ret %= MOD;
}

int main(){
    scanf("%d%d",&N,&K);

    minv[1] = 1;
    for(int i=2;i<=N*K;i++){
        minv[i] = MOD - (MOD/i)*minv[MOD%i]%MOD;
    }

    C[K-2] = 1;
    for(int i=K-1;i<=N*K;i++){
        C[i] = C[i-1]*i%MOD*minv[i-(K-2)]%MOD;
    }

    if(K==1) printf("1");
    else{
        ll ans = back(N,N);
        for(int i=1;i<=N;i++) ans=ans*i%MOD;
        printf("%lld",ans);
    }
}


Measured memory_bytes: 85504
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>//memset()
#include<algorithm>
#include<sstream>
#include<stack>
#include<bitset>
#include<queue>
#include<cmath>
#include<set>
#define ll long long
#define PI 3.14159265358979323846
#define IO ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,start,end) for(int i=start;i<end;i++)
#define per(i,start,end) for (int i=end-1;i>=start;i--)
using namespace std;

const ll mod=1000000007;
const ll inf=1e9;

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}
ll leastbit(ll a) { return a&(-a);}
ll C(int a,int b) { ll res=1;rep(i,0,b)res=res*(a-i)/(i+1);return res;}
ll powmod(ll a,ll  b) { if(b==0)return 1;ll cnt=powmod(a,b/2);(cnt*=cnt) %=mod;if(b&1){(cnt*=a) %= mod;}return cnt;}


int main()
{IO
#ifndef ONLINE_JUDGE
    //freopen("output.txt","w",stdout);
#else
#endif
    ll n,arr[500];
    ll sum=1000;
    cin>>n;
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=1;i<n;i++){
        if(arr[i-1]<arr[i]){        
            ll num=sum/arr[i-1];
            //cout<<num<<endl;
            sum+=arr[i]*num;
            sum-=num*arr[i-1];
        }
    }
    cout<<sum<<endl;
    
    
    return 0;
}

Measured memory_bytes: 3604
// AOJ Volume 0 Problem 0052

#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    int n_2, n_5;
    int i, j;

    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        n_2 = n_5 = 0;
        for (i = 1; i <= n; i++){
            j = i;
            while (j % 5 == 0){
                j /= 5;
                n_5++;
            }
            while (j % 2 == 0){
                j /= 2;
                n_2++;
            }
        }
        if (n_2 < n_5){
            printf("%d\n", n_2);
        }
        else {
            printf("%d\n", n_5);
        }
    }

	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;

int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll a,b; cin>>a>>b;
        if(a>b) swap(a,b);
        if((a+b)%2) cout<<"IMPOSSIBLE";
        else cout<<(a+b)/2;
    }   
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

//数字6個と方角を受け取って数字6個を返す関数
int *dice(int *me,char *houi){
  int kari,i=0,j;
  while(1){
    if(houi[i]=='E'){
      kari=me[0];
      me[0]=me[3];
      me[3]=me[5];
      me[5]=me[2];
      me[2]=kari;
    }else if(houi[i]=='N'){
      kari=me[0];
      me[0]=me[1];
      me[1]=me[5];
      me[5]=me[4];
      me[4]=kari;
    }else if(houi[i]=='S'){
      kari=me[0];
      me[0]=me[4];
      me[4]=me[5];
      me[5]=me[1];
      me[1]=kari;
    }else if(houi[i]=='W'){
      kari=me[0];
      me[0]=me[2];
      me[2]=me[5];
      me[5]=me[3];
      me[3]=kari;
    }
    if(houi[i]=='\0')break;
    i++;
  }
  return me;
}

int main(){
  int me1[6],me2[6],me3[6];       //サイコロの目
  char N[2]="N";
  char W[2]="W";
  char E[2]="E";
  char S[2]="S";
  char NN[3]="NN";
  char ho[4]="SEN";  //方位の命令
  int i,j;
  
  //読み取り
  for(i=0;i<6;i++){
    scanf("%d",&me1[i]);
  }
  for(i=0;i<6;i++){
    scanf("%d",&me2[i]);
    me3[i]=me2[i];
  }
  
  //とりあえず上下を合わせる
  if(me1[0]==me2[0]&&me1[5]==me2[5]){
    int *me3=dice(me2,ho);
  }else if(me1[0]==me3[1]&&me1[5]==me3[4]){
    int *me3=dice(me2,N);
  }else if(me1[0]==me3[2]&&me1[5]==me3[3]){
    int *me3=dice(me2,W);
  }else if(me1[0]==me3[3]&&me1[5]==me3[2]){
    int *me3=dice(me2,E);
  }else if(me1[0]==me3[4]&&me1[5]==me3[1]){
    int *me3=dice(me2,S);
  }else if(me1[0]==me3[5]&&me1[5]==me3[0]){
    int *me3=dice(me2,NN);
    
  }else {
    printf("No\n");
    return 0;
  }
  
                           
  
  
  //比較
  for(i=0;i<5;i++){
    if(me1[1]==me2[1]&&me1[2]==me2[2]&&me1[3]==me2[3]&&me1[4]==me2[4]){
      printf("Yes\n");
      break;
    }else {
      int *me3=dice(me2,ho);
      
    }
    if(i==4){
      printf("No\n");
      break;
    }
  }
  return 0; 
}








Measured memory_bytes: 2104
L, R = map(int, input().split())
ql = L//2019
qr = R//2019
rl = L%2019
rr = R%2019
if ql != qr:
    print(0)
else:
    listans = []
    for i in range(rl,rr):
        for j in range(i+1,rr+1):
            ans = (i*j)%2019
            listans.append(ans)
    print(min(listans))      

Measured memory_bytes: 75416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
int a[200000];
int main()
{
	int m,n,i,j,t,k;
	cin>>n>>m>>i;
	t=n;
	n=m;
	m=t;
	t=n;
	n=i;
	i=t;
	cout<<n<<" "<<m<<" "<<i;
 } 

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll h,w;
    cin >> h >> w;
    string ans;
    rep(i,h){
        rep(j,w){
            string s;
            cin >> s;
            if(s=="snuke"){
                char c = 'A' + j;
                ans = c + to_string(i+1);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double fact(double n)
{
    double ff=1;
    for(double i=n; i>1; i--)
        ff*=i;
    return ff;
}
double dis(pair<double,double> a,pair<double,double> b)
{
    return sqrt(pow(a.first-b.first,2.0)+pow(a.second-b.second,2.0));
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,t,j,n;
    double a,b,sum=0,m;

    cin>>t;
    n=t;
    vector<pair<double,double>> point;
    m=fact(t*1.0);
    while(t--)
        {
            cin>>a>>b;
            point.push_back(make_pair(a,b));
        }
    sort(point.begin(), point.end());

    do
        {
            for(int i=1; i<n; i++)
                sum+=dis(point[i],point[i-1]);
        }
    while (next_permutation(point.begin(), point.end()));
    //cout<<sum<<" "<<m<<endl;

    sum/=m;
    cout<<fixed<<setprecision(7)<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            var min = a.Skip(i).Min();
            if (a[i] != min)
            {
                var ind = i + a.Skip(i).TakeWhile(x => x != min).Count();
                var tmp = a[i];
                a[i] = a[ind];
                a[ind] = tmp;
                res++;
            }
        }
        Console.WriteLine(string.Join(" ", a));
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 18316
/* @ by batr (T) */
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
 
#define cmp_all(X) (X).begin(), (X).end(), cmp
 
#define B begin()
#define E end()
#define sz size()
#define skip continue
 
#define ppi pair<pair<int, int>, int>
#define pii pair<int, int> 
#define pli pair<ll, int>
#define pcc pair<char, char>
 
#define F first
#define S second

using namespace std;
 
const int maxn = 1e7 + 17;
const int MAXN = maxn * 4;
const int darr = 1e3 + 17;
const ll INF = 1e17 + 5;
const int mod = 1e9 + 7;
 
void Need_For_Speed () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
int a[maxn];

vector <int> v;

int main () { 
	Need_For_Speed();
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] != a[i-1]) {
			v.pb(a[i]);
		}
	}
	string dir;
	int ct = 1;
	bool b = 0;
	for (int i = 1; i < v.sz; i++) {
		if (b == 0) {
			if (v[i] > v[i-1]) {
				dir = "inc";
			}
			else {
				dir = "dec";
			}
			b = 1;
			skip;
		}
		if (dir == "inc") {
			if (v[i] < v[i-1]) {
				ct++;
				b = 0;
			}
		}
		else {
			if (v[i] > v[i-1]) {
				ct++;
				b = 0;
			}
		}
	}
	cout << ct;
	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<ll, ll> P;
int main()
{
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    vector<P> value(4);
    value[0] = P(Q * 8, 0); value[1] = P(H * 4, 0);
    value[2] = P(S * 2, 0); value[3] = P(D, 1);
    sort(all(value));
    ll s2 = N / 2;
    ll ans = s2 * value[0].first;
    if (N % 2) {
        ll concent = value[0].first;
        if (value[0].second == 1) {
            concent = value[1].first;
        }
        ans += concent / 2;
    }

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

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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


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

const ll MAX_N = 100, MAX_K = 1e5;
ll N, K;
ll a[MAX_N];
ll dp[MAX_N + 2][MAX_K + 2] = {};

ll residue(ll n, ll m){
  return ((n % m) + m) % m;
}
int main(){
  cin >> N >> K;
  REP(i, N){
    cin >> a[i];
  }
  REP(k, K + 1){
    dp[0][k + 1] = 1;
  }
  REP(i, N){
    dp[i + 1][0] = 0;
    REP(k, K + 1){
      if (k >= a[i]){
        dp[i + 1][k + 1] = dp[i + 1][k] + dp[i][k + 1] - dp[i][k - a[i]];
      }
      else {
        dp[i + 1][k + 1] = dp[i + 1][k] + dp[i][k + 1];
      }
      dp[i + 1][k + 1] = residue(dp[i + 1][k + 1], MOD);
//      printf("dp[%lld][%lld] = %lld\n", i + 1, k + 1, dp[i + 1][k + 1]);
    }
  }
  cout << residue(dp[N][K + 1] - dp[N][K], MOD) << endl;
}


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

int w, h;
int s[32][32];
int cost[4];

// dir
// 0 : right
// 1 : up
// 2 : left
// 3 : down
const int dr[4] = {0, -1, 0, 1};
const int dc[4] = {1, 0, -1, 0};
const int dd[4] = {0, 3, 2, 1};

typedef std::pair<int, int> Pii;

class Node {
public:
  Node() {}
  Node(int r_, int c_, int dir_) : r(r_), c(c_), dir(dir_) {}
  int r, c, dir;
};

class Data {
public:
  Data() {}
  Data(Node s_, Node t_, int cost_) : s(s_), t(t_), cost(cost_) {}
  Node s, t;
  int cost;
};

inline bool operator < (const Data& a, const Data& b) {
  return a.cost > b.cost;
}

int dist[32][32][8];
int dijkstra() {
  std::priority_queue<Data> q;
  int r = 0;
  int c = 0;
  int dir = 0;
  dist[r][c][dir] = 0;
  for(int k = 0; k < 4; ++k) {
    int nd = (dir + dd[k]) % 4;
    int nr = r + dr[nd];
    int nc = c + dc[nd];
    if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue;
    q.push(Data(Node(r, c, dir), Node(nr, nc, nd), k == s[r][c] ? 0 : cost[k]));
  }
  while( not q.empty() ) {
    Data t = q.top(); q.pop();
    int r = t.t.r, c = t.t.c, dir = t.t.dir;
    if( dist[r][c][dir] <= dist[t.s.r][t.s.c][t.s.dir] + t.cost ) {
      continue;
    }
    dist[r][c][dir] = std::min(dist[r][c][dir], dist[t.s.r][t.s.c][t.s.dir] + t.cost);
    if( r == h - 1 and c == w - 1 ) continue;
    for(int k = 0; k < 4; ++k) {
      int nd = (dir + dd[k]) % 4;
      int nr = r + dr[nd];
      int nc = c + dc[nd];
      if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue;
      q.push(Data(Node(r, c, dir), Node(nr, nc, nd), k == s[r][c] ? 0 : cost[k]));
    }
  }
  int res = (1 << 30);
  for(int i = 0; i < 4; ++i) {
    res = std::min(res, dist[h-1][w-1][i]);
  }
  return res;
}

void Init() {
  for(int i = 0; i < 32; ++i) {
    for(int j = 0; j < 32; ++j) {
      for(int k = 0; k < 8; ++k) {
        dist[i][j][k] = (1 << 29);
      }
    }
  }
}

int main() {
  for(;;) {
    Init();
    scanf("%d %d", &w, &h);
    if( w == 0 and h == 0 ) break;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        scanf("%d", &s[i][j]);
      }
    }
    for(int i = 0; i < 4; ++i) {
      scanf("%d", &cost[i]);
    }
    int res = dijkstra();
    printf("%d\n", res);
  }
  
  return 0;
}

Measured memory_bytes: 8684
import Control.Monad (replicateM)
import Data.ByteString.Char8 as C (readInteger, words, getLine)
import Data.Maybe (fromJust)

f :: [[Integer]] -> Integer -> Integer
f [] _ = 0
f ([a, b]:abs) acc =
    c + f abs (acc + c)
  where c = (-a - acc) `mod` b

main = do
    n <- readLn :: IO Int
    ab <- reverse <$> replicateM n ((map (fst . fromJust . C.readInteger) . C.words) <$> C.getLine) :: IO [[Integer]]
    print $ f ab 0

Measured memory_bytes: 31868
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
    int n;
    cin>>n;
    lli arr[n], val = 0.0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr, arr+n);
    val = arr[0] + arr[1];
    lli x = 2ll;
    for(int i=2;i<n;i++){
        val = val + arr[i] * x;
        x *= 2;
    }
    double ans = 1.0 * val/x;
    cout<<setprecision(10)<<ans<<"\n";
    return 0;
}


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

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = Input.NextInt();
            var list = Input.IntList();

            Console.WriteLine(list.Max() - list.Min());
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<vector<int>> c(3,vector<int>(3));
    int Max = 0;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
            if(i == 0) Max =max(Max,c[i][j]);
        }
    }
    int a1,b1,b2,b3;
    bool flag = false;
    for(int i = 0; i <= Max; i++){
        a1 = i;
        b1 = c[0][0] - a1;
        b2 = c[0][1] - a1;
        b3 = c[0][2] - a1;
        if((c[1][0] - b1 == c[1][1] - b2 && c[1][0] - b1 == c[1][2] - b3) && (c[2][0] - b1 == c[2][1] - b2 && c[2][0] - b1 == c[2][2] - b3)){
            flag = true;
            break;
        }
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;

    rep(i,0,100) rep(j,0,100) if(4*i+7*j==N){
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
A = [int(a) for a in input().split()]

ans = 0
for i in range(N):
  if i == 0:
    if A[i] <= x:
      pass
    else:
      ans += A[i] -x
      A[i] = x
  else:
    rest = x - A[i-1]
    if A[i] <= rest:
      pass
    else:
      ans += A[i] - rest
      A[i] = rest
print(ans)


Measured memory_bytes: 14052
n = int(input())
l = list(map(int,input().split()))
count = 0

for i in range(1,n):
    if l[i-1] == i:
        l[i-1],l[i] = l[i],l[i-1]
        count += 1
if l[n-1] == n:
    count += 1
print(count)

Measured memory_bytes: 13880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int d = s.nextInt();
        if(d==7||d==5||d==3) System.out.println("YES");
        else System.out.println("NO");


    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;

ll check(vector<ll>& A, int start_sign, int N)
{
  ll diff = 0, ret = 0;
  for (int i = 1, sign = start_sign; i <= N; ++i, sign *= -1) {
    ll val = A[i] + diff;
    if (sign > 0) {
      if (val > 0) { continue; }
      diff += abs(val) + 1;
      ret += abs(val) + 1;
    }
    else if (sign < 0) {
      if (val < 0) { continue; }
      diff -= (val + 1);
      ret += val + 1;
    }
  }
  return ret;
}

int main()
{
  int N; scanf("%d", &N);
  vector<ll> A(N + 5);
  for (int i = 1; i <= N; ++i) {
    scanf("%lld", &A[i]);
    A[i] += A[i - 1];
  }
  ll cnt1 = check(A, 1, N);
  ll cnt2 = check(A, -1, N);
  ll ans = min(cnt1, cnt2);
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
	long long n, m, k, a[200001], b[200001];
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i)a[i]+=a[i-1];
	}
	for(int i = 1; i <= m; i++){
		cin >> b[i];
		if(i)b[i]+=b[i-1];
	}
	int ans = 0;
	for(int i = 0; i <= n; i++){
		if(a[i] > k)break;
		int j = upper_bound(b, b + m + 1, k - a[i]) - b;
		ans = max(ans, i+j-1);
	}
	cout << ans  << '\n';
}

Measured memory_bytes: 6716
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int a, b;
  cin >> a >> b;

  if (a > b) {
    cout << a - 1 << endl;
  }
  else {
    cout << a << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    n = 5;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << i + 1;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <limits.h>
#include <map>
#define MAXN 100000
#define Amari 1000000007
#define p pair <int,int>
using namespace std;
multimap <int, int> ship;
bool clear = false; 
vector <int> buckets(100004,0);
int main(int argc,char const* argv[])
{
  long long x,y,answer=0;
  cin >> x >> y;
  if(x*y>0)
    {
      if((abs(y)>=abs(x) && x>0 )||(abs(x)>=abs(y) && x<0))
	{
	  answer+=(max(abs(x),abs(y))-min(abs(x),abs(y)));
	}
      else if((abs(y)>abs(x) && x<0) || (abs(x)>abs(y)&& x>=0))
	{
	  answer++;
	  answer+=(max(abs(x),abs(y))-min(abs(x),abs(y)));
	  if(y !=0 && x !=0)answer++;
	}
    }
  else if(x*y<=0)
    {
      if(x >=0 && y<0)answer++;
      else if(x <0 && y>0) answer++;
      else if(x >=0 && y==0) answer++;
      answer+=(max(abs(x),abs(y))-min(abs(x),abs(y)));
    }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    cout << ((n>=3200)?s:"red")<<endl;
    return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){ 
    ll A,B,K;
    cin >> A >> B >> K;
    if( (A-K) >= 0 ){
        cout << (A-K) << " " << B << endl;
    }else if( ( B-(K-A)) >= 0 ){
        cout << 0 << " " << B-(K-A) << endl;
    }else{
        cout << 0 << " " << 0 << endl;
    }

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>


using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}

auto mdist(pair<int, int> a, pair<int, int> b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
int main() {

	int N;

	cin >> N;
	vector<int> a, anum(N,0);
	vector<ll> w(N+1);
	a.resize(N);
	w.resize(N+1);
	w[0] = 0;
	w[1] = 0;
	rep(i, 2, N+1) {
		w[i] = i * (i - 1) / 2;
	}

	ll sum = 0;
	rep(i, 0, N) {
		cin >> a[i];
		anum[a[i] - 1] += 1;
	}
	rep(i, 0, N) {
		sum += w[anum[i]];
	}

	ll tsum;
	rep(i, 0, N) {
		int temp;
		temp = anum[a[i]-1] - 1;
		tsum = sum;
		tsum -= w[anum[a[i]-1]];
		if (temp < 0) temp = 0;
		tsum += w[temp];
		cout << tsum << endl;

	}

	return 0;
}



Measured memory_bytes: 5760
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
//const long long INF = 1LL << 60;
const int INF = 1e9;
const int MOD = 1000000007;
using ll = long long;

int N;
ll ans = 0;

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

	std::cout << s;
	if(s[s.length()-1] == 's')
	{
		std::cout << "es" << std::endl;
	} 
	else
	{
		std::cout << "s" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
int main(void)
{
	int n,m,a[51],b[51],c[51],i,j;
	scanf("%d%d",&n,&m);
	for(i=0; i<m; i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	for(i=1; i<=n; i++){
		c[i]=0;
	}
	for(i=0; i<m; i++){
		for(j=1; j<=n; j++){
			if(a[i]==j){
				c[j]=c[j]+1;
			}
			if(b[i]==j){
				c[j]=c[j]+1;
			}
		}
	}
	for(i=1; i<=n; i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

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

#define MOD 1000000007
#define NALPHABETS 26

void solve()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    set<int> s[NALPHABETS];
    rep(i, N)
    {
        s[S[i] - 'a'].insert(i);
    }

    int Q;
    cin >> Q;
    rep(q, Q)
    {
        int type;
        cin >> type;
        if (type == 1)
        {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (c == S[i])
                continue;
            s[S[i] - 'a'].erase(i);
            s[c - 'a'].insert(i);
            S[i] = c;
        }
        else if (type == 2)
        {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            int ans = 0;
            rep(j, NALPHABETS)
            {
                auto iter = s[j].lower_bound(l);
                if (iter == s[j].end())
                    continue;
                if (*iter <= r)
                    ans++;
            }
            cout << ans << endl;
        }
    }
}

int main()
{
    solve();
    return 0;
}


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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            var n = int.Parse(Console.ReadLine());

            var x = n / (decimal)3;
            var y = n / (decimal)3;
            var z = n - x - y;

            Console.WriteLine(x * y * z);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)

using namespace std;

int a, b, c;

int main() {
  ios::sync_with_stdio(false);
  while (cin >> a >> b >> c) {
    bool yes = false;
    FOR(x, 1, 1000) 
      if ((a * x) % b == c) {
        yes = true; break;
      }
    if (yes) cout << "YES";
     else cout << "NO";
    cout << endl;
  }
  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 rate;
    int rank = 1;
    int[] boarder = { 600, 800, 1000, 1200, 1400, 1600, 1800 };
    rate = sc.nextInt();
    for (int q = 0; q < 7; q++) {
      if (rate < boarder[q]) {
        rank = 8 - q;
        break;
      }
    }
    System.out.println(rank + "");
    sc.close();
  }
}

Measured memory_bytes: 38712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String abcd = scanner.next();

        char[] split = abcd.toCharArray();
        int digit = split.length;

        for (int i = 0; i < Math.pow(2, digit - 1); i++) {
            int sum = 0;
            boolean sign = true; // true: +, false: -
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < digit; j++) {
                sb.append(split[j]);
                int num = Integer.parseInt(String.valueOf(split[j]));
                if (sign) sum += num;
                else sum -= num;
                if ((1 & i >> j) == 1) {
                    sb.append("+");
                    sign = true;
                } else if (j < digit - 1) {
                    sb.append("-");
                    sign = false;
                }
            }
            if (sum == 7) {
                sb.append("=").append(sum);
                System.out.println(sb.toString());
                break;
            }
        }
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K;
    cin >> K;
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[K - 1] << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>
 
//#define int long long
 
#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define endl '\n'
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
mt19937 mrand(random_device{}());
 
double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
 
void solve();
void scan();
 
signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return;
}

Measured memory_bytes: 896
package main

import (
        "fmt"
)

// 解説と同じ解法で解いてみる

// N を 6^p で払う額と 9^p で払う額に分ける。
// N を 6^p で表せる額だけで払うとき、各i に対して
// 6^i 円で払う回数は floor(N/6^i)%6 で求まる。

func main() {
        var n int
        fmt.Scan(&n)

        mincnt := n
        for i := 0; i <= n; i++ {
                cnt := 0
                nn := i
                for nn > 0 {
                        cnt += nn % 6
                        nn /= 6
                }
                nn = n - i
                for nn > 0 {
                        cnt += nn % 9
                        nn /= 9
                }
                if cnt < mincnt {
                        mincnt = cnt
                }
        }
        fmt.Println(mincnt)
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))

dp = [[0, 0] for _ in range(N + 1)]
dp[N][0] = A[N]
dp[N][1] = A[N]

for i in range(N)[::-1]:
    dp[i][0] = -(-dp[i + 1][0]//2) + A[i]
    dp[i][1] = dp[i + 1][1] + A[i]

res = [0 for _ in range(N + 1)]

tmp = 1
for i in range(N + 1):
    if tmp < dp[i][0] or dp[i][1] < tmp // 2:
        print(-1)
        break
    res[i] = min(tmp, dp[i][1])
    tmp = res[i]
    tmp -= A[i]
    tmp *= 2

else:
    print(sum(res))

Measured memory_bytes: 91644
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
	string s;
	cin >> s;
	int ans = 1;
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < s.size(); j++){
			if(i != j && s[i] == s[j]) ans = 0;
		}
	}
	if(ans == 0) cout << "no" << endl;
	else cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,x=0,y=0;
    cin>>a;
    int b[a];
    for(int i=0;i<a;i++) cin>>b[i];
    sort(b,b+a);
    for(int i=1;i<=a;i++){
        if(i%2) x+=b[a-i];
        else y+=b[a-i];
    }
    cout<<x-y<<endl;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    map<string, int> Name;
    Name["AC"] = 0;
    Name["WA"] = 1;
    Name["TLE"] = 2;
    Name["RE"] = 3;
    int res[4] = {0, 0, 0, 0};
    rep(i, n){
        cin >> s;
        res[Name[s]]++;
    }
    cout << "AC" << ' ' << 'x' << ' ' << res[0] << endl;
    cout << "WA" << ' ' << 'x' << ' ' << res[1] << endl;
    cout << "TLE" << ' ' << 'x' << ' ' << res[2] << endl;
    cout << "RE" << ' ' << 'x' << ' ' << res[3] << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int X, t;

int main(void){
    
    scanf("%d %d", &X, &t);
    
    int ans = X - t;
    if(ans < 0) printf("0\n");
    else printf("%d\n",ans);
    
}


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

using namespace std;

queue<int> q[1000];
int n, a, i, j;
int d[1000];
int c = 0, t = 0, now, l;
bool f;

int main() {
    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n - 1; ++j) {
            scanf("%d", &a);
            q[i].push(a- 1);
        }
        d[i] = -1;
    }
    l = n * (n - 1) / 2;

    while (true) {
        f = false;
        for (i = 0; i < n - 1; i++) {
            if (!q[i].empty()) {
                now = q[i].front();
                if (!q[now].empty() && q[now].front() == i) {
                    if (d[i] == c || d[now] == c) continue;
                    q[i].pop();
                    q[now].pop();
                    d[i] = c;
                    d[now] = c;
                    f = true;
                    t++;
                }
            }
        }
        c++;
        if (!f) {
            cout << "-1" << endl;
            return 0;
        }
        if (t == l) {
            cout << c << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> b(n-1);
  for(int i=0;i<n-1;i++)
    cin>>b.at(i);
  vector<int> a(n);
  a.at(0)=b.at(0);
  for(int i=0;i<n-1;i++)
    a.at(i+1)=b.at(i);
  for(int i=0;i<n-1;i++)
    if(b.at(i)<max(a.at(i),a.at(i+1)))
      a.at(i)=b.at(i);
  int s=0;
  for(int i=0;i<n;i++)
    s+=a.at(i);
  cout<<s<<endl;
}

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

int main() {

  string s;
  map<string, int> names;

  while(cin>>s) {
    if(s=="") break;
    if( names.find(s) == names.end() ) {
      names.insert( map<string, int>::value_type(s,1) );
    }else{
      names[s]++;
    }
  }

  //cout<<"AA"<<endl;
  map<string, int>::iterator it = names.begin();
  int max=0,ml=0;
  string lo,fr;
  while( it != names.end() ) {
    //cout<<(*it).first<<" "<<(*it).second<<endl;
    if( (*it).second > max ) {
      max = (*it).second;
      fr = (*it).first;
    }
    if( (*it).first.length() > ml ) {
      ml = (*it).first.length();
      lo = (*it).first;
    }
    it++;
  }

  cout<<fr<<" "<<lo<<endl;
}

Measured memory_bytes: 0
from math import sqrt
from bisect import bisect_right

def eratos(n):
    L = [True for _ in range(n+1)]
    L[0],L[1] = False,False

    for i in range(2,int(sqrt(n))+1):
        if L[i]:
            for j in range(2,n//i+1):
                L[i*j] = False

    P = []
    for i in range(n+1):
        if L[i]:
            P.append(i)

    return P

def sim(P):
    #よく考えたら元の数より小さい数に対する判定
    #なのでisPrime関数を使うまでもない
    P_set = set(P)
    P_sim = []
    for i in range(len(P)):
        if (P[i]+1)//2 in P_set:
            P_sim.append(P[i])

    return P_sim

def main():
    Q = int(input())

    P = eratos(10**5)
    P_sim = sim(P)

    ans_L = []
    for i in range(Q):
        l,r = map(int,input().split())
        ans = bisect_right(P_sim,r)-bisect_right(P_sim,l-1)
        ans_L.append(ans)

    for i in range(Q):
        print(ans_L[i])

if __name__ == "__main__":
    main()


Measured memory_bytes: 8224