akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    char c=getchar();bool f=0;x=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return x;
}
template<class t> inline void write(t x){
    if(x<0) putchar('-'),write(-x);
    else{if(x>9) write(x/10);putchar('0'+x%10);}
}


const double eps=1e-9;
const double pi=acos(-1);

struct point{
	double x,y;
	inline void read(){
		scanf("%lf%lf",&x,&y);
	}
	inline bool operator < (const point &nt) const {
		if(y==nt.y) return x<nt.x;
		return y<nt.y;
	}
	inline point operator + (const point &nt) const {
		return (point){x+nt.x,y+nt.y};
	}
	inline point operator - (const point &nt) const {
		return (point){x-nt.x,y-nt.y};
	}
	inline point operator * (const double &nt) const {
		return (point){x*nt,y*nt};
	}
	inline double length(){
		return sqrt(x*x+y*y);
	}
};

double distance(point x,point y){ //距离 
	return sqrt((y.x-x.x)*(y.x-x.x)+(y.y-x.y)*(y.y-x.y));
}

struct segment{
	point x,y;
	inline void read(){
		x.read();y.read();
	}
	inline double length(){ //线段长度 
		return distance(x,y);
	}
};

struct line{
	point x,y;
	inline void read(){
		x.read();y.read();
	}
};

segment linetoseg(line x){
	return (segment){x.x,x.y};
}

line segtoline(segment x){
	return (line){x.x,x.y};
}

double DJ(point x,point y){ //点积 
	return x.x*y.x+x.y*y.y;
}

double CJ(point x,point y){ //叉积 
	return x.x*y.y-x.y*y.x;
}

point trpoint(segment x){ //将有向线段转成向量点 
	return x.y-x.x;
}

point trpoint(line x){ //将直线转成向量点 
	return x.y-x.x;
}

double prolen(point x,segment a){ //点在有向线段上的投影长度 
	return DJ(trpoint((segment){a.x,x}),trpoint(a))/a.length();
}

point propoint(point x,segment a){ //点在直线(线段)上的投影点 
	return a.x+trpoint(a)*(prolen(x,a)/a.length());
}

point refpoint(point x,segment a){ //点对于直线(线段)的对称点 
	return x+(propoint(x,a)-x)*2;
}

bool orthline(line x,line y){ //两条直线是否垂直 
	return DJ(trpoint(x),trpoint(y))==0;
}

bool paraline(line x,line y){ //两条直线是否平行 
	return CJ(trpoint(x),trpoint(y))==0;
}

bool interseg(segment x,segment y){ //两条线段是否相交 
	return min(x.x.x,x.y.x)<=max(y.x.x,y.y.x)&&min(y.x.x,y.y.x)<=max(x.x.x,x.y.x)&&min(x.x.y,x.y.y)<=max(y.x.y,y.y.y)&&min(y.x.y,y.y.y)<=max(x.x.y,x.y.y)&&CJ(y.x-x.x,y.y-x.x)*CJ(y.x-x.y,y.y-x.y)<=0&&CJ(x.x-y.x,x.y-y.x)*CJ(x.x-y.y,x.y-y.y)<=0;
}

double dispointline(point x,line y){ //点到直线的距离 
	return distance(x,propoint(x,linetoseg(y)));
}

point crossline(line x,line y){ //两条直线的交点 
	double a=dispointline(x.x,y),b=dispointline(x.y,y);
	return x.x+(x.y-x.x)*(a/(a+b));
}

void doit(){
	line a,b;
	a.read();
	b.read();
	point ans=crossline(a,b);
	printf("%.10lf %.10lf\n",ans.x,ans.y);
}

signed main(){
	int t;
	read(t);
	while(t--) doit();
}


Measured memory_bytes: 3256
#include <iostream>
#include <cstdio>
#include <vector>

class Graph{
public:
	std::vector< std::vector<int> > A;
	std::vector<int> d, f;
	int n;

	Graph(int n);

	void DepthFirstSearch();
	int DepthFirstSearch_Rec(int id, int time);

};

Graph::Graph(int n){
	A.resize(n);
	d.resize(n);
	f.resize(n);
	for (int i = 0; i < n; i++){
		A[i].resize(n);
		for (int j = 0; j < n; j++){
			A[i][j] = 0;
		}
		d[i] = 0;
		f[i] = 0;
	}
	this->n = n;
}

void Graph::DepthFirstSearch(){
	int time = 0;
	for (int i = 0; i < n; i++){
		if (d[i] == 0) time = DepthFirstSearch_Rec(i, time + 1);
	}
	return;
}

int Graph::DepthFirstSearch_Rec(int id, int time){
	d[id] = time;
	for (int i = 0; i < n; i++){
		if (A[id][i] == 1 && d[i] == 0){
			time = DepthFirstSearch_Rec(i, time + 1);
		}
	}
	time++;
	f[id] = time;
	return time;
}

int main(){
	int n, u, k, v;
	scanf("%d", &n);
	Graph G(n);
	for (int i = 0; i < n; i++){
		scanf("%d%d", &u, &k);
		for (int j = 0; j < k; j++){
			scanf("%d", &v);
			G.A[u - 1][v - 1] = 1;
		}
	}

	G.DepthFirstSearch();

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


	return 0;
}


Measured memory_bytes: 3268
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	}
	

}


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

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

    int k, n; cin>>k>>n;
    int arr[n];
    for(int &i:arr) cin>>i;
    int ans=-1;
    for(int i=0; i<n-1; i++){
        ans=max(ans, arr[i+1]-arr[i]);
    }
    ans=max(k-(arr[n-1]-arr[0]), ans);
    cout<<k-ans;





}


Measured memory_bytes: 1024
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define                          ll                          long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

#define                          in(x)                       scanf("%lld",&x)
#define                          in2(x,y)                    scanf("%lld %lld",&x,&y)
#define                          in3(x,y,z)                  scanf("%lld %lld %lld",&x,&y,&z)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          inf                         1e18
#define                          neg                         -1e18
#define                          mx                          2111111
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define                          fi                          frist
#define                          si                          second
#define                          ce                          cout<<endl
#define                          pb                          push_back
#define                          vc(x)                       x.begin(),x.end()
#define                          pb                          push_back
#define                          pi                          pair<ll,ll>
#define                          debug                       printf("ok\n");
#define                          pg                          pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> >



int main(){

     ll a,b,i,n,j,ans=0,m,s=0,sum=0,x=0;
     in2(a,b);
     in(n);
    if(b*n>=a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}



Measured memory_bytes: 3756
import numpy as np
n, m, x, y = list(map(int, input().split()))
xl = [int(i) for i in input().split()]
yl = [int(i) for i in input().split()]

if x > y:
    print("War")
else:
    zl = np.arange(x+1, y+1)
    for z in zl:
        if (max(xl) < z) & (z <= min(yl)):
            print("No War")
            break
    else:
        print("War")

Measured memory_bytes: 12440
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define all(a)  (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int d,g; cin >> d >> g;
  vector<pii> pc(d);
  rep(i, d){
    int p, c; cin >> p >> c;
    pc[i] = make_pair(p, c);
  }

  int ans = 1e9;
  for (int bit = 0; bit < (1<<d); bit++) {
    vector<bool> used(d,false);
    int sum = 0;
    int cnt = 0;
    for (int i = 0; i < d; i++) {
      if(bit & (1<<i)){
        used[i] = true;
        sum += 100*(i+1)*pc[i].first + pc[i].second;
        cnt += pc[i].first;
      }
    }
    if(sum >= g) chmin(ans, cnt);
    else{
      for (int j = d-1; j >= 0; j--) {
        if(!used[j]){
          rep(k, pc[j].first){
            sum += 100*(j+1);
            cnt++;
            if(sum >= g){
              chmin(ans, cnt);
              break;
            }
          }
        }
      }
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
//'A' = 65, 'a' = 97

int main()
{
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    int ans = 0;
    int m = 1e9;
    for (int i = 0; i < n; i++) {
        int dif = abs(sum - n * a[i]);
        if (dif < m) {
            m = dif;
            ans = i;
        }
    }

    cout << ans << endl;

}


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

int main(){
  int i,j;
  int N,M;
  
  vector<string> list(0);
  
  cin >> N;
  vector<string> blue(N);
  for(i = 0 ; i < N ; i++)	cin >> blue.at(i);
  
  cin >> M;
  vector<string> red(M);
  for(i = 0 ; i < M ; i++)	cin >> red.at(i);
  
  for(i = 0 ; i < N ; i++){
    if(i == 0)	list.push_back(blue.at(i));
    else{
      for(j = 0 ; j < list.size() ; j++){
        if( blue.at(i) == list.at(j) )	break;
        if(j == list.size() - 1) list.push_back(blue.at(i));
      }
    }
  }
  
  vector<int> score(list.size());
  for(i = 0 ; i < list.size() ; i++){
    for(j = 0; j < N ; j++){
      if( list.at(i) == blue.at(j) )	score.at(i)++;
    }
  }
  
  for(i = 0 ; i < list.size() ; i++){
    for(j = 0 ; j < M ; j++){
      if( list.at(i) == red.at(j) )		score.at(i)--;
    }
  }
  
  int max = 0;
  for(i = 0 ; i < list.size() ; i++)	if( max < score.at(i) )	max = score.at(i);
  
  cout << max << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
 
public class Main {
 
        int INF = 1 << 28;
        int MAX = 10;
        int[][] map;
        int n, m;
        
        void run() {
                Scanner sc = new Scanner(System.in);
                for(;;) {
                        n = sc.nextInt();
                        if( n == 0) break;
                        
                        map = new int[MAX][MAX];
                        for(int[] a: map) fill(a, INF);
                        m = 0;
                        for(int i=0;i<n;i++) {
                                int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
                                m = max(m, max(a, b)+1);
                                map[a][b] = map[b][a] = min(c, map[a][b]);
                        }
 
                        int p=-1, min = INF;
                        for(int i=0;i<m;i++) {
                                int v = dijkstra(i);
                                if( min > v) {
                                        p = i;
                                        min = v;
                                }
                        }
                        
                        System.out.println(p + " " + min);
                }
        }
        
        int dijkstra(int s) {
                int[] d = new int[m];
                boolean[] visited = new boolean[m];
                fill(d, INF);
                d[s] = 0;
                
                for(;;) {
                        int v = -1;
                        for(int u=0;u<m;u++) if(!visited[u]) {
                                if(v == -1 || d[u] < d[v]) v = u;
                        }
                        
                        if( v == -1 ) break;
                        visited[v] = true;
                        
                        for(int u=0;u<m;u++) {
                                d[u] = min(d[u], d[v]+map[v][u]);
                        }
                }
                int ret = 0;
                for(int v: d) ret += v;
                return ret;
        }
 
        public static void main(String[] args) {
                new Main().run();
        }
 
        void debug(Object... os) {
                System.err.println(Arrays.deepToString(os));
        }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
int n; ll dp[1010][20010],mx[1010][20010],ans;
struct node { ll w,s,v; } d[1010];
bool cmp(node a,node b) { return a.s<b.s; }
void update(ll &x,ll y) { if (x<=y) x=y; }
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(d[i].w),read(d[i].s),d[i].s+=d[i].w,read(d[i].v);
	sort(d+1,d+n+1,cmp);
	for (int i=1;i<=n;i++) {
		for (int j=d[i].w;j<=d[i].s;j++)
			dp[i][j]=mx[i-1][j-d[i].w]+d[i].v;
		for (int j=0;j<=20000;j++) mx[i][j]=max(mx[i-1][j],dp[i][j]);
	}
	for (int j=0;j<=20000;j++) update(ans,mx[n][j]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 315648
#include <bits/stdc++.h>
using namespace std;
#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;i>=0;i--)
#define MAX 200004
#define B 100
#define dpb push_back
#define fi first
#define se second
typedef pair<int, int> P;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e16;
//__gcd(a,b), __builtin_popcount(a);

ll a[MAX], total;

int solve(ll m, int n){
	int r = 0, l1 = 1, l2 = 1;
	ll sum = 0, s1, s2, s3, t;
	a[0] = 0;
	
	while(r < n){
		/*s1 = *lower_bound(a, a+MAX, sum+m);
		if(s1 == INF){
			r++;sum += a[r];
			continue;
		}
		s2 = *lower_bound(a, a+MAX, s1+m);
		if(s2 == INF){
			r++;sum += a[r];
			continue;
		}
		t = *lower_bound(a, a+MAX, s2+m);
		if(m == 216)printf("%lld %lld %lld %lld\n", s1, s2, t, total+sum-s2);*/
		while(a[l1]-a[r] < m){
			if(a[l1] == INF)break;
			l1++;
		}
		while(a[l2]-a[l1] < m){
			if(a[l2] == INF)break;
			l2++;
		}
		//printf("%lld %lld\n", total-(a[l2]-a[r]), m);
		if(a[l1] == INF || a[l2] == INF)return 1;
		
		if(total-(a[l2]-a[r]) >= m){
			return 0;
		}else{
			r++;
			sum += a[r];
		}
	}
	
	return 1;
}

int main(){
	int n;
	scanf("%d", &n);
	fill(a, a+MAX, INF);
	rrep(i,n){
		scanf("%lld", &a[i]);
		a[n+i] = a[i];
	}
	for(int i = 2;i <= 2*n;i++){
		a[i] += a[i-1];
		//printf("%d ", a[i]);
	}
	total = a[n];
	//printf("\n");
	
	ll vl = 0, vr = INF;
	while(vr-vl > 1){
		ll mid = (vr+vl)/2;
		int f = solve(mid, n);
		if(f)vr = mid;
		else vl = mid;
	}
	printf("%lld\n", vl);
	//printf("%lld", total);
	return 0;
}

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

int main() {

int A,B,C,D,ans=0;
	cin>>A>>B>>C>>D;
for(int i=1; i<=A;i++){
  if(i>B){ans+=D;}
  else{ans+=C;}
}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int N ;
   cin >> N ;
   int d[N];
   for(int i=0;i<N;i++)cin >> d[i] ;

   int sum = 0 ;
   for(int i=0;i<N-1;i++){
       for(int j=i+1;j<N;j++){
     sum+=d[i]*d[j] ;
       }
   }  
  cout << sum << endl;
     
    return 0;
}


Measured memory_bytes: 256
import sys

N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]
sys.setrecursionlimit(N+M)

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i):
    if DP[i] != -1: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, 1 + From(node))
            DP[i] = maxLength
        return maxLength

Ans = 0
for i in range(N):
    Ans = max(Ans, From(i))
print(Ans)

Measured memory_bytes: 59056
#include<iostream>
#include<algorithm>
#include<map>
typedef long long lint;
using namespace std;

int main()
{
	int N;
	lint a;
	lint amax=0,amin=1e9+7;
	lint f=0,s=0;
	map<lint,int> m;
	lint ans=0;
	
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> a;
		amax=max(amax,a);
		amin=min(amin,a);
		m[a]++;
	}
	
	for(auto itr=m.rbegin();itr!=m.rend();++itr)
	{
		if(itr->second>=4)
		{
			ans=max(ans,(itr->first)*(itr->first));
			break;
		}
	}
	for(auto itr=m.rbegin();itr!=m.rend();++itr)
	{
		if(f!=0 && s!=0)break;
		if(itr->second>=2)
		{
			if(f==0)
			{
				f=itr->first;
				continue;
			}
			if(s==0)
			{
				s=itr->first;
				continue;
			}
		}
	}
	ans=max(ans,f*s);
	
	cout << ans << endl;
	return 0;
}


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

#define MAXN 50000
#define MAXM 20
#define INF 2000000000

int main() {
	int n, m;
	int C[MAXM], T[MAXN + 1];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> C[i];
	}
	for (int i = 0; i <= n; i++) {
		T[i] = INF;
	}
	T[0] = 0;
	for (int i = 0; i < m; i++) {
		for (int j = C[i]; j <= n; j++) {
			T[j] = min(T[j], T[j - C[i]] + 1);
		}
	}
	cout << T[n] << endl;
	return 0;
}



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

int main(){
  int A, B, C;
  string result;
  cin >> A >> B >> C;
  if(A + B + C == 17){
    if((A == 5)||(B == 5)||(C == 5)){
      if((A == 7)||(B == 7)||(C == 7)){
        result = "YES";
      }
    }
  } else {
    result = "NO";
  }
  cout << result << endl;
}
  
    

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

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

    if (D == 0) {
        if (N != 100) {
            cout << N << endl;
        }
        else {
            cout << "101" << endl;
        }
    }
    else if (D == 1) {
        if (N != 100) {
            cout << 100 * N << endl;
        }
        else {
            cout << "10100" << endl;
        }
    }
    else {
        if (N != 100) {
            cout << 10000 * N << endl;
        }
        else {
            cout << "1010000" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] == s[n-1] && n % 2 == 0) cout << "First" << endl;
    else if (s[0] != s[n-1] && n % 2 == 1) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}


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

int main()
{
	int a[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
	}
	sort(a, a+3);
	cout << a[2]-a[0] << endl;
	return 0;
}

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

struct Edge{
    int to; ll cost;
    Edge(int to,ll cost) : to(to), cost(cost){}
};

int n;
vector<Edge> G[101000];

int ans[101000];
int used[101000];

void dfs(int s,ll cost){
	if(used[s]) return ;

	used[s]=1;

	if(cost % 2 == 0) ans[s]=0;
	else ans[s]=1;

	for(auto p:G[s]){
		dfs(p.to, cost + p.cost);
	}
}

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		ll u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(Edge(v,w));
		G[v].push_back(Edge(u,w));
	}
	dfs(0,0);
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 9472
#include<cstdio>
#include<algorithm>
#define MN 510000
using namespace std;

int n,a[MN],r,l=r=250000;
int main(){
	scanf("%d",&n);r--;
	for (int i=1;i<=n;i++)
	if ((i&1)^(n&1)) scanf("%d",&a[++r]);else scanf("%d",&a[--l]);
	for (int i=l;i<=r;i++) printf("%d ",a[i]);
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 800005;
ll bit[MAX_N+1];
int nn = MAX_N; //　1-index

const ll MOD = 998244353;

void adds(int a, ll w){
    for(int x = a; x <= nn; x += x & -x){
        bit[x] += w;
        bit[x] %= MOD;
    } 
}
ll sums(int a){ // bit[1,a]の和を返す.
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x){
        ret += bit[x];
        ret %= MOD;
    }
    return ret;
}

int main() {
    int n, k;
    cin >> n >> k;
    int l[k], r[k];
    rep(i,k) cin >> l[i] >> r[i];

    adds(1,1);
    adds(2,-1);
    srep(i,1,n){
        ll x = sums(i);
        rep(j,k){
            adds(i+l[j], x);
            adds(i+r[j]+1, MOD-x);
        }
    }

    

    ll ans = sums(n) % MOD;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 6588
s=input()
t=list(map(int,input().split()))
i=0
j=0
l=int(s)
for i in range(l-2):
  list=[t[i],t[i+1],t[i+2]]
  if t[i+1]!=max(list) and t[i+1]!=min(list):
    j=j+1
print(j)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,q;
    cin>>n>>k>>q;
    int arr[n];
    for(int i=0;i<n;i++)
        arr[i]=k;
    for(int i=0;i<q;i++)
    {
        int ee;
         cin>>ee;
         arr[ee-1]+=1;
    }
    for(int i=0;i<n;i++)
    {
        int val=arr[i]-q;
        if(val <= 0)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;

    }
    return 0;
}


Measured memory_bytes: 1024
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var N = intShift();
  var D = intShift() - 1;
  var X = intShift();
  
  for(var i = 0; i < N ; i++){
  	X += Math.floor(D / intShift()) + 1;
  }
  
  return X
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
5
30 44
26
18
81
18
6
`);

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

int number(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  
  int total = 0;
  if (n==10 || n==100 || n==1000 || n==10000 ||n==100000)
    total = 10;
  else total = number(n);
  
  cout << total << endl;
  
}

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

typedef long long ll;

struct Edge {
    ll t,w;
};

struct State {
    ll v;
    ll score;
    bool operator < (const State& tgt) const {
	return score > tgt.score;
    }
};

vector<ll> dijkstra(vector<vector<Edge>>& G, const int start) {
    const ll V = G.size();

    vector<ll>res(V,INT_MAX);
    priority_queue<State> q;
    q.push( State{0,0} );
    while( q.size() ) {
	State s = q.top(); q.pop();
	if( res[s.v] != INT_MAX ) continue;
	res[s.v] = s.score;
	for(auto& e : G[s.v]) {
	    if( res[e.t] != INT_MAX ) continue;
	    q.push( State{e.t, s.score + e.w} );
	}
    }
    return res;
}


int main () {

    ll V; cin >> V;
    vector<vector<Edge>> G(V);
    for(int i=0; i<V; i++) {
	ll u,k; cin >> u >> k;
	for(int j=0; j<k; j++) {
	    ll v,w; cin >> v >> w;
	    G[i].push_back( Edge{v,w} );
	}
    }
    vector<ll> res = dijkstra(G,0);
    for(int i=0; i<V; i++) {
	cout << i << " " << res[i] << endl;
    }    
    return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
int main()
{
    int x1, x2, x3, x4, y1, y2, y3, y4;
    int wx, wy,  vx, vy;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    vx = x2 - x1;
    vy = y2 - y1;
    wx = - vy;
    wy = vx;
    x3 = x2 + wx;
    y3 = y2 + wy;
    x4 = x1 + wx;
    y4 = y1 + wy;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define F first
#define S second

int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll k;
	cin>>k;
	ll a[n+1];
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	vector<ll>next(n+1,-1);
	vector<ll>v;
	ll cur=1;
	while(next[cur]==-1){
		next[cur]=a[cur];
		cur=next[cur];
		v.PB(cur);
	}
	ll cyclebg=cur;
	ll len=1;
	vector<ll>cycle;
	cycle.PB(cyclebg);
	while(next[cur]!=cyclebg){
		cur=next[cur];
		cycle.PB(cur);
		len++;
	}
	ll done=v.size()-len;
	ll rem=(k-done)%len;
	if(k<=v.size()){
		cout<<v[k-1];
	}
	else{
		/*cur=cyclebg;
		while(rem>0){
			cur=next[cur];
			rem--;
		}
		cout<<cur;*/
		cout<<cycle[rem];
	}
	return 0;
}

Measured memory_bytes: 10756
s = [input() for _ in range(3)]

t = 0
while len(s[0]) >= 0 and len(s[1]) >= 0 and len(s[2]) >= 0:
    if len(s[t]) == 0:
        ans = t
        break
    if s[t][0] == "a":
        s[t] = s[t][1:]
        t = 0
    elif s[t][0] == "b":
        s[t] = s[t][1:]
        t = 1
    elif s[t][0] == "c":
        s[t] = s[t][1:]
        t = 2

if ans == 0:
    print("A")
elif ans == 1:
    print("B")
elif ans == 2:
    print("C")


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

int main(){
  int n;
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    int l,r;
    cin >> l >> r;
    cnt += r-l+1;
  }

cout << cnt << endl;

  
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int idx(char c) {
    switch (c) {
        case 'R': return 0;
        case 'G': return 1;
        default: return 2;
    }
    return -1;
}

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    auto MEMO = new int[][](N, 3);
    foreach (i, c; S) {
        if (i) foreach (j; 0..3) MEMO[i][j] += MEMO[i-1][j];
        MEMO[i][idx(c)] += 1;
    }
    long r;
    foreach (i; 1..N-1) {
        auto m = S[i];
        foreach (j; 0..i) {
            if (S[j] == m) continue;
            auto n = S[j];
            char l;
            if (m != 'R' && n != 'R') {
                l = 'R';
            } else if (m != 'G' && n != 'G') {
                l = 'G';
            } else {
                l = 'B';
            }
            r += MEMO[N-1][idx(l)] - MEMO[i][idx(l)];
            if (i + (i-j) < N && S[i + (i-j)] == l) r -= 1;
        }
    }
    writeln(r);
}

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

const int MOD = (int)1e9+7;

int main(){
	int N,K;
	cin >> N >> K;
	vector<int> h(N);
	for(int i=0;i<N;i++)	cin >> h.at(i);

	vector<int> dp(N,2e9);
	dp.at(0)=0;
	for(int i=0;i<N;i++){
		for(int j=1;j<=K;j++){
			if(i+j>=N)	break;
			dp.at(i+j)=min(dp.at(i+j),dp.at(i)+abs(h.at(i+j)-h.at(i)));
		}
	}

	cout << dp.at(N-1) << endl;
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int h[n];
    for(int x=0; x<n; x++) cin >> h[x];
    int ans=0;
    int save=0;
    for(int x=0; x<n-1; x++){
        if(h[x]>=h[x+1]) save++;
        else {
            if(save>=ans) ans=save;
            save=0;
        }
        if(save>=ans) ans=save;
    }

    cout << ans << endl;
}

Measured memory_bytes: 768
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn max (a: &i64, b:&i64) -> i64{
    if *a < *b {*b} else {*a}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        n: usize,
        v: [i64; n],
        c: [i64; n]
    }
    let mut sum = 0i64;
    for i in 0..n {
        if v[i] - c[i] > 0 {
            sum += v[i] - c[i];
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2156
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		Scanner sc=new Scanner(System.in);
		
		String[] buf=sc.nextLine().split(" ");
		int[] n=new int[3];
		n[0]=Integer.parseInt(buf[0]);
		n[1]=Integer.parseInt(buf[1]);
		n[2]=Integer.parseInt(buf[2]);
		Arrays.sort(n);
		System.out.println((n[2]-n[1])+(n[1]-n[0]));
		
			
	}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[]args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char c[] = sc.next().toCharArray();
		int pre[] = new int[n];
		int suf[] = new int[n];
		for (int i = 0 ; i < n ; ++i) {
			pre[i] += c[i] == 'W' ? 1 : 0;
			if (i > 0) {
				pre[i] += pre[i - 1];
			}
		}
		for (int i = n - 1 ; i >= 0 ; --i) {
			suf[i] = c[i] == 'E' ? 1 : 0;
			if (i + 1 < n) {
				suf[i] += suf[i + 1];
			}
		}
		int ans = 1 << 30;
		for (int i = 0 ; i < n ; ++i) {
			int before = 0;
			int after = 0;
			if (i - 1 >= 0) {
				before += pre[i - 1];
			}
			if (i + 1 < n) {
				after += suf[i + 1];
			}
			ans = Math.min(before + after,ans);
		}
		System.out.println(ans);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(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 {
			return Double.parseDouble(next());
		}

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

Measured memory_bytes: 29672
def main():
  n=[int(i) for i in list(input())]
  l=len(n)
  
  def abc_num(n,a,b,c):
    dp=[[0]*2 for i in range(l+1)]
    dp[0][0]=1
    for i in range(l):
      if n[i]<a:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][1]*3
      elif n[i]==a:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][1]*3
      elif n[i]<b:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]+dp[i][1]*3
      elif n[i]==b:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]+dp[i][1]*3
      elif n[i]<c:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*3
      elif n[i]==c:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*3
      else:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*3+dp[i][1]*3
    return sum(dp[-1])
    
        
  def ab_num(n,a,b):
    dp=[[0]*2 for i in range(l+1)]
    dp[0][0]=1
    for i in range(l):
      if n[i]<a:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][1]*2
      elif n[i]==a:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][1]*2
      elif n[i]<b:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]+dp[i][1]*2
      elif n[i]==b:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]+dp[i][1]*2
      else:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*2
    return sum(dp[-1])
  
  def a_num(x):
    x=int(''.join([str(i) for i in x]))
    three=int(''.join(['3']*l))
    five=int(''.join(['5']*l))
    seven=int(''.join(['7']*l))
    if x<three:
      return 0
    elif three<=x<five:
      return 1
    elif five<=x<seven:
      return 2
    else:
      return 3  

  ans=abc_num(n,3,5,7)
  ans-=(ab_num(n,3,5)+ab_num(n,3,7)+ab_num(n,5,7))
  ans+=a_num(n)
  for i in range(3,l):
    ans+=3**i-3*(2**i)+3
  print(ans)  
if __name__=='__main__':
  main()

Measured memory_bytes: 3380
#include<stdio.h>
int n,m;

int f(int depth, int sum, int s)
{
    if(depth == 10)
    {
        if(sum == n && s == m)return 1;
        return 0;
    }
    return f(depth+1,sum+1,s+depth) + f(depth+1,sum,s);
}
int main()
{
    while(scanf("%d%d",&n,&m),n+m)
    {
        printf("%d\n",f(0,0,0));
    }
    return 0;
}

Measured memory_bytes: 2560
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] L = new int[N];
        for (int n = 0; n < N; n++)
            L[n] = in.nextInt();

        int ans = 0;
        for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) for (int k = j + 1; k < N; k++) {
            if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i])
                continue;
            if (L[i] + L[j] <= L[k] || L[j] + L[k] <= L[i] || L[k] + L[i] <= L[j])
                continue;
            ans++;
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}


Measured memory_bytes: 33560
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

void run(void){
  int n;
  scanf("%d",&n);
  int *cnt=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    cnt[a]++;
  }
  const int mod=1000000007;
  int ans=1;
  for(i=n-1;i>0;i-=2){
    if(cnt[i]!=2){
      printf("0\n");
      return;
    }
    ans=ans*2%mod;
  }
  printf("%d\n",ans);
}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int N;
  cin >> N;
  vector<i64> D(N);
  rep(i,0,N -1) cin >> D[i];
  int M;
  cin >> M;
  vector<i64> T(M);
  rep(i,0,M - 1) cin >> T[i];
  map<i64,int> mp;
  rep(i,0,N - 1){
    mp[D[i]]++;
  }
  rep(i,0,M - 1){
    if(mp[T[i]] == 0){
      cout << "NO" << endl;
      return 0;
    }
    mp[T[i]]--;
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 15872
package main

import "fmt"

func main() {
	var k, s int
	fmt.Scan(&k, &s)

	var cnt int
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y
			if 0 <= z && z <= k {
				cnt++
			}
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
	int n,m,l,a[200][200],b[200][200];
	double c;
	
	scanf("%d %d %d",&n,&m,&l);
	
	int i,t,p;
	
	for(i=0;i<n;i++){
		
		for(t=0;t<m;t++){
			
			scanf("%d",&a[i][t]);
			//printf("%d\n",a[i][t]);
		}
	}
	for(i=0;i<m;i++){
		
		for(t=0;t<l;t++){
			
			scanf("%d",&b[i][t]);
			//printf("%d\n",b[m][l]);
		}
	}
	for(i=0;i<n;i++){
		
		for(t=0;t<l;t++){
			
			c=0;
			
			for(p=0;p<m;p++){
				
				c=c+a[i][p]*b[p][t];
				
			}
			printf("%.0lf",c);
			
			if(t==l-1){
				printf("\n");
			}
			else printf(" ");
		}
	}
	return 0;
}

Measured memory_bytes: 2780
class Binary_Indexed_Tree:
    def __init__(self, n):
        self.size = n
        self.tree = [0 for _ in range(n+1)]

    # a[i]にxを加算(1 <= i <= n) 1-indexed
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & (-i)

    # a[1] から a[t] までの合計を得る (1 <= t <= n)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i)

        return s

alpha_small_dict = {chr(i):i-97 for i in range(97, 97+26)} #辞書ver
n = int(input())
S = input()
data = [[0 for i in range(n)] for j in range(26)]

bit = [Binary_Indexed_Tree(n) for i in range(26)]
for i,x in enumerate(S):
    bit[alpha_small_dict[x]].add(i+1,1)
    data[alpha_small_dict[x]][i] = 1
q = int(input())
for i in range(q):
    x,y,z = input().split()
    x,y = int(x),int(y)
    #print(x,y,z)
    if x == 1:
        num = alpha_small_dict[z]
        for j in range(26):
            if data[j][y-1] == 1:
                data[j][y-1] = 0
                bit[j].add(y,-1)
                break
        data[num][y-1] = 1
        bit[num].add(y,1)
    else:
        z = int(z)
        ans = 0
        for j in range(26):
            if bit[j].sum(z)-bit[j].sum(y-1) >= 1:
                ans += 1
        print(ans)

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

const int mod = 1e9 + 7;

void add_self(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}

void sub_self(int &x, int y) {
  x -= y;
  if (x < 0)
    x += mod;
}

int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}

int sub(int x, int y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;
}

int powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for( ; b; b >>= 1){
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res % mod;
}

int mult(int x, int y) {
  return (1LL * x * y) % mod;
}

int divide(int x, int y) {
  return mult(x, powmod(y, mod - 2));
}

const int N = 3010;
const int INV2 = divide(1, 2);

int n, qq;
int a[N], dp[N][N];

int main() {
  scanf("%d %d", &n, &qq);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      dp[i][j] = (a[i] > a[j]);
  for (int i = 0; i < qq; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x, --y;
    dp[x][y] = dp[y][x] = mult(add(dp[x][y], dp[y][x]), INV2);
    for (int j = 0; j < n; ++j) {
      if (j != x && j != y) {
        dp[j][x] = dp[j][y] = mult(add(dp[j][x], dp[j][y]), INV2);
        dp[x][j] = dp[y][j] = mult(add(dp[x][j], dp[y][j]), INV2);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      add_self(ans, dp[i][j]);
  for (int i = 0; i < qq; ++i)
    add_self(ans, ans);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
signed main(){
    string s;
    cin>>s;
    long long sum=0;
    for(int i=0;i<s.size();i++){
        sum+=s[i]-'0';
    }
    if(sum%9==0){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return(0);
}

Measured memory_bytes: 3692
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct segment { int s, t, x; };
struct person { int i, d, result; };

const int S = 0, D = 2, T = 1;
struct event { int tpe, index, time; };

int main() {
  int n, q;
  while (cin >> n >> q) {
    vector<segment> v(n);
    REP(i,n) cin >> v[i].s >> v[i].t >> v[i].x;
    REP(i,n) { v[i].s -= v[i].x; v[i].t -= v[i].x; }

    vector<person> p(q);
    REP(i,q) {
      cin >> p[i].d;
      p[i].i = i;
      p[i].result = -1;
    }

    vector<event> events;
    REP(i,n) {
      events.push_back((event) { S, i, v[i].s });
      events.push_back((event) { T, i, v[i].t });
    }
    REP(i,q) {
      events.push_back((event) { D, i, p[i].d });
    }

    sort(ALL(events), [](const event& a, const event &b){
                        if (a.time != b.time) return a.time < b.time;
                        return a.tpe < b.tpe;
                      });

    multiset<int> xs;
    for (const auto& e: events) {
      // cout << "Event " << "SDT"[e.tpe] << ' ' << e.index << ' ' << e.time << endl;
      if (e.tpe == S) {
        xs.insert(v[e.index].x);
      } else if (e.tpe == T) {
        xs.erase(xs.find(v[e.index].x));
      } else {
        if (xs.empty()) continue;
        int result = *xs.begin();
        if (p[e.index].result != -1) ls(p[e.index].result, result);
        else p[e.index].result = result;
      }
      // cout << "xs = "; pp(xs); cout << endl;

    }

    REP(i,q) cout << p[i].result << endl;
  }
}


Measured memory_bytes: 24040
#include <iostream>
#include <cmath>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;

map<string, int> vote;
int N;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    vote[str]++;
  }
  int m = 0;
  map<string, int>::iterator itr;
  for (itr = vote.begin(); itr != vote.end(); itr++) {
    if (m < itr->second) {
      m = itr->second;
    }
  }
  for (itr = vote.begin(); itr != vote.end(); itr++) {
    if (itr->second == m) {
      cout << itr->first << endl;
    }
  }
  return 0;
}


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

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

#define FOR(i,n,m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i,n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin>>S;
    string ans="First";
    if(S[0]==S[S.length()-1])
    {
        if(S.length()%2==1)
        {
            ans="Second";
        }
    }
    else
    {
        if(S.length()%2==0)
        {
            ans="Second";
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {

	int n, k;

	cin >> n >> k;

	if (n%k == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

int main(){
    ll H, W; std::cin >> H >> W;
    std::vector<std::string> a;
    for(int i=0; i<H; ++i){
        std::string b; std::cin >> b; a.push_back(b);
    }

    std::vector<bool> row(H,false);
    std::vector<bool> col(W,false);
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            if(a[i][j]=='#'){
                row[i]=true;
                col[j]=true;
            }
        }
    }

    for(int i=0; i<H; ++i){
        if(row[i]){
            for(int j=0; j<W; ++j){
                if(col[j]){
                    std::cout << a[i][j];
                }
            }
            std::cout << '\n';
        }
    }

    return 0;
}


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

#define ALL(a) a.begin(),a.end()
using ll=long long;

int main(){
    string a;
    cin>>a;
    const int alpha='z'-'a'+1;
    vector<int> cnt(alpha,0);
    ll res=1;
    for(int i=0;i<a.size();i++){
        res+=(i-cnt[a[i]-'a']);
        cnt[a[i]-'a']++;
    }    
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else if(c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;

}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int ans=1;
  int distance=0;
  for(int i=0;i<n;i++){
    int d;
    cin>>d;
    distance+=d;
    if(distance<=x)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256