akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#define PSIZE 1000000
char primes[PSIZE];

int main(){
  int i,j,n,m;

  primes[0]=1;
  primes[1]=1;
  n=sqrt(PSIZE);
  for(i=2;i<n;i++){
    if(!primes[i]){
      m=PSIZE/i+1;
      for(j=2;j<m;j++) primes[i*j]=1;
    }
  }
  while(scanf("%d",&n)!=EOF){
    n++;
    for(m=0,i=2;i<n;i++)
      if(!primes[i]) m++;
    printf("%d\n",m);
  }
  return 0;
}
      

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <iomanip>
#include <climits>
#include <cmath>
#define ll long long int
#define MOD 1000000007
#define IOS ios::sync_with_stdio(false)  ;cin.tie()  ; cout.tie()

using namespace std;



int main()
{
    IOS;
    ll n ;
    cin>>n ;
    map<ll , ll>mp ;

    for(ll i  = 0 ; i <  n ;++i)
    {
        ll v  ;
        cin>>v ;
        if(mp.find(v) == mp.end())
            mp[v]  =1  ;
        else
            mp[v]++ ;
    }
    ll first = -1 ;
    ll second = 0 ;
    for(auto z = mp.rbegin()  ; z != mp.rend()  ; ++z)
    {

        if((*z).second > 1)
        {
            if((*z).second >= 4)
            {

               if(first == -1)
               {

                   first =  (*z).first  ;
                   second  =(*z).first ;
                   break  ;
               }
               else
               {
                   second  =  (*z).first ;
                   break ;
               }


            }
            else{

             if(first == -1)
             {
                 first  = (*z).first ;
             }
             else
             {
                 second = (*z).first ;
                 break ;
             }
           }
        }


    }

     cout<<first*second<<"\n" ;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,k,a[N],b[N];
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    int ans=1e9,m1=1e9,m2=1e9;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),m1=min(m1,a[i]);
    for(int i=1;i<=m;i++) scanf("%d",&b[i]),m2=min(m2,b[i]);
    ans=m1+m2;
    for(int i=1;i<=k;i++)
    {
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        ans=min(ans,a[x]+b[y]-c);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        s: chars,
    }

    for i in 0..s.len() {
        for j in i..s.len() + 1 {
            let mut t = String::new();
            for k in 0..s.len() {
                if k < i || j <= k {
                    t.push(s[k]);
                }
            }

            // println!("{:?}", t);

            if t == "keyence" {
                println!("YES");
                return;
            }
        }
    }

    println!("NO");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  if (count(a.begin(), a.end(), a[0]) > 2) {
    cout << "Impossible\n";
    return 0;
  }
  map<int, int> m;
  rep(i, n) m[a[i]]++;
  if (count(a.begin(), a.end(), a[0]) == 1) {
    if (a[n - 1] != 2 * a[0]) {
      cout << "Impossible\n";
      return 0;
    }
    FOR(i, a[0] + 1, 2 * a[0] + 1) {
      if (m[i] < 2) {
        cout << "Impossible\n";
        return 0;
      }
    }
    cout << "Possible\n";
  }
  else {
    if (a[n - 1] != 2 * a[0] - 1) {
      cout << "Impossible\n";
      return 0;
    }
    FOR(i, a[0] + 1, 2 * a[0]) {
      if (m[i] < 2) {
        cout << "Impossible\n";
        return 0;
      }
    }
    cout << "Possible\n";
  }




  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 15001

/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_2_A&lang=jp

	巡回セールスマン問題。

	dp[V][0] = 0
	dp[S][v] = min {dp[S ∪ [u]][u] + d(v,u)| u ? S}

	参考：蟻本 p 174
*/
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_V = 15;

int V, E;
int d[MAX_V][MAX_V];
int dp[1<<MAX_V][MAX_V];	// メモ化テーブル
int s;				// スタート位置

// すでに訪れた頂点がS、現在位置が v
int dfs (int S, int v ){
	if (dp[S][v] >= 0 ) return dp[S][v];

	if (S == (1<<V)-1 && v == s ){
	// すべての頂点を訪れて戻って来た
		return dp[S][v] = 0;
	} // end if

	int res = INF;
	for (int u = 0; u < V; u++ ){
		if (!(S>>u & 1 ) ){
			// 次に u に移動する
			res = min (res, dfs (S | (1<<u), u ) + d[v][u] );
		} // end if
	} // end for

	return dp[S][v] = res;
}

int main()
{
	rep (i, MAX_V ) rep (j, MAX_V ) d[i][j] = INF;

	ios_base::sync_with_stdio(0);
	cin >> V >> E;
	rep (i, E ){
		int from, to, cost;
		cin >> from >> to >> cost;
		d[from][to] = cost;
	} // end rep

	int res = INF;
	rep (i, V ){
		memset (dp, -1, sizeof (dp ) );
		s = i;
		res = min (res, dfs (0, i ) );
	} // end rep
	cout << (res == INF ? -1 : res ) << endl;

	return 0;
}

Measured memory_bytes: 3124
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a;
P b[100010];
signed main() {
	cin >> n >> m;
	prique<int, vector<int>, greater<int>> que;
	rep(i, n) {
		cin >> a;
		que.push(a);
	}
	rep(i, m)cin >> b[i].second >> b[i].first;
	sort(b, b + m, greater<P>());
	rep(i, m) {
		bool f = false;
		while (b[i].second) {
			int t = que.top();
			if (t >= b[i].first) {
				f = true;
				break;
			}
			que.pop();
			que.push(b[i].first);
			b[i].second--;
		}
		if (f)break;
	}
	int ans = 0;
	while (!que.empty()) {
		int t = que.top();
		que.pop();
		ans += t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2676
/******

AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)

MOTTO : Use criticism as fuel and you will never run out of energy.
        AIM : TO BECOME A BETTER CODER
        INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
        Every moment is an opportunity to better yourself
        
*******/

#include<bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define pb push_back
#define mp make_pair
#define d(x) cout<<x<<"\n"

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

int powermod(int A, int p, int MOD = mod){
    A%=MOD;
    int res  = 1;
    while(p){
        if(p&1)
            res = ((__int128)res*A)%MOD;
        
        A = ((__int128)A*A)%MOD;
        p>>=1;
    }

    return res;
}*/

int32_t main(void)
{
    fastio
    int t=1;
    while(t--)
    {
        string x;
        cin>>x;
        int max_1=INT_MIN;
        int count=0;
        for(int i=0;i<x.size();i++)
        {
            if(x[i]=='R')
            count++;
            else
            {
                max_1=max(max_1,count);
                count=0;
            }
        }
        
        max_1=max(max_1,count);
        
        cout<<max_1<<"\n";
        
        
        
    }
    return 0;
}

Measured memory_bytes: 3576
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r<0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
N,P,*A = map(int, open(0).read().split())
B = list(map(lambda x:x%2, A))
n0 = B.count(0)
n1 = B.count(1)
ans = 0
if P==0:
  for i in range(0,n0+1):
    for j in range(0,n1+1,2):
      ans += cmb(n0,i)*cmb(n1,j)
else:
  for i in range(0,n0+1):
    for j in range(1,n1+1,2):
      ans += cmb(n0,i)*cmb(n1,j)
print(ans)

Measured memory_bytes: 3700
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (mapAccumL, sort)

main :: IO ()
main = do
  (n : d : a : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    walk :: [(Int, Int)] -> [(Int, Int)] -> [(Int, Int)]
    walk = fmap (snd .) $ flip $ mapAccumL step . (,) (0, 0)
      where
        step ((l, c), yks) (x, h) = (((succ (l - l'), c - c' + k'), yks'), (x, k'))
          where
            v = take l yks
            u = takeWhile ((< x - 2 * d) . fst) v
            (l', c') = lenSum u
            k' = (max 0 (h - (c - c') * a) + a - 1) `div` a
            yks' = drop l' yks
    
    lenSum :: [(Int, Int)] -> (Int, Int)
    lenSum = foldl step (0, 0)
      where
        step (l, s) (_, h) = (succ l, s + h)

    
  xhs <- sequence . replicate n $ unsafeListToTuple . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  print . sum . map snd . fix . walk . sort $ xhs

fix :: (a -> a) -> a
fix f = x
  where
    x = f x

unsafeListToTuple :: [Int] -> (Int, Int)
unsafeListToTuple (x : y : _) = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 119164
#include <stdio.h>

int main(){
    int x, y, i;
    for (i = 0; i < 3000; i++) {
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0 ) break;
        if (x > y) {
            printf("%d %d\n", y, x);
        }else{
            printf("%d %d\n", x, y);
        }
    }
    return 0;
}


Measured memory_bytes: 2732
# coding= utf-8
lol=input("")
S1=int(lol[0:1])
S2=int(lol[1:2])
S3=int(lol[2:3])
Ss=[S1,S2,S3]
cnt=0
Ss.sort()
while 1 in Ss:
  cnt += 1
  del Ss[-1]
else:
  print(cnt)

Measured memory_bytes: 9112
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0) 
#define inf                  (ll)1<<60
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={-2,-2,1,-1,-1,-1,1,1};
int dy[8]={1,-1,-2,-2,-1,1,-1,1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n;
    cin>>n;
    vector<vector<ll>> v(n,vector<ll> (3,0)),dp(n,vector<ll> (3,0));
    f(i,n)
    {
        f(j,3)
        {
            cin>>v[i][j];
        }
    }
    dp[0]=v[0];
    for(int i=1;i<n;i++)
    {
        f(j,3)
        {
            f(k,3)
            {
                if(j!=k)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][j]);
                }
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 11264
#include <stdio.h>

int main() {
	int multi, a, b;
	
	scanf("%d", &multi);
	scanf("%d %d", &a, &b);
	while(a <= b) {
		if(a%multi == 0) {
			printf("OK");
			return 0;
		}
		a++;
	}
	printf("NG");
	
	return 0;
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

int main(){
    int n,a,b;cin >> n >> a >> b;
    if(n*a >= b)cout << b << endl;
    else cout << n*a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  string S;
  cin >> S;
  ll N = S.size();
  ll qW[N+1]; // qW[i]: iまででWが何個あるか
  qW[0] = 0;
  for(int i=0; i<N; i++){
    if(S[i] == 'W') qW[i+1] = qW[i] + 1;
    else qW[i+1] = qW[i];
//    cout << qW[i+1] << endl;
  }
  ll ans = 0;
  for(int i=0; i<N; i++){
    if(S[i] == 'B') {
//      cout << i << endl;
      ans += (qW[N]-qW[i]);
    }
  }
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 2180
N, T = list(map(int, input().split()))

min_cost = 9999
for _ in range(N):
  c, t = list(map(int, input().split()))
  if t <= T and c < min_cost:
    min_cost = c
if min_cost == 9999:
  print('TLE')
else:
  print(min_cost)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
struct Node{
    int x,id;
    bool operator < (Node p){
        return x<p.x;
    }
}a[max_n],b[max_n];
int n;
int p[max_n];
bool vis[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].x),a[i].id=i;
    for(int i=1;i<=n;i++)scanf("%d",&b[i].x),b[i].id=i;
    sort(a+1,a+n+1);sort(b+1,b+n+1);
    for(int i=1;i<=n;i++)if(a[i].x>b[i].x)return printf("No\n"),0;
    for(int i=2;i<=n;i++){
        if(a[i].x<=b[i-1].x){
            return printf("Yes\n"),0;
        }
    }
    for(int i=1;i<=n;i++){
        int u=b[i].id,v=a[i].id;
        p[u]=v;
    }
    int cnt=0;
    int now=1;
    while(!vis[now]){
        vis[now]=true;
        cnt++;
        now=p[now];
    }
    if(cnt==n)printf("No\n");
    else printf("Yes\n");
    return 0;
}


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

//24??????????????????
int suf[24][4] =
{
	{ 0, 1, 2, 3 },
	{ 0, 1, 3, 2 },
	{ 0, 2, 1, 3 },
	{ 0, 2, 3, 1 },
	{ 0, 3, 1, 2 },
	{ 0, 3, 2, 1 },
	{ 1, 0, 2, 3 },
	{ 1, 0, 3, 2 },
	{ 1, 2, 0, 3 },
	{ 1, 2, 3, 0 },
	{ 1, 3, 0, 2 },
	{ 1, 3, 2, 0 },
	{ 2, 0, 1, 3 },
	{ 2, 0, 3, 1 },
	{ 2, 1, 0, 3 },
	{ 2, 1, 3, 0 },
	{ 2, 3, 0, 1 },
	{ 2, 3, 1, 0 },
	{ 3, 0, 1, 2 },
	{ 3, 0, 2, 1 },
	{ 3, 1, 0, 2 },
	{ 3, 1, 2, 0 },
	{ 3, 2, 0, 1 },
	{ 3, 2, 1, 0 }
};

string op = "+-*";

int cal(int a, int b, char op)
{
	switch (op)
	{
	case'+': return a + b;
	case'-': return a - b;
	case'*': return a * b;
	}
}

int main()
{
	int ary[4];
	while (true)
	{
		Break:

		for (int i = 0; i < 4; i++)
		{
			scanf("%d", &ary[i]);
		}
		if (ary[0] == 0) break;

		for (int i = 0; i < 24; i++)
		{
			for (int a = 0; a < 3; a++)
			{
				for (int b = 0; b < 3; b++)
				{
					for (int c = 0; c < 3; c++)
					{
						int n1 = ary[suf[i][0]];
						int n2 = ary[suf[i][1]];
						int n3 = ary[suf[i][2]];
						int n4 = ary[suf[i][3]];

						int ans = cal(cal(cal(n1, n2, op[a]), n3, op[b]), n4, op[c]);
						if (ans == 10)
						{
							printf("((%d%c%d)%c%d)%c%d\n", n1, op[a], n2, op[b], n3, op[c], n4);
							goto Break;
						}

						ans = cal(cal(n1, n2, op[a]), cal(n3, n4, op[c]), op[b]);
						if (ans == 10)
						{
							printf("(%d%c%d)%c(%d%c%d)\n", n1, op[a], n2, op[b], n3, op[c], n4);
							goto Break;
						}

						ans = cal(cal(n1, cal(n2, n3, op[b]), op[a]), n4, op[c]);
						if (ans == 10)
						{
							printf("(%d%c(%d%c%d))%c%d\n", n1, op[a], n2, op[b], n3, op[c], n4);
							goto Break;
						}

						ans = cal(n1, cal(cal(n2, n3, op[b]), n4, op[c]), op[a]);
						if (ans == 10)
						{
							printf("%d%c((%d%c%d)%c%d)\n", n1, op[a], n2, op[b], n3, op[c], n4);
							goto Break;
						}

						ans = cal(n1, cal(n2, cal(n3, n4, op[c]), op[b]), op[a]);
						if (ans == 10)
						{
							printf("%d%c(%d%c(%d%c%d))\n", n1, op[a], n2, op[b], n3, op[c], n4);
							goto Break;
						}
					}
				}
			}
		}

		printf("0\n");
	}

	return 0;
}

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

typedef long long ll;

using namespace std;


const ll N=100001;

int dp[667][2010];

const ll mod=1000000000+7;




int main(){

    int S;
    cin>>S;

    int p=S/3;

    for(int i=3;i<=S;++i){
        dp[1][i]=1;
        
    }
/*
    for(int i=0;i<=p;i++){
        for(int j=0;j<=S;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */

    for(int i=1;i<=p;i++){
        for(int j=3*i;j<=S;++j){
           for(int k=3;k<=S-j;++k){
               dp[i+1][j+k]=(dp[i+1][j+k]+dp[i][j])%mod;
           }
    
        }
        /*
        
        cout<<"========="<<endl;
         for(int i=0;i<=p;i++){
        for(int j=0;j<=S;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
        
    }
    */
    
    }

    ll ans=0;

    for(int i=1;i<=p;i++){

        ans=(ans+dp[i][S])%mod;
    }


cout<<ans<<endl;
    
}



Measured memory_bytes: 8180
n,m= map(int,raw_input().split())
box = [1 for _ in range(n+1)]
red = [0 for _ in range(n+1)]
red[1] = 1
for i in xrange(m):
    x,y = map(int,raw_input().split())
    box[x] -= 1
    box[y] += 1
    if red[x] == 1:
        red[y] = 1
    if box[x] == 0:
        red[x] = 0

# print box
# print red
print sum(red)

Measured memory_bytes: 7292
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
       printf("YES\n");
       else
        printf("NO\n");

    return 0;
}


Measured memory_bytes: 1612
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
//i日目で、雲がj番目で、最後に〇〇を訪れたのは〇日前
int memo[365][9][7][7][7][7];
int dx[4] = { 0,0,1,1 };
int dy[4] = { 0,1,0,1 };
void init() {
	rep(i, 365) {
		rep(j, 9) {
			rep(k, 7) {
				rep(l, 7) {
					rep(m,7) {
						rep(n,7) {
							memo[i][j][k][l][m][n] = 0;
						}
					}
				}
			}
		}
	}
}
bool check(int k, int a[16]) {
	int x = k / 3; int y = k % 3;
	rep(i, 4) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (a[nx*4+ny])return false;
	}
	return true;
}
int rained(int k) {
	if (k == 0)return 1;
	else if (k == 2)return 2;
	else if (k == 6)return 3;
	else if (k == 8)return 4;
	return 0;
}
bool validroute(int i, int j) {
	int x1 = i / 3; int x2 = j / 3;
	int y1 = i % 3; int y2 = j % 3;
	if (x1 == x2 || y1 == y2)return true;
	return false;
}
int main(){
	int n;
	while (cin >> n, n) {
		init();
		int a[16];
		rep(i, 16) {
			cin >> a[i];
		}
		bool pass = false;
		if (!check(4, a)) {
			cout << 0 << endl;
			pass = true;
		}
		memo[0][4][1][1][1][1] = 1;
		rep(i, n - 1) {
			rep(j, 16) {
				cin >> a[j];
			}
			if (pass)continue;
			rep(j, 9) {
				rep(k, 9) {
					if (!validroute(j, k))continue;
					if (!check(k, a))continue;
					rep(k1, 7) {
						rep(k2, 7) {
							rep(k3, 7) {
								rep(k4, 7) {
									if (!memo[i][j][k1][k2][k3][k4])continue;
									int nex[4] = { k1 + 1,k2 + 1,k3 + 1,k4 + 1 };
									int ch = rained(k);
									if (ch > 0) {
										nex[ch - 1] = 0;
									}
									bool cannex = true;
									rep(aa, 4) {
										if (nex[aa] == 7)cannex = false;
									}
									if (cannex) {
										memo[i+1][k][nex[0]][nex[1]][nex[2]][nex[3]] = 1;
									}
								}
							}
						}
					}
				}
			}
		}
		if (pass)continue;
		int ans = 0;
		rep(j, 9) {
			rep(k1, 7) {
				rep(k2, 7) {
					rep(k3, 7) {
						rep(k4, 7) {
							if (memo[n - 1][j][k1][k2][k3][k4])ans = 1;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 33900
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string x;
	cin >> x;
	stack<char> sta;

	REP(i, x.size()){
		if(x[i] == 'S') sta.push(x[i]);
		else{
			if(sta.empty() or sta.top() == 'T') sta.push(x[i]);
			else sta.pop();
		}
	}

	cout << sta.size() << endl;
	rtn 0;
}

Measured memory_bytes: 720
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <cassert>
using namespace std;

#define sz(a) int((a).size())
#define rep(i, s, n)  for(int i = s; i <= (n); ++i)
#define rev(i, n, s)  for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
typedef long long ll;
const int mod = 1000000007;
const int N = 3005;

int dp[N][N];
int n;

int go(int m, int r) {
  if(m == 0) {
    return 1;
  }
  int &res = dp[m][r];
  if(res == -1) {
    res = 0;
    if(r) {
      res += go(m - 1, r - 1);
      if(res >= mod) {
        res -= mod;
      }
      res += go(m - 1, r);
      if(res >= mod) {
        res -= mod;
      }
    }
    if(n - r) {
      res += go(m - 1, r);
      if(res >= mod) {
        res -= mod;
      }
      res += go(m - 1, r + 1);
      if(res >= mod) {
        res -= mod;
      }
    }
  }
  return res;
}

int main() {
#ifdef loc
  if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
    assert(0);
  }
  freopen((string(FOLDER) + "out.txt").c_str(), "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  int res = 0;
  rep(i, 0, n) {
    res += go(m, i);
    if(res >= mod) {
      res -= mod;
    }
  }
  n--;
  memset(dp, -1, sizeof(dp));
  rep(i, 0, n) {
    res -= go(m, i);
    if(res < 0) {
      res += mod;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 6010;

int N;
string S;
pair<vi,vi> oc;
string ans[MX];
int lst = -1;

pair<vi,vi> genOc(string tmp) {
    pair<vi,vi> z;
    F0R(i,sz(tmp)) {
        if (tmp[i] == 'a') z.f.pb(i);
        else z.s.pb(i);
    }
    return z;
}

string get(string tmp, bitset<MX> selec) {
    int a = -1, b = -1;
    string ans;
    F0R(i,sz(tmp)) {
        if (tmp[i] == 'a') {
            a ++;
            if (selec[a]) ans += 'a';
        } else {
            b ++;
            if (selec[b]) ans += 'b';
        }
    }
    return ans;
}

void solve(int x) {
    ans[x] = ans[x+1];
    bitset<MX> ok;
    FOR(i,x,N) ok[oc.f[i]] = ok[oc.s[i]] = 1;
    string tmp;
    F0R(i,2*N) if (ok[i]) tmp += S[i];
    
    pair<vi,vi> t = genOc(tmp);
    vi ab, ba;
    F0R(i,sz(t.f)) {
        if (t.f[i] < t.s[i]) ab.pb(i);
        else ba.pb(i);
    }
    
    pi nex = {0,0};
    bitset<MX> selec; selec[0] = 1;
    
    int cmx = 0;
    if (tmp[0] == 'a') nex.f ++;
    else nex.s ++;
    
    int lastB = t.s[0];
    while (nex.s < sz(ba)) {
        int cur = ba[nex.s];
        if (t.s[cur] < max(t.f[cmx],t.s[cmx])) {
            selec[cur] = 1;
            cmx = cur;
            nex.s ++;
            lastB = t.s[cur];
        } else break;
    }
    
    cmx ++;
    while (cmx < sz(t.f) && t.f[cmx] < t.s[cmx] && t.f[cmx] < lastB) cmx ++;
    ans[x] = max(ans[x],get(tmp,selec)+ans[x+cmx]);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> S;
    oc = genOc(S);
    F0Rd(i,N) solve(i);
    cout << ans[0];
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        //dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 1; i < n; i++) {
            for (int j = Math.max(i - k, 0); j <= i - 1; j++) {
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(h[i] - h[j]));
            }
        }
        System.out.println(dp[n - 1]);
    }

}


Measured memory_bytes: 59736
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef complex<double> P;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9, PI = acos(-1);

int n;
P p[20];
double r, t;
double dp[20][20][10010], d[20][20];
bool can[20][20][20];

int main(){
	cin >> n >> r >> t;
	t *= PI / 180;
	rep(i, n) cin >> p[i].real() >> p[i].imag();
	
	rep(i, n) rep(j, n) rep(k, n) if(i != j && j != k){
		double a = abs(arg((p[j] - p[i]) / (p[k] - p[j])));
		can[i][j][k] = a + EPS < t;
	}
	rep(i, n) rep(j, n) d[i][j] = abs(p[i] - p[j]);
	
	rep(i, n) rep(j, n) rep(k, 10010) dp[i][j][k] = INF;
	rep(i, n) if(i) dp[0][i][1] = d[0][i];
	
	int ans = 0;
	rep(k, 10010) rep(i, n) rep(j, n) if(dp[i][j][k] < r + EPS){
		ans = max(ans, k);
		rep(l, n) if(can[i][j][l]){
			dp[j][l][k + 1] = min(dp[j][l][k + 1], dp[i][j][k] + d[j][l]);
		}
	}
	cout << ans << endl;
	
	return 0;
}

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


int main(){
  int n,k,i;
  cin >> n >> k;
  vector<int> h(n);
  for(i=0;i<n;++i){
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  int ans=1000000000;
  for(i=0;i<=n-k;++i){
    int sa=abs(h[i]-h[i+k-1]);
    if(sa<ans){
      ans=sa;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

int obstacle_left[2000][2000];
int obstacle_right[2000][2000];
int obstacle_up[2000][2000];
int obstacle_down[2000][2000];

string S[2000];
int main(){
    int H;
    int W;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        cin >> S[i];
    }
    for(int i = 0; i < H; i++){
        obstacle_left[i][0] = -1;
        for(int j = 1; j < W; j++){
            if(S[i][j - 1] == '#'){
                obstacle_left[i][j] = j - 1;
            } else {
                obstacle_left[i][j] = obstacle_left[i][j - 1];
            }
        }
        obstacle_right[i][W - 1] = W;
        for(int j = W - 2; j >= 0; j--){
            if(S[i][j + 1] == '#'){
                obstacle_right[i][j] = j + 1;
            } else {
                obstacle_right[i][j] = obstacle_right[i][j + 1];
            }
        }
    }

    for(int i = 0; i < W; i++){
        obstacle_up[0][i] = -1;
        for(int j = 1; j < H; j++){
            if(S[j - 1][i] == '#'){
                obstacle_up[j][i] = j - 1;;
            } else {
                obstacle_up[j][i] = obstacle_up[j - 1][i];
            }
        }
        obstacle_down[H - 1][i] = H;
        for(int j = H - 2; j >= 0; j--){
            if(S[j + 1][i] == '#'){
                obstacle_down[j][i] = j + 1;
            } else {
                obstacle_down[j][i] = obstacle_down[j + 1][i];
            }
        }
    }

    /*
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << obstacle_left[i][j] << " ";
        }
        cout << endl;
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << obstacle_right[i][j] << " ";
        }
        cout << endl;
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << obstacle_up[i][j] << " ";
        }
        cout << endl;
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << obstacle_down[i][j] << " ";
        }
        cout << endl;
    }
    */
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] != '#'){
                ans = max(ans, obstacle_right[i][j] - obstacle_left[i][j] - 1 + obstacle_down[i][j] - obstacle_up[i][j] - 1 - 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 66816
package main

import (
	"fmt"
	"math"
)

// 以下の問題
// https://atcoder.jp/contests/abc110/tasks/abc110_a

func main() {
	var a, b, c float64
	fmt.Scan(&a, &b, &c)

	// A問題なのでsortを使わずにmath.Maxで解くのが正攻法だと思う
	fmt.Println(math.Max(10*a+b+c, math.Max(10*b+a+c, 10*c+a+b)))
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int V,E,r;
const int Inf = 10000*100000+100;
int C[100010];
int main(){
	while(cin >> V >> E >> r && V >0){
		vector< vector< pair<int,int> > > v(V+10);
		for(int i=0;i<E;i++){
			int s,t,d;
			cin >> s >> t >> d;
			v[s].push_back(make_pair(d,t));
		}
		priority_queue<pair <int,int> > P;
		P.push(make_pair(0,r));
		for(int i=0;i<V;i++){
			C[i] = Inf;
		}
		C[r] = 0;
		while(!P.empty()){
			pair<int,int> t = P.top();
			int s = t.second;
			P.pop();
			if(C[s] < t.first) continue;
			for(int i=0;i<v[s].size();i++){
				pair<int,int> e = v[s][i];
				if(C[e.second] > C[s] + e.first){
					C[e.second] = C[s] + e.first;
					P.push(make_pair(-C[e.second],e.second));
				}
			}
		}
		for(int i=0;i<V;i++){
			if(C[i] < Inf) cout << C[i] << endl;
			else cout << "INF" << endl;
		}
	}
}

Measured memory_bytes: 12928
/*input
3 1
10 20 10
*/
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define mpr make_pair
#define MX 1000000007
#define ui unsigned int
#define ll long long
#define ld long double
#define fi first
#define se second
#define testcases int testcases;cin>>testcases;while(testcases--)
#define printvector(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";  cout<<endl
#define printarray(v,n)  for(int i=0;i<n;i++) cout<<v[i]<<" ";  cout<<endl
#define inputarray(v,n)  for(int i=0;i<n;i++)cin>>v[i]
#define debug(i) cout<<"debug: "<<i<<endl
#define pr(i) cout<<i<<endl
#define timetaken cerr<<clock()/double(CLOCKS_PER_SEC)<<endl
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define toDigit(a) (a-'0')
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }



int cal(vector<int>&a, int n, int k){
    vector<int>dp(n+1,0);
    dp[1] = 0;
    for(int i=2;i<=n;++i){
        dp[i] = INT_MAX;
        for(int j=1;j<=min(i-1,k);++j){
            dp[i] = min(dp[i], dp[i-j] + abs(a[i-1]-a[i-j-1]));
        }
    }
    return dp[n];
}

int main() {
    fast_io;
    int n,k;
    cin>>n>>k;
    vector<int>a(n); inputarray(a,n);
    pr(cal(a,n,k));
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main() {
	int w, h, x, y, r;
	std::cin >> w >> h >> x >> y >> r;

	if ((x + r) > w || (y + r) > h || (x - r) < 0 || (y - r) < 0) {
		std::cout << "No" << std::endl;
	}
	else{
		std::cout << "Yes" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;




signed main(){
    cin >> n;
    vec(a,n);
    input(a,n);
    int ans = max_int;
    FOR(i,1,101){
        int tmp = 0;
        REP(j,n){
            tmp += pow(i-a[j],2);
        }
        ans = min(ans,tmp);
    }
    print(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct AntPos {
	int64_t pos;
	int     dir;
};


int main()
{
	int n; cin >> n;
	int64_t l, t; cin >> l >> t;

	vector<AntPos> ants(n);
	int cw_count = 0;
	int ucw_count = 0;
	for (auto & ant : ants) {
		cin >> ant.pos;
		cin >> ant.dir;

		if (ant.dir == 1) {
			cw_count++;
		}
		else {
			ucw_count++;
		}
	}


	// まずは蟻の個体を気にせず位置
	vector<int64_t> anspos(n);
	FOR_LT(i, 0, n) {
		anspos[i] = ants[i].pos + ((ants[i].dir == 1) ? t : -t);
		anspos[i] %= l;
		if (anspos[i] < 0) anspos[i] += l;
	}
	sort(anspos.begin(), anspos.end());

	// 0 番のアリの延長線上が何番かを特定
	int ti = 0;

	auto head = ants[0];
	if (head.dir == 1) {
		int64_t ccount = 0;
		// 1 周ごとに 2 回ずつあたる
		ccount = (t / l) * 2 * ucw_count;

		// 残りの衝突は 0, 1, 2
		int64_t rem = t % l;
		for (auto& ant : ants) {
			if (ant.dir == 1) continue;

			if (ant.pos - head.pos <= 2 * rem) ccount++;
			if (ant.pos - head.pos + l <= 2 * rem) ccount++;
		}

		ti += ccount % n;
	}
	else {
		int64_t ccount = 0;
		// 1 周ごとに 2 回ずつあたる
		ccount = (t / l) * 2 * cw_count;

		// 残りの衝突は 0, 1, 2
		int64_t rem = t % l;
		for (auto& ant : ants) {
			if (ant.dir == 2) continue;

			if (head.pos + l - ant.pos <= 2 * rem) ccount++;
			if (head.pos + l - ant.pos + l <= 2 * rem) ccount++;
		}

		ti += (n - ccount % n);
	}

	int64_t headpos = head.pos + ((head.dir == 1) ? t : -t);
	headpos %= l;
	if (headpos < 0) headpos += l;

	auto it = find(anspos.begin(), anspos.end(), headpos);
	assert(it != anspos.end());
	if (it + 1 != anspos.end() && *(it + 1) == headpos && head.dir == 1) {
		// 右回りで丁度衝突した場合
		it++;
	}

	vector<int64_t> ansantpos(n);

	FOR_LT(i, 0, n) {
		ansantpos[(ti + i) % n] = *it;
		it++;
		if (it == anspos.end()) it = anspos.begin();
	}

	for (auto& elem : ansantpos) {
		cout << elem << endl;
	}

	return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#define eps 1e-14
#define double long double
using namespace std;
struct point{
	double x,y;
	void read(){scanf("%Lf%Lf",&x,&y);}
	void write(){printf("%.10Lf %.10Lf\n",x,y);}
	point(double X=0.0,double Y=0.0):x(X),y(Y){}
	point operator +(const point a)const{return point(x+a.x,y+a.y);}
	point operator -(const point a)const{return point(x-a.x,y-a.y);}
	point operator *(double a)const{return point(x*a,y*a);}
	point operator /(double a)const{return point(x/a,y/a);}
	bool operator ==(const point a)const{return abs(x-a.x)<=eps && abs(y-a.y)<=eps;}
};
double dis(point a){return sqrt(a.x*a.x+a.y*a.y);}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
double cross3(point o,point a,point b){return cross(a-o,b-o);}
bool jiao(point a,point b,point c,point d)
{
	if(min(a.x,b.x)>max(c.x,d.x) || min(a.y,b.y)>max(c.y,d.y)) return false;
	if(min(c.x,d.x)>max(a.x,b.x) || min(c.y,d.y)>max(a.y,b.y)) return false;
	if(cross3(a,b,c)*cross3(a,b,d)>0) return false;
	if(cross3(c,d,a)*cross3(c,d,b)>0) return false;
	return true;
}
void make_rand(double &x){x=x+(1ll*rand()%10+1)/10.0*eps;}
struct Line{
	point a,b;
	void read(){a.read();b.read();}
	bool operator &&(const Line u){return jiao(a,b,u.a,u.b);}
	point operator &(const Line u)
	{
		if(a==u.a || a==u.b) return a;
		if(b==u.a || b==u.b) return b;
		double x1=a.x,x2=b.x,x3=u.a.x,x4=u.b.x;
		double y1=a.y,y2=b.y,y3=u.a.y,y4=u.b.y;
		if(x3==x4) return point(x3,(y2-y1)*x3/(x2-x1)+(y1*x2-x1*y2)/(x2-x1));
		if(x1==x2) return point(x1,(y4-y3)*x1/(x4-x3)+(y3*x4-x3*y4)/(x4-x3));
		make_rand(x2);
		double x=((y3*x4-y4*x3)*(x2-x1)-(y1*x2-y2*x1)*(x4-x3))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
		double y=(y2-y1)*x/(x2-x1)+(y1*x2-x1*y2)/(x2-x1);
		return point(x,y);
	}
};
int main()
{
	int n;
	scanf("%d",&n);
	
	srand(n);
	for(int i=1;i<=n;i++)
	{
		Line a,b;
		a.read();b.read();
		(a&b).write();
	}
	return 0;
}



Measured memory_bytes: 3220
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] num = new int[3];
		for(int i=0;i<3;i++){
			num[i] = sc.nextInt();
		}

		for(int i=0;i<3;i++){
			for(int j=i+1;j<3;j++){
				if(num[i]>num[j]){
					int tmp = num[i];
					num[i] = num[j];
					num[j] = tmp;
				}
			}
		}

		for(int i=0;i<3;i++){
			if(i!=2){
				System.out.print(num[i]+" ");
			}
			else{
				System.out.println(num[i]);
			}
		}

	}
}





Measured memory_bytes: 26160
import java.util.*;

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

class Solver {

    private void gen(int i, List<List<Integer>> res, List<Integer> cur, int N, int[] A) {
        if (cur.size() == N) {
            res.add(cur);
            return;
        }

        List<Integer> v1 = new ArrayList<Integer>(cur);
        v1.add(A[i] - 1);
        gen(i + 1, res, v1, N, A);

        List<Integer> v2 = new ArrayList<Integer>(cur);
        v2.add(A[i]);
        gen(i + 1, res, v2, N, A);

        List<Integer> v3 = new ArrayList<Integer>(cur);
        v3.add(A[i] + 1);
        gen(i + 1, res, v3, N, A);
    }


    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int cnt = 0;
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        gen(0, result, new ArrayList<Integer>(), N, A);
        for (List<Integer> l : result) {
            long sum = 1;
            for (Integer v :l)  {
                sum *= v;
            }
            if (sum % 2 == 0) cnt++;
        }
        System.out.println(cnt);

        return;
    }

}

Measured memory_bytes: 50824
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INARR(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int K, X;

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> K >> X;
	
}


void preprocess() {
	
	
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	for (int i = max(-1000000, X-K+1); i <= min(1000000, X+K-1); ++i) {
		cout << i << " ";
	}
	
	cout << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 256
from bisect import bisect_left

n, k = map(int,input().split())
a = list(map(int,input().split()))
assert len(a) == n
sa = sorted(a)
M = 10**9 + 7

inv_before = [0] * n
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            inv_before[j] += 1

inv_all = [0] * n
for i in range(n):
    inv_all[i] = bisect_left(sa, a[i])

def solve():
    ans = 0
    for i in range(n):
        ans += (k * inv_before[i]) % M
        ans %= M
        ans += (k * (k-1) // 2 * inv_all[i]) % M
        ans %= M
    return ans

print(solve())


Measured memory_bytes: 3188