akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long dp[1001][1001];
int st[1001][1001];
int h,w;
string s[1001];

int solve(int i,int j)
{
    
    
    if(i==-1 || j==-1) return 0; 
    else if(s[i][j]=='#'){st[i][j]=1;return 0;}
    else if(st[i][j]) {return dp[i][j];} 
    //else if(i==0 && j==0) {dp[i][j]=1;return 1;}
    else {
        
        
        dp[i][j]= (solve(i-1,j)+solve(i,j-1))%1000000007;
        // (dp[i][j]+= solve(i,j-1))%=1000000007;
        st[i][j]=1;
        return dp[i][j];
    }
}
int main() {
	cin>>h>>w;for(int i=0;i<h;++i)cin>>s[i];
	/*dp[0][0]=1;
	for(int i=1;i<h;++i)
	    if(s[i][0]=='.')dp[i][0]=dp[i-1][0];
	for(int j=1;j<w;++j)
	    if(s[0][j]=='.')dp[0][j]=dp[0][j-1];
	for(int i=1;i<h;++i)
	 {   for(int j=1;j<w;++j)
	        {     if(s[i][j]=='.')
	              dp[i][j]= (dp[i-1][j]+dp[i][j-1])%1000000007;
	              
	        }
    }
	        
	cout<<dp[h-1][w-1];
	*/
	dp[0][0]=1;st[0][0]=1;
	cout<<solve(h-1,w-1);
	return 0;
}

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

vector<int> values;

int main() {
	int a, b;

	cin >> a >> b;

	values.push_back(a + b);
	values.push_back(a - b);
	values.push_back(a * b);

	sort(values.begin(), values.end());

	cout << values[2];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ef(i,u) for(int i=b[u];i;i=nxt[i])
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n,a[N];
map<int,int>mp;
int main(){
    read(n);
    rep(i,1,n)read(a[i]),mp[i-a[i]]++,a[i]=a[i]+i;
    ll ans=0;
    rep(i,1,n){
        ans+=mp[a[i]];
    }
    cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 21252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	map<string, int> cnt;
	while (n--) {
		string s;
		cin >> s;
		cnt[s]++;
	}
	for (auto s : {"AC", "WA", "TLE", "RE"}) {
		cout << s << " x " << cnt[s] << endl;
	}
}

Measured memory_bytes: 3648
public class Main {
  private static void solve() {
    char[] s = ns();
    int n= s.length;
    int l = 0, r = 0;
    for (int i = 0; i < n; i ++) {
      if (s[i] == '0' && i % 2 == 0 || s[i] == '1' && i % 2 == 1) {
        l ++;
      }
      if (s[i] == '1' && i % 2 == 0 || s[i] == '0' && i % 2 == 1) {
        r ++;
      }
    }
    System.out.println(Math.min(l, r));

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 26708
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        long c = sc.nextLong();
        long x[] = new long[n + 2];
        long v[] = new long[n + 2];
        for (int i = 1; i <= n; i++) {
            x[i] = sc.nextLong();
            v[i] = sc.nextLong();
        }
        x[n + 1] = c;

        long left[] = new long[n + 1];
        long right[] = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            left[i] = left[i - 1] + v[i] - x[i] + x[i - 1];
            right[i] = right[i - 1] + v[n - i + 1] - x[n - i + 2] + x[n - i + 1];
        }

        long maxLeft[] = new long[n + 1];
        long maxRight[] = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            maxLeft[i] = Math.max(maxLeft[i - 1], left[i]);
            maxRight[i] = Math.max(maxRight[i - 1], right[i]);
        }

        long max = 0;
        for (int i = 1; i <= n; i++) {
            max = Math.max(max, left[i]);
            max = Math.max(max, left[i] - x[i] + maxRight[n - i]);
            max = Math.max(max, right[i]);
            max = Math.max(max, right[i] - c + x[n - i + 1] + maxLeft[n - i]);
        }

        System.out.println(max);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 92080
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    long long n; cin >> n;
    int y = sqrt(n);
    long long ans = 1L<<60;
    for(int i = 1; i <= sqrt(n); i++){
        if(n%i == 0) {
            if(i-1 + n/i-1 < ans) ans = i-1 + n/i-1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ll long long
        #define ld long double

        int main()
        {
            tani_nachi_ke  

            long long h,n;
            cin >> h >> n;
            long long sum = 0;
            for(int i = 0; i < n; i++)
            {
                long long x;
                cin >> x;
                sum += x;
            }
            if(sum >= h)
                cout << "Yes\n";
            else
                cout << "No\n";






           return 0;
        }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n; cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];

  sort(l.begin(), l.end());
  int res = 0;
  rep(i,n) {
    rep(j,n) {
      if(i >= j) continue;
      int sum = l[i] + l[j];
      int lb = j, ub = n;
      while(ub - lb > 1) {
	int mid = (ub + lb) / 2;
	(l[mid] < sum ? lb : ub) = mid;
      }
      res += lb - j;
    }
  }
  
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> pairint;

long long GCD(long long former, long long latter){
    if((former == 0)||(latter == 0))return former + latter;
    if(former % latter == 0)return latter;
    if(latter % former == 0)return former;
    return GCD(latter, former % latter);
}

int main(void){
    int N;
    string Abuf;
    vector<pairint> Asorted;
    long long res = 0;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        long long numerator = 0;
        long long denominator = 1;
        bool ifdecimal = false;
        for(char C: Abuf){
            if(C=='.'){
                ifdecimal = true;
            }else{
                int Cbuf = (int)(C - '0');
                numerator = numerator * 10 + Cbuf;
                if(ifdecimal){
                    denominator *= 10;
                }
            } 
        }
        long long reduction = GCD(numerator, denominator);
        numerator /= reduction;
        denominator /= reduction;
        int count2 = 0;
        int count5 = 0;
        while((numerator > 0) && (numerator % 2 == 0)){
            count2++;
            numerator /= 2;
        }
        while((numerator > 0) && (numerator % 5 == 0)){
            count5++;
            numerator /= 5;
        }
        while((denominator > 0) && (denominator % 2 == 0)){
            count2--;
            denominator /= 2;
        }
        while((denominator > 0) && (denominator % 5 == 0)){
            count5--;
            denominator /= 5;
        }
        Asorted.push_back(pairint(count2, count5));
    }
    sort(Asorted.begin(), Asorted.end());
    for(pairint pairAbuf: Asorted){
        for(int i=0-pairAbuf.first; i<30; i++){
            res += lower_bound(Asorted.begin(), Asorted.end(), pairint(i+1, -13)) - lower_bound(Asorted.begin(), Asorted.end(), pairint(i, 0-pairAbuf.second));
        }
        if((pairAbuf.first >= 0) && (pairAbuf.second >= 0))res--;
    }
    cout << res/2 << endl;
    return 0;
}

Measured memory_bytes: 5348
function Dice( faces ) {
  this.faces = faces;
  this.getFace = function ( id ) {
    return this.faces[id];
  }
  this.roll = function ( cmds ) {
    var t;
    for( var i=0; i<cmds.length; i++ ) {
      if( 'E' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.LEFT];
        this.faces[Dice.LEFT] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.RIGHT];
        this.faces[Dice.RIGHT] = t;
      } else if( 'S' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.BACK];
        this.faces[Dice.BACK] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.FRONT];
        this.faces[Dice.FRONT] = t;
      } else if( 'W' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.RIGHT];
        this.faces[Dice.RIGHT] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.LEFT];
        this.faces[Dice.LEFT] = t;
      } else if( 'N' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.FRONT];
        this.faces[Dice.FRONT] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.BACK];
        this.faces[Dice.BACK] = t;        
      }
    }
  }  
}
Dice.TOP = 0;
Dice.FRONT = 1;
Dice.RIGHT = 2;
Dice.LEFT = 3;
Dice.BACK = 4;
Dice.BOTTOM = 5;

var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  var faces = data[0].split( ' ' ).map( Number );
  var mydice = new Dice( faces ); 
  var cmds = data[1];
  mydice.roll( cmds );
  console.log( mydice.getFace( 0 ) );
});

Measured memory_bytes: 15620
N = int(input())
C = input()


def main():
    s = 0
    l = list(C)
    i, j = 0, N - 1
    while i != j:
        if l[i] == "R":
            i += 1
        else:
            if l[j] == "W":
                j -= 1
            else:
                l[i] = "R"
                l[j] = "W"
                i += 1
                s += 1
    
    ans = min(C.count("R"), s)
    print(ans)
                

if __name__ == "__main__":
    main()


Measured memory_bytes: 10600
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll dp[110000][4];

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

  dp[0][0] = 1;
  REP(i, S.size()) {
    for (int j = 0; j < 4; j++) {
      if (S[i] == '?') (dp[i + 1][j] = 3*dp[i][j])%=MOD;
      else (dp[i + 1][j] = dp[i][j])%=MOD;
    }

    if (S[i] == 'A' || S[i] == '?') (dp[i + 1][1] += dp[i][0])%=MOD;
    if (S[i] == 'B' || S[i] == '?') (dp[i + 1][2] += dp[i][1])%=MOD;
    if (S[i] == 'C' || S[i] == '?') (dp[i + 1][3] += dp[i][2])%=MOD;
  }

  cout << dp[S.size()][3] << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF 0xfffffffff
typedef long long ll;

using namespace std;

int n, w, wt[100], val[100];
ll dp[101][100001], ans;

int main()
{
  for(int i = 0; i<101; i++)
    for(int j = 0; j<100001; j++)
      dp[i][j] = -INF;
  cin >> n >> w;
  for(int i = 0; i<n; i++)
    cin >> wt[i] >> val[i];
  dp[0][0] = 0;
  for(int i = 0; i<n; i++)
    for(int j = 0; j<=w; j++)
    {
      dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
      if(j+wt[i]<=w)
        dp[i+1][j+wt[i]] = max(dp[i+1][j+wt[i]],dp[i][j]+val[i]);
      ans = max(ans,dp[i+1][j]);
    }
  cout << ans << endl;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main(){
    long s,t; cin>>s;
    long a[1000001]={0};
    a[s]=1;
    long i=2;
    while(1){
        if(s%2){
            s=s*3+1;
        }
        else{
            s/=2;
        }
        if(a[s]){
            cout<<i<<endl;
            return 0;
        }
        a[s]=1;
        i++;
    }
}

Measured memory_bytes: 8064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (int T = 1;; T++) {
			int W = sc.nextInt();
			if (W == 0)
				return;
			int N = sc.nextInt();
			int[] v = new int[N];
			int[] w = new int[N];
			for (int i = 0; i < N; i++) {
				String[] in = sc.next().split(",");
				v[i] = Integer.valueOf(in[0]);
				w[i] = Integer.valueOf(in[1]);
			}

			int maxCost = 0;
			int minWeight = Integer.MAX_VALUE / 2;
			int[][] dp = new int[N + 1][W + 1];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j <= W; j++) {
					if (j - w[i] >= 0) {
						dp[i + 1][j] = Math.max(dp[i][j], dp[i][j - w[i]]
								+ v[i]);
					} else {
						dp[i + 1][j] = dp[i][j];
					}
					if (dp[i + 1][j] == maxCost && j < minWeight) {
						minWeight = j;
					} else if (dp[i + 1][j] > maxCost) {
						maxCost = dp[i + 1][j];
						minWeight = j;
					}
				}
			}
			System.out.println("Case " + T + ":");
			System.out.println(maxCost + "\n" + minWeight);
		}
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 28704
def main():
    mod = 998244353
    a, b, c, d = map(int, input().split())
    dp = [[0]*(d+1) for _ in [0]*(c+1)]
    dp[a][b] = 1
    for i in range(a+b+1, c+d+1):
        for p in range(c, a-1, -1):
            q = i-p
            if q > d:
                break
            if q < 0:
                continue
            dp[p][q] = (q*dp[p-1][q]+p*dp[p][q-1] -
                        (p-1)*(q-1)*dp[p-1][q-1]) % mod
    print(dp[c][d])


main()


Measured memory_bytes: 138760
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int inf = 0x3f3f3f3f;
int rr[10];
int mp[205][205];
bool v[10];

int n,m,r;
int ans;

void dfs(int c,int las,int dis)
{
	if (c == r)
	{
		ans  = min(ans,dis);
		return;
	}

	for (int i = 0;i < 8;i++)
	{
		if (!v[i])
		{
			v[i] = 1;

			if (las == -1) dfs(c + 1,i,dis);
			else dfs(c+1,i,dis + mp[rr[las]][rr[i]]);

			v[i] = 0;
		}

	}
}

int main()
{

	ans = inf;

	memset(mp,inf,sizeof(mp));

	scanf("%d%d%d",&n,&m,&r);

	for (int i = 0;i < r;i++)
		scanf("%d",&rr[i]);

	for (int i = 0;i < m;i++)
	{
		int x,y,z;

		scanf("%d%d%d",&x,&y,&z);

		if (mp[x][y] > z)
			mp[x][y] = mp[y][x] = z;
	}

	for (int k = 1;k <= n;k++)
		for (int i = 1;i <= n;i++)
			for (int j = 1;j <= n;j++)
				mp[i][j] = min(mp[i][j],mp[i][k] + mp[k][j]);

	dfs(0,-1,0);

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

	return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
const int N = 1e5;


int find_par(int x, int *par){
	if(par[x] == x) return x;
	return par[x] = find_par(par[x],par);
}

int par[N+5];
int global_par[N+5];
vector<ipii> edge;

int n,q;
ll m;
int cnt[N+5];
int maksi[N+5];
bool pake[N+5];

int main(){
	memset(pake,0,sizeof(pake));
	scanf("%d%lld%d",&n,&m,&q);
	int unused = n;
	for(int i=1;i<=q;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a++;
		b++;
		if(!pake[a]){
			unused--;
			pake[a]=1;
		}
		if(!pake[b]){
			unused--;
			pake[b]=1;
		}
		edge.push_back(make_pair(c,make_pair(a,b)));
	}
	unique(edge.begin(),edge.end());
	sort(edge.begin(),edge.end());
	for(int i=1;i<=n;i++) par[i] = i,cnt[i]=1, global_par[i] = i;
	int valid = 1;
	int cnt2 = 0;
	ll gabung = n;
	
	for(int i=0;i<q;i++){
		if(edge[i].first == 0){
			int pa = find_par(edge[i].second.first,par);
			int pb = find_par(edge[i].second.second,par);
			if(pa != pb){
				par[pa] = pb;
				gabung--;
			}
		} else {
			if(m == n-1)valid = 0;
			int pa = find_par(edge[i].second.first,par);
			int pb = find_par(edge[i].second.second,par);
			if(pa == pb){
				valid = 0;
				break;
			}
			
		}
	}
	
	if(!valid){
		printf("No\n");
		return 0;
	}
	
	ll cnM = gabung * (gabung-3) / 2;
	if(m <= n+cnM) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 2804
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    
    public static void main(String[] args) throws IOException {
        
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        
       
        int n = sc.nextInt();
        long[]arr = new long[n];
        boolean set = false;
        for(int i = 0; i < n; ++i) {
         arr[i] = sc.nextLong();  
         if(arr[i] == 0) {
          set = true;   
         }
        }
        if(!set) {
            BigInteger b = new BigInteger("1");
            BigInteger fin = new BigInteger("" + (long)Math.pow(10, 18));
            boolean f = false;

            for(long x : arr) {
             b = b.multiply(new BigInteger(String.valueOf(x)));
             if(x == 0){
              b = new BigInteger("0");
              break;
             }
             if(b.compareTo(fin) == 1)
             {
                 f = true;
                 break;
             }

            }

            if(f)
                out.write("-1");
            else
                System.out.print(b.toString());
        }
        else
            out.write("0");
      
        
        out.flush();
    }
}

Measured memory_bytes: 51016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	int n, m, l;
	cin >> n >> m >> l;
	int ans = max({ n,m,l }) * 3 - (n + m + l);
	if (ans % 2 == 0)
		cout << ans/2 << endl;
        else
                cout << (ans+3)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int n, q;
  int data[101];

  while(cin >> n >> q){

    if(n == 0 && q == 0) break;

    for(int i = 0; i < 101; i++) data[i] = 0;

    for(int i = 0; i < n; i++){
      int num;
      cin >> num;
      for(int j = 0; j < num; j++){
	int in;
	cin >> in;
	data[in]++;
      }
    }
    int max = 0;
    int maxnum = 0;

    for(int i = 100; i > 0; i--){
      if(data[i] >= q && max <= data[i]){
	maxnum = i;
	max = data[i];
      }
    }

    cout << maxnum << endl;
  }

  return 0;
}

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

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

using namespace std;

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

    for (int i = 1; i <= n; i++) {
        if ((int)(i * 108 / 100) == n) {
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;
    return 0;
}


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;
    vector <long> x(n),y(n);
    rep(i,n){
        cin >> x[i];
        y[i]=x[i];
    } 

    vector <long> ans(n);

    sort(all(y));
    long smid=y[n/2-1];
    long bmid=y[n/2];

    for(int i=0; i<n; i++){
        if(x[i]<bmid){
            ans[i]=bmid;
        }
        else{
            ans[i]=smid;
        }
    }

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


Measured memory_bytes: 6912
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,x,y,a,b;
    cin>>n>>x;
    cout<<((n%x==0)?0:1);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int a,b,c,i;
int g = 1;
int z = 0;
scanf("%d %d",&a,&b);
c = b - a ; 
for(i = 0;i < c;i++){
z = z + g;
g += 1;
}
printf("%d",z - b );
}

Measured memory_bytes: 128
import sys
def input():
    return sys.stdin.readline()[:-1]

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
cnt = [0] * N

for i in range(Q):
    a = A[i]-1
    cnt[a] += 1
for i in range(N):
    tmp = K - (Q -cnt[i])
    if tmp > 0:
        print('Yes')
    else:
        print('No')

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

using namespace std;

int main()
{
    string s;
    int n,i,l;
    cin>>s>>n;
    l=s.length();
    for (i=0;i<l;i+=n){

        cout<<s[i];

    }
    cout<<endl;
    return 0;
}


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

int n,a[25];

ll get(int l,int r,ll L,ll R)
{
	if (l+1==r) return L*a[l]+R*a[r];
	ll ans=1e18;
	for (int i=l+1;i<r;i++)
		ans=min(get(l,i,L,L+R)+get(i,r,L+R,R)-a[i]*(L+R),ans);
	return ans;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	printf("%lld\n",get(1,n,1,1));
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a[5];
    ll mod[5];
    ll lst=INF;
    ll pin;
    ll ndt[5];
    rep(i,0,5)ndt[i]=0;
    rep(i,0,5){
        cin>>a[i];
        mod[i]=a[i]%10;
        if(lst>mod[i]&&mod[i]!=0){
            lst=mod[i];
            pin=i;
        }
        if(mod[i]==0){
            ndt[i]=a[i];
            continue;
        }
        ndt[i]=a[i]+10-(a[i]%10);
    }
    ll ans=0;
    if(lst==INF){
        rep(i,0,5)ans+=a[i];
        cout<<ans<<endl;
        return 0;
    }
    ndt[pin]=0;
    rep(i,0,5){
        ans+=ndt[i];
    }
    ans+=a[pin];
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
diff, total = 0, 0
for i in range(len(A) - 1):
  if diff < 0:
    A[i] += abs(diff)
  diff = A[i + 1] - A[i]
  if diff < 0:
    total += abs(diff)
print(total)

Measured memory_bytes: 32380
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    a=[[[0]*K*2 for _ in range(K*2)] for _ in range(2)]
    for _ in range(N):
        x,y,c=input().split()
        x,y=int(x)%(K*2),int(y)%(K*2)
        if c=='W':
            a[0][y][x]+=1
        else:
            a[1][y][x]+=1
    S=[[[0]*(K*2+1) for _ in range(K*2+1)] for _ in range(2)]
    for k in range(2):
        for i in range(K*2):
            for j in range(K*2):
                S[k][i+1][j+1]=S[k][i][j+1]+S[k][i+1][j]-S[k][i][j]+a[k][i][j]
    def getsum(k,y1,y2,x1,x2):
        return S[k][x2][y2]-S[k][x1][y2]-S[k][x2][y1]+S[k][x1][y1]
    ans=0
    for k in range(2):
        for i in range(K+1):
            for j in range(K+1):
                tmp=0
                tmp+=getsum(k,0,i,0,j)+getsum(k,i+K,K*2,0,j)+getsum(k,0,i,j+K,K*2)+getsum(k,i+K,K*2,j+K,K*2)+getsum(k,i,i+K,j,j+K)
                tmp+=getsum(not k,i,i+K,0,j)+getsum(not k,i,i+K,j+K,K*2)+getsum(not k,0,i,j,j+K)+getsum(not k,i+K,K*2,j,j+K)
                ans=max(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


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

int main(){
  int n, t;
  cin >> n >> t;
  vector<int> c;
  for(int i = 0; i<n; i++){
    int ci, ti;
    cin >> ci >> ti;
    if(ti > t) continue;
    c.push_back(ci);
  }
  
  if(c.size() == 0){
    cout << "TLE" << endl;
  } else {
    sort(c.begin(), c.end());
    cout << c[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	LL ans = 0;
	for(int i=0; i<=N; i++){
		for(int j=0; j<=N; j++){
			int now = R*i+G*j;
			now = N - now;
			if(now < 0) continue;
			if(now % B == 0) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
N = len(S) + 1
ans = [-1] * N
prev = '#'
cnt = 0
if S[0] == '<':
    ans[0] = 0
if S[-1] == '>':
    ans[-1] = 0
for i in range(N-2):
    if S[i] == '>' and S[i+1] == '<':
        ans[i+1] = 0
for i in range(N-1):
    if S[i] == '<':
        ans[i+1] = ans[i] + 1
for i in range(N-2, -1, -1):
    if S[i] == '>':
        ans[i] = max(ans[i+1] + 1, ans[i])
print(sum(ans))


Measured memory_bytes: 46420
import Data.List

main = do
  one <- getLine
  str <- getLine
  let x = read . head . words $ one :: Int
  putStrLn $ main' x str

main' :: Int -> String -> String
main' x cs
  | cs!!x == '-'
    && length (delete '-' cs) == length cs - 1
    && all (\x -> x `elem` ['0'..'9']) (delete '-' cs) = "Yes"
  | otherwise                                                 = "No"

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  string s;
  cin >> s;
  while (s.size() >= 2 && s.substr(0,2) == "hi") s.erase(s.begin(), s.begin()+2);

  if (s.empty()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }


}


Measured memory_bytes: 3656
N, K = gets.split.map &:to_i
dp = Array.new(K+1){0.0}

1.upto(N) do |i|
  dp[[i, K].min] += 1.0 / N.to_f
end

res = dp[K]
40.times do
  (K-1).downto(1) do |i|
    if 2*i < K
      dp[2*i] = dp[i] * 0.5
    else
      res += dp[i] * 0.5
    end
    dp[i] = 0.0
  end
end
p res


Measured memory_bytes: 2556
#17:16
n,q = map(int,input().split())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
ans = [0 for _ in range(n)]
for _ in range(q):
  p,x = map(int,input().split())
  p -= 1
  ans[p] += x
ect = [0 for _ in range(n)]
ect[0] = 1
now = [0]
while now != []:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if ect[y] == 0:
        ect[y] = 1
        now.append(y)
        ans[y] += ans[x]
print(' '.join(list(map(str,ans))))

Measured memory_bytes: 66832
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  int N;cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  
  int even=0;
  for(int i=0;i<N;i++){
    if(vec.at(i)%2==0){
      even++;
    }
  }
  
  int check=0;
  for(int i=0;i<N;i++){
    if(vec.at(i)%6==0||vec.at(i)%10==0){
      check++;
    }
  }
  
  if(even==check){
    cout<<"APPROVED"<<endl;
  }
  else{
    cout<<"DENIED"<<endl;
  }
}
  

  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


        public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int a, b;
    	String op;
    	while(scan.hasNext()){
        	a = scan.nextInt();
        	op = scan.next();
        	b = scan.nextInt();
    		switch(op){
    			case "+" :
    				System.out.println((a + b));
    				break;
    			case "-" :
    				System.out.println((a - b));
    				break;
    			case "*" :
    				System.out.println((a * b));
    				break;
    			case "/" :
    				System.out.println((a / b));
    				break;
    		}
    		if(op == "?")
    			break;
    	}
        scan.close();
    }
}

Measured memory_bytes: 26376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
string ans,s,t;
ll a,b;
ll c;
int main()
{
    
    cin>>a>>b;
    int p=__gcd(a,b);
    ll ans;
    ans=a*b/p;
    cout<<ans;
    return 0;
}

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

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

    string s;
    while(getline(cin, s), s != ".") {
        bool judge = true;
        stack< char > cor;
        for(int i = 0; i < s.size(); i++) {
            if(s[i] == '(' || s[i] == '[') cor.push(s[i]);
            if(s[i] == ')') {
                if(cor.empty()) judge = false;
                else if(cor.top() != '(') judge = false;
                else cor.pop();
            }
            if(s[i] == ']'){
                if(cor.empty()) judge = false;
                else if(cor.top() != '[') judge = false;
                else cor.pop();
            }
        }
        cout << (judge && cor.empty() ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
bool cmp(const pii& a, const pii& b)
{
    return a.fi < b.fi;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vpii a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i].fi, a[i].se = i;
    sort(rall(a), cmp);
    vvi dp(n + 1, vi(n + 1));
    int res = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            int pos = i + j;
            if (pos == n)
            {
                res = max(res, dp[i][j]);
                break;
            }
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + abs(a[pos].se - i) * a[pos].fi);
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + abs(a[pos].se - (n - 1 - j)) * a[pos].fi);
        }
    cout << res << endl;
    GAME_OVER;
}

Measured memory_bytes: 34620
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N, h[100];
	cin >> N;
	int s = 0;
	rep(i, N) {
		cin >> h[i];
		s += h[i];
	}
	int ans = 0;
	while (s) {
		bool flag = 0;
		int a, b;
		for (int i = 0; i < N; i++) {
			if (flag) {
				if (!h[i]) {
					b = i;
					flag = 0;
					for (int j = a; j < b; j++) {
						h[j]--;
						s--;
					}
					ans++;
				}
			}
			else {
				if (h[i]) {
					flag = 1;
					a = i;
				}
			}
		}
		if (flag) {
			b = N;
			flag = 0;
			for (int j = a; j < b; j++) {
				h[j]--;
				s--;
			}
			ans++;
		}
	}
	cout << ans << endl;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int rec(int i,int depth,vector<int>& a) {
    if (depth) {
        int x = rec(i*2,depth-1,a),y = rec(i*2+1,depth-1,a);
        if (x == y) return x;
        else return abs(x-y);
    } else return a[i];
}

int main() {
    int n;
    cin >> n;
    vector<int> a(1<<n);
    for (int i = 0;i < (1<<n);++i) cin >> a[i];
    cout << rec(0,n,a);
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

constexpr ll INF       = 1000000000;/* 1e+9a */

ll gcd(ll a, ll b){
    if(b == 0) return a;
    if(a < b) return gcd(b, a);
    return gcd(b, a % b);
}

void solve(istream& cin) {
    int N;
    while(cin >> N){
        ll ans = 1;
        for (int i = 0; i < N; ++i) {
            ll tmp;
            cin >> tmp;
            ans = tmp / gcd(ans, tmp) * ans;
        }// i
        cout << ans << endl;
    }
}

int main(int argc, char *argv[]) {
    string FileName("C"), Modifier("_MEPH");
    string ExecutionName = FileName + Modifier;
    string sub(argv[0]);
    // pass消去
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());

	// 数値計算もの用
    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {    
	    cerr << sub << endl;
        string inFile = "C_sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}


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

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

    unordered_map<int, bool> m;
    m[s] = true;

    int i = 2;
    while (1) {
        if (s % 2) {
            s = 3 * s + 1;
        } else {
            s = s / 2;
        }

        if (m.find(s) == m.end()) {
            m[s] = true;
        } else {
            cout << i << endl;
            return 0;
        }
        i++;
    }

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> P(N);
    for (int i = 0; i < N; i++){
        string s;
        int p;
        cin >> s >> p;
        P.at(i).first = make_pair(s, -p);
        P.at(i).second = i;  
    }
    sort(P.begin(), P.end());
    for (int i = 0; i < N; i++){
        cout << P.at(i).second + 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    static final long MOD=1000000007;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int tmp;
        int odd=0;
        int even=0;
        int even4=0;
        for(int i=0;i<n;i++){
            tmp=sc.nextInt();
            if(tmp%4==0){
                even4++;
            }else if(tmp%2==0){
                even++;
            }else{
                odd++;
            }
        }
        System.out.println((odd<=even4)||(even==0&&odd-1<=even4)?"Yes":"No");
    }
}

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

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

	int n = 0, m = 0;
	for (int i = N; 1 < i; i--) {
		n += i - 1;
	}
	for (int i = M; 1 < i; i--) {
		m += i - 1;
	}

	cout << n + m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
        a[i]--;
    }
    if(k<=n){
        ll next=0;
    //cout<<loops<<" "<<next<<endl;
        for(ll i=0; i<k; i++){
            next=a[next];
        }
        cout<<next+1<<endl;
        return 0;
    }
    vector<bool> visit(n,false);
    vector<ll> vcnt(n,0);
    ll v=0,loop;
    ll cnt=0;
    while(true){
        if(visit[v]){
            cnt++;
            loop=a[v];
            break;
        }
        visit[v]=true;
        vcnt[v]=cnt;
        v=a[v];
        cnt++;
    }
    k-=vcnt[loop];
    ll divs=cnt-vcnt[loop];
    ll loops=k%divs;
    ll next=loop;
    //cout<<loops<<" "<<next<<endl;
    for(ll i=0; i<loops; i++){
        next=a[next];
    }
    cout<<next+1LL<<endl;
}

Measured memory_bytes: 6400
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>

using namespace std;


int main(void) {
	int N, a[3000];
	int ans;

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}

	ans = 0;
	for (int i = 0; i < N; i++) {
		ans = ans + a[i] - 1;
	}

	printf("%d\n", ans);
}









Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> l(n);
    for (int i=0; i<n; i++) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    multiset<ll> se;
    se.insert(l.at(0) + l.at(1));
    ll cnt = 0;
    for (int i=2; i<n; i++) {
        auto iter = se.upper_bound(l.at(i));
        se.erase(se.begin(), iter);
        cnt += (ll)se.size();
        for (int j=0; j<i; j++) {
            se.insert(l.at(i) + l.at(j));
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 93952
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    ll i = 1;
    ll sum = 1;
    while (sum < N)
    {
        i++;
        sum += i;
    }
    rep(1, j, i + 1)
    {
        if (j == sum - N)
        {
            continue;
        }
        cout << j << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
K = int(input())
ResMin = float("inf")

for i in range(2**N):
    point = 1
    operate = [1] * N
    for j in range(N):
        if ((i >> j) & 1):
            operate[N - j - 1] = 2
    for k in operate:
        if k == 1:
            point *= 2
        else:
            point += K
    
    if point < ResMin:
        ResMin = point

print(ResMin)

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

int main() {

	int n; cin >> n;
	string s; cin >> s;

	long long rNum = 0;
	long long gNum = 0;
	long long bNum = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') rNum++;
		if (s[i] == 'G') gNum++;
		if (s[i] == 'B') bNum++;
	}

	long long ans = rNum * gNum * bNum;

	long long cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int k = 2 * j - i;
			if (s[i] == 'R' && s[j] == 'G' && s[k] == 'B') cnt++;
			if (s[i] == 'R' && s[j] == 'B' && s[k] == 'G') cnt++;
			if (s[i] == 'G' && s[j] == 'R' && s[k] == 'B') cnt++;
			if (s[i] == 'G' && s[j] == 'B' && s[k] == 'R') cnt++;
			if (s[i] == 'B' && s[j] == 'R' && s[k] == 'G') cnt++;
			if (s[i] == 'B' && s[j] == 'G' && s[k] == 'R') cnt++;
		}
	}
	
	ans -= cnt;

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define eb emplace_back
#define PF pop_front
#define PB pop_back
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof(a.begin()) it=a.begin(); it!=a.end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define INF 1e9
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
 
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;
 
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
 
int n, m, stx, sty, step[805][805], mx, res=2e9;
char grid[805][805];
queue<int> q;
 
inline bool out(int x, int y)
{
	return x<0||x==n||y<0||y==m;
}
 
void Init()
{
	cin>>n>>m>>mx;
	memset(step, -1, sizeof(step));
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
		{
			cin>>grid[i][j];
			if(grid[i][j]=='S')
				stx=i, sty=j;
		}
		
	q.push(stx), q.push(sty);
	
	step[stx][sty]=0;
	while(!q.empty())
	{
		int x=q.front();	q.pop();
		int y=q.front();	q.pop();
		if(step[x][y]==mx+1)
			break;
		for(int i=0; i<4; i++)
		{
			int xx=x+dx[i], yy=y+dy[i];
			if(!out(xx, yy)&&step[xx][yy]==-1&&grid[xx][yy]!='#')
			{
				step[xx][yy]=step[x][y]+1;
				q.push(xx);
				q.push(yy);
			}
		}
	}
	while(!q.empty())
		q.pop();
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			if(step[i][j]<=mx&&step[i][j]!=-1)
				q.push(i), q.push(j);
}
 
int main() 
{
	Init();
	while(!q.empty())
	{
		int x=q.front();	q.pop();
		int y=q.front();	q.pop();
		res=min(res, (min(min(n-x-1, x), min(y, m-y-1))+mx-1)/mx);
	}
	printf("%d", res+1);
	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 100000 + 10;
int a[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) a[i] = nextInt() - 1;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == i && i + 1 < N && a[i+1] == i+1) {
      ans++;
      i++;
    } else {
      if (a[i] == i) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



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

int main(){
	
	int ans = 0;
	string str;
	
	while( cin >> str ){
		if( cin.eof() ) break ;
		
		bool f = true;
		for( int i=0 ; i<str.size()/2 ; i++ ){
			if( !f ) break;
			f = ( str[i]==str[str.size()-i-1] );
		}
		if( f ) ans++ ;
	}
	
	cout << ans << endl ;
	
	return 0;
}

Measured memory_bytes: 1184
fn main() {
    use std::collections::VecDeque;
    let mut input = String::new();
    std::io::stdin().read_line(&mut input);
    let mut vec: Vec<i32> = Vec::with_capacity(2);
    vec = input
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<i32>>();
    println!("{}", (vec[0] + vec[1] -1) / vec[1] );
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  ll ans = n-2; ans *= ans;
  vector<int> v[] = {vector<int>(n+1,n),vector<int>(n+1,n)};
  int d[] = {n,n};
  rep(_,q){
    int x,a;
    cin >> x >> a;
    --x;
    if(a<d[x]){
      for(int i=a;i<d[x];++i){
        v[x][i] = d[!x];
      }
      d[x] = a;
    }
    ans -= v[x][a] - 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4776