akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int gcd(int x, int y);
int lcm(int x, int y, int g);
int main(){
    int g,l,x,y;
    while (scanf("%d%d",&x,&y) != EOF){
        g=gcd(x,y);
        l=lcm(x,y,g);
        printf("%d %d\n",g,l);
    }
    return 0;
}
int gcd(int x, int y){
    int a,b,c,GCD;
    if(x > y){
        a=x;
        b=y;
        for(;;){
            c = a % b;
            if(a % b == 0){
                GCD=b;
                break;
            }
            a=b;
            b=c;
        }
    }
    else if(x < y){
        a=y;
        b=x;
        for(;;){
            c = a % b;
            if(a % b == 0){
                GCD=b;
                break;
            }
            a=b;
            b=c;
        }
    }
    else if(x == y) GCD=x;
        return GCD;
}
int lcm(int x, int y, int g){
    return (x/g)*(y/g)*g;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    for(int i=0 ; i<10 ; i++){
      if(i==3){
        System.out.print(8);
      }else{
        System.out.print(s.charAt(i));
      }
    }
    System.out.println();
  }
}


Measured memory_bytes: 23892
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long K = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        sc.close();

        long ans = 0;
        if (B - A > 2) {
            K -= (A - 1);
            ans = A;
            ans += (B - A) * (K / 2);
            if (K % 2 != 0) ans++;
        } else {
            ans = K + 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val H = sc.nextInt(); val W = sc.nextInt()
  val h = sc.nextInt(); val w = sc.nextInt()

  if(H % h != 0) {
    println("Yes")
    for (y <- 1 to H) {
      val now = if(y % h == 0) -500 * (h-1) - 1 else 500
      for (x <- 1 to W)
        if (x != W) print(s"$now ")
        else println(now)
    }
  }
  else if (W % w != 0) {
    println("Yes")
    val ar = new Array[Int](W+1)
    for(i <- 1 to W){
      if (i % w == 0)
        ar(i) = -500 * (w-1) - 1
      else
        ar(i) = 500
    }
    for(_ <- 1 to H) {
      ar.slice(1, W).foreach{x => print(x + " ")}
      println(ar(W))
    }
  }
  else {
    println("No")
  }
}


Measured memory_bytes: 62248
#include<stdio.h>

int main(){
	int N;

	scanf("%d",&N);

	int a[N];

	int temp;
	long sum = 0;
	int i;
	for(i=0;i<N;i++){
		temp = i+1;
		if(temp % 3 == 0){
			temp = 0;
		}else if(temp % 5 == 0){
			temp = 0;
		}

		a[i] = temp;

		sum = sum + a[i];

	}

	printf("%ld",sum);


	return 0;
}


Measured memory_bytes: 5576
import java.util.*;

public class Main {
	public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		
        int k =D*2+1;
        
        if(N%k==0){
        System.out.print(N/k);
        }else{
        System.out.print(N/k+1);    
        }
}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define lli long long int 
using namespace std;
int main(){
    int h,n,count=0;
    cin >> h >> n;
    lli a[n];
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    for(int i=0;i<n;++i){
        h-=a[i];
        if(h<=0){
            break;
        }
    }
    if(h<=0){
    cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public string S;
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            S = Console.ReadLine();

            char last = '.';
            long BC = 0;
            long ret = 0;
            N = S.Length;

            // ABCACCBABCBCAABCB

            // ABCACCB ABCBCAABC B

            for (int i = N - 1; i >= 0; i--)
            {
                char curr = S[i];

                if (curr == 'B' && last == 'C')
                    BC++;
                else if (curr == 'A' && last == 'C')
                    BC = 0;
                else if (curr == 'B' && last == 'A')
                    BC = 0;
                else if (curr == 'B' && last == 'B')
                    BC = 0;
                // else if (curr == 'C' && last == 'B')
                //     BC = 0;
                else if (curr == 'C' && last == 'C')
                    BC = 0;

                if (curr == 'A') ret += BC;

                // AA
                // CA

                last = curr;
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11616
#include <stdio.h>


int n, cnt;
int A[1000000];



void shellSort(); 
void insertionSort(int);


int main() {
  
  int i;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%d", A+i);
  }

  shellSort();

  return 0;

}




void insertionSort(int g) {
  
  int v;
  int i, j;

  for(i = g; i < n; i++) {

    v = A[i];
    j = i-g;

    while(j >= 0 && A[j] > v) {

      A[j+g] = A[j];
      j -= g;
      cnt++;

    }
    
    A[j+g] = v;

  }
}
void shellSort() {
  
  int G[100];
  int m = 0, g = 0;
  int i;
  
  while(3 * g + 1 <= n) {

    g = 3 * g + 1;
    G[m++] = g;

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

  for(i = m - 1; i >= 0; i--) {

    if(i < m - 1) printf(" ");
    printf("%d", G[i]);
    insertionSort(G[i]);

  }

  puts("");
  printf("%d\n", cnt);

  for(i = 0; i < n; i++){
    
    printf("%d\n", A[i]);

  }
}

Measured memory_bytes: 4520
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll x,n; cin>>x>>n;
    vector<ll>p(n);
    vector<bool>b(10000,true);
    rep(i,n){
        cin>>p[i];
        b[p[i]]=false;
    }
    if(b[x]){
        cout<<x<<endl;
        return 0;
    }
    
    ll bb=x+1;
    ll c=x-1;
    while(1){
        if(b[c]){
            cout<<c<<endl;
            return 0;
        }
        else if(b[bb]){
            cout<<bb<<endl;
            return 0;
        }
        c--; bb++;
    }
}








Measured memory_bytes: 3632
N, P = map(int, input().split())
def fact(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append((i, cnt))

    if temp!=1:
        arr.append((temp, 1))

    if arr==[]:
        arr.append((n, 1))

    return arr
ans =1
for yakusu, kosu in fact(P):
  ans *= yakusu**(kosu//N)
print(ans)

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

class Proc{
	string name;
	int time;
public:
	Proc(string n, int t) : name(n), time(t){}
	Proc() : name(""), time(0){}
	int execute(int q){return time -= q;};
	string get_name(){return name;};
	int get_time(){return time;};
};
int main(){
	int n, q;
	cin >> n >> q;
	Proc queue[n];
	string name;
	int time;
	for (int i = 0; i < n; i ++){
		cin >> name >> time;
		queue[i] = Proc(name, time);
	}
	int i = 0, last = 0, now_time = 0, size = n, temp = 0;
	while (size > 0){
		now_time += q;
		temp = queue[i].execute(q);
		if (temp <= 0){
			now_time += temp;
			cout << queue[i].get_name() << " " << now_time << "\n";
			size -= 1;
			i = (i + 1) % n;
		}else{
			queue[last] = queue[i];
			i = (i + 1) % n;
			last = (last + 1) % n;
		}
	}
}


Measured memory_bytes: 6196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i < n-i) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main()
{
    char a[5];
    int i;
    scanf("%s",&a);
    for(i=1;i<4;i++)
        if(a[i]==a[i-1])
    {
        printf("Bad");
        return 0;
    }
    printf("Good");
}


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


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

  for(int i=0;i<s.size()-2;++i){
    for(int al='a';al<='z';++al){
      int cnt=0;
      for(int j=0;j<3;++j){
        if(s[i+j]==al)cnt++;
      }
      if(cnt>=2){
        cout << i+1 << " " << i+3 << endl;
        return 0;
      }
    }
  }
  cout << "-1" << " " << "-1" << endl;
  return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
char s[200005];
int modulo(int a, int b) {
    if (b == 0)
        return 1;
    const int m = 2019;
    ll x = 1, y = a;
    while (b > 0) {
        if (b % 2 == 1)
            x = x * y % m;
        y = y * y % m;
        b /= 2;
    }
    return x % m;
}
int main() {
    scanf("%s", s);
    int n = strlen(s);
    if (n < 5) {
        puts("0");
        return 0;
    }
    unordered_map<int, int> m;
    int sum = 0;
    ll cnt = 0;
    m[0] = 1;
    for (int i = n - 1; i >= 0; i--) {
        sum = (sum + (s[i] - '0') * modulo(10, n - 1 - i)) % 2019;
        if (m.find(sum) != m.end())
            cnt += m[sum];
        m[sum]++;
    }
    printf("%lld\n", cnt);
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
bool a[205][205],b[205][205];
int has[205],n,ans,x,y; 
int main()
{
   ios::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>x>>y,a[x][y]=1;
	for(int i=0;i<n;i++)cin>>x>>y,b[x][y]=1;
	for(int i=0;i<n+n;i++)
	{
		for(int j=0;j<n+n;j++)
	    if(b[i][j])
		{
			int k=j-1;
			while(k>=0&&!has[k])k--;
			if(k>=0)has[k]--,ans++;
		}
		for(int j=0;j<n+n;j++)
		if(a[i][j])
		has[j]++;
	}
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int K; cin >> K;
	map<string, int>mp;
	mp["tameru"] = 0;
	mp["kougekida"] = 1;
	mp["mamoru"] = 2;
	vector<int>as, bs;
	for (int i = 0; i < K; ++i) {
		string st; cin >> st;
		as.push_back(mp[st]);
	}
	for (int i = 0; i < K; ++i) {
		string st; cin >> st;
		bs.push_back(mp[st]);
	}
	int win = 0;
	int apower = 0, bpower = 0;
	for (int i = 0; i < K; ++i) {
		if (as[i] == 1 && !apower) {
			win |= 2;
		}
		if (bs[i] == 1 && !bpower) {
			win |= 1;
		}
		if (win == 3)win = 0;
		if (win)break;
		if (as[i] == 1){
			if (bs[i] == 1) {
				if (apower > bpower) {
					win = 1;
				}
				else if (apower == bpower) {
					apower = 0;
					bpower = 0;
				}
				else {
					win = 2;
				}
			}
			else if (bs[i] == 2) {
				if (apower == 5) {
					win = 1;
				}
			}
			else if (bs[i] == 0) {
				win = 1;
			}
		}
		if (bs[i] == 1) {
			if (as[i] == 2) {
				if (bpower == 5) {
					win = 2;
				}
			}
			else if (as[i] == 0) {
				win = 2;
			}
		}
		if (as[i] == 0) {
			apower = min(5, apower + 1);
		}
		if (bs[i] == 0) {
			bpower = min(5, bpower + 1);
		}
		if (as[i] == 1)apower = 0;
		if (bs[i] == 1)bpower = 0;
		
		if (win)break;
	}
	if (win == 1)cout << "Isono-kun" << endl;
	else if (win == 2)cout << "Nakajima-kun" << endl;
	else cout << "Hikiwake-kun" << endl;
	return 0;
}

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

int bubbleSort(int A[],int N);
void printList(int A[],int N);

int main()
{
  int ans,N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++) cin >> A[i];
  ans = bubbleSort(A,N);
  return 0;
}

int bubbleSort(int A[],int N)
{
  int count = 0;
  int tmp;
  int flag = 1;
  while(flag) {
    flag = 0;
    for(int j=N-1;j>0;j--) {
      if(A[j] < A[j-1]) {
        count += 1;
        tmp = A[j-1];
        A[j-1] = A[j];
        A[j] = tmp;
        flag = 1;
      }
    }
  }
  printList(A,N);
  cout << count << endl;
  return count;
}


void printList(int A[],int N)
{
  for (int i = 0;i<N-1;i++) cout << A[i] << " ";
  cout << A[N-1] << endl;
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdlib.h>

using namespace std;
int main()
{
  int N;
  cin >> N;

  if (N % 10 == 3)
  {
    cout << "bon" << endl;
  }
  else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }

  return 0;
}

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

const int N = 1e6 + 50;
typedef long long ll;
int n, top;
ll S[N], sum[N];

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0;
	char ch;
	do ch = nc(); while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res;
}

inline int read_operation()
{
	char ch;
	do ch = nc(); while (ch != '+' and ch != '-');
	return ch == '+';
}

int main()
{
	n = read();
	S[0] = sum[0] = read(); top = 0;
	for (int i = 1; i < n; ++i)
	{
		int p = read_operation(); ll t = read();
		if (p == 1) sum[top] += t, S[top] += t; 
		else 
		{
			++top;
			S[top] = S[top - 1] + t;
			sum[top] = sum[top - 1] - t;
		}
	}
	ll ans = sum[top];
	for (int i = 0; i < top; ++i) ans = std::max(ans, sum[i] - (S[i + 1] - S[i]) + (S[top] - S[i + 1]));
	printf("%lld", ans);
}


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

int32_t main() {
  int n;
  cin >> n;
  vector<pair<int,int>> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].first;
    b[i].second = i;
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    if (a[i].first > b[i].first) {
      cout << "No";
      return 0;
    }
  }

  for (int i = 0; i < n-1; i++) {
    if (a[i+1].first <= b[i].first) {
      cout << "Yes";
      return 0;
    }
  }

  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    p[a[i].second] = b[i].second;
  }
  int len = 1;
  int cur = p[0];
  while (cur != 0) {
    cur = p[cur];
    len++;
  }
  if (len < n) {
    cout << "Yes";
    return 0;
  }
  cout << "No";
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		char[][] s = new char[2][n];
		s[0] = sc.next().toCharArray();
		s[1] = sc.next().toCharArray();
		int idx = 0;
		long cnt = 0;
		int v = 1000000007;
		boolean x = false, y = false;
		if (s[0][0] == s[1][0]) {
			idx = 1;
			cnt = 3;
			x = true;
		} else {
			idx = 2;
			cnt = 6;
			y = true;
		}
		for (; idx < n; idx++) {
			if (s[0][idx] == s[1][idx]) {
				if (x) {
					cnt = (cnt * 2) % v;
				} else if (y) {
					y = false;
					x = true;
				}
			} else {
				idx++;
				if (x) {
					cnt = (cnt * 2) % v;
					x = false;
					y = true;
				} else if (y) {
					cnt = (cnt * 3) % v;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22996
def solve():
    N, A, B = list(map(int, input().split(" ")))
    S = list(input())
    pass_students = 0
    pass_foreigners = 0

    for s in S:
        if s == "a":
            if pass_students < A + B:
                print("Yes")
                pass_students += 1
            else:
                print("No")
        elif s == "b":
            if pass_students < A + B and pass_foreigners < B:
                print("Yes")
                pass_students +=1
                pass_foreigners += 1
            else:
                print("No")
        else:
            print("No")


solve()

Measured memory_bytes: 4704
c11,c12,c13 = map(int,input().split())
c21,c22,c23 = map(int,input().split())
c31,c32,c33 = map(int,input().split())

d1,d2 = c12-c11, c13-c12
d3,d4 = c22-c21, c23-c22
d5,d6 = c32-c31, c33-c32

d7,d8,d9 = c21-c11,c22-c12,c23-c13
da,db,dc = c31-c21,c32-c22,c33-c23

if not(d1 == d3 == d5):
    print('No')
elif not(d2 == d4 == d6):
    print('No')
elif not(d7 == d8 == d9):
    print('No')
elif not(da == db == dc):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	while (1) {
		s.pop_back();
		s.pop_back();
		bool ok = 1;
		for (int i = 0; i < s.size() / 2; i++) {
			if (s[i] != s[i + s.size() / 2]) {
				ok = 0;
				break;
			}
		}
		if (ok) {
			cout << s.size() << endl;
			return 0;
		}
	}
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string N;
    cin >> N;
    vector<vector<vector<vector<int>>>> dp(N.size() + 1, vector<vector<vector<int>>>(8, vector<vector<int>>(2, vector<int>(2))));
    
    dp[0][0][0][0] = 1;
    int dig[] = {3, 5, 7};

    for(int i = 0; i < N.size(); i++) {
        for(int j = 0; j < 8; j++) {
            for(int l = 0; l < 2; l++) {
                // k == 0
                for(int k = 0; k < 3 && dig[k] <= N[i] - '0'; k++) {
                    dp[i + 1][j | (1 << k)][(N[i] - '0') != dig[k]][1] += dp[i][j][0][l];
                }
                // k == 1
                for(int k = 0; k < 3; k++) {
                    dp[i + 1][j | (1 << k)][1][1] += dp[i][j][1][l];
                }
                if (!l) {
                    dp[i + 1][j][1][0] += dp[i][j][0][0];
                    dp[i + 1][j][1][0] += dp[i][j][1][0];
                }
            }
            
        }
    }
    int ans = 0;
    for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 2; l++) {
            ans += dp[N.size()][7][k][l];
        }
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll V, E, s, t, d;

const ll INF = 1e15;
typedef ll Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 Graph:隣接リスト,dist:各頂点から各頂点までの距離が入る,inter:最短路木の親頂点が入る
//戻値 負閉路が存在しない場合:true,そうでないとき:false
bool shortestPath(const Graph &g, vector<vector<Weight> > &dist, vector<vector<int> > &inter) {
	int n = g.size();
	dist.assign(n, vector<Weight>(n, INF));
	for (int i = 0; i<n; i++) {
		dist[i][i] = 0;
	}
	for (int i = 0; i<n; i++) {
		for (auto f = g[i].begin(); f != g[i].end(); f++) {
			dist[i][f->dst] = f->weight;
		}
	}
	inter.assign(n, vector<int>(n, -1));
	for (int k = 0; k<n; k++) {
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				if (dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i][k] + dist[k][j]) {
					dist[i][j] = dist[i][k] + dist[k][j];
					inter[i][j] = k;
				}
			}
		}
	}
	for (int i = 0; i<n; i++) {
		if (dist[i][i]<0) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> V >> E;
	Graph g(V);
	for (int i = 0; i < E; i++) {
		cin >> s >> t >> d;
		g[s].push_back(Edge(s, t, d));
	}
	vector<vector<Weight> >dist;
	vector<vector<int> > inter;
	bool negative_cycle = shortestPath(g, dist, inter);
	if (!negative_cycle) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V - 1; j++) {
				if (dist[i][j] == INF) {
					cout << "INF ";
				}
				else {
					cout << dist[i][j] << " ";
				}
			}
			if (dist[i][V - 1] == INF) {
				cout << "INF" << endl;
			}
			else {
				cout << dist[i][V - 1] << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3308
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{
	ll a,b,k;
	cin >> a >> b >> k;
	
	if (k < a) {
		cout << (a - k) << " " << b << endl;
	}
	else if (a <= k && k <= (a+b)) {
		cout << "0" << " " << b - (k - a) << endl;
	}
	else if (k > b) {
		cout << "0" << " " << "0" << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.14159265359;
typedef pair<int,int> P;

signed main() {
    int X,Y;
    cin >> X >> Y;
    int ret = 0;
    if(X == 1 && Y == 1) {
        cout << 1000000 << endl;
        return 0;
    }
    if(X < 4) {
        if(X == 1) {
            ret += 300000;
        }
        else if(X == 2) {
            ret += 200000;
        }
        else if(X == 3) {
            ret += 100000;
        }
    }
    if(Y < 4) {
        if(Y == 1) {
            ret += 300000;
        }
        else if(Y == 2) {
            ret += 200000;
        }
        else if(Y == 3) {
            ret += 100000;
        }
    }
    cout << ret << endl;
}

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

int main()
{
  // 入力                                                                                                              
  int A, B;
  cin >> A >> B;

  int fee = 0;

  if(A >= 13)
    fee = B;
  else if((A < 13) && (A >=6))
    fee = B / 2;
  else if (A < 6)
    fee = 0;

  //出力                                                                                                   
  cout << fee << endl;

  return 0;
}

Measured memory_bytes: 256
from sys import stdin

n, l = [int(v) for v in stdin.readline().rstrip().split()]

a_lst = [l+i for i in range(n)]
a_p_lst = [abs(l+i) for i in range(n)]

p = a_p_lst.index(min(a_p_lst))
print(sum(a_lst)-a_lst[p])

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<vector>


using namespace std;














int main(){

    int a[3][200];
    int N =0;


    //int num_candy = 0;
    int max=0;

    cin >> N;

    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin >> a[i][j];
        }
    }

    //for(int i=0;i<2;i++){
    //    for(int j=0;j<N;j++){
    //        cout <<  a[i][j] << " ";
    //    }
    //    cout << endl;
    //}

   for(int k=0;k<N;k++){
       int num_candy = 0;
         for(int i=0;i<=k;i++){
             num_candy+=a[0][i];
         }
         for(int j=k;j<N;j++){
             num_candy +=a[1][j];
         }


         if(max<num_candy) max = num_candy;
       }

       cout << max;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <stdio.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 998244353
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};
 
string S;
int dp[202020][2][3][3]; 

set<string> se;

void dfs(string ss) {
  se.insert(ss);
  REP(i,ss.length()-1) if (ss[i] != ss[i+1]) {
    string t = ss;
    if ((ss[i] == 'b' && ss[i+1] == 'c') || (ss[i] == 'c' && ss[i+1] == 'b')) t[i] = t[i+1] = 'a';
    else if ((ss[i] == 'a' && ss[i+1] == 'c') || (ss[i] == 'c' && ss[i+1] == 'a')) t[i] = t[i+1] = 'b';
    else if ((ss[i] == 'a' && ss[i+1] == 'b') || (ss[i] == 'b' && ss[i+1] == 'a')) t[i] = t[i+1] = 'c';
    if (se.find(t) == se.end()) {
      dfs(t);
    }
  }
}

int brute(string ss) {
  dfs(ss);
  return se.size();
}

signed main() {
  cin >> S;
  int N = S.length();

  // if (N <= 7) assert(false);

  if (N <= 7) {
    cout << brute(S) % MOD << endl;
    return 0;
  }

  bool same = true;
  REP(i,N-1) if (S[i] != S[i+1]) {
    same = false;
    break;
  }
  if (same) {
    cout << 1 << endl;
    return 0;
  }

  dp[1][0][0][0] = 1;
  dp[1][0][1][1] = 1;
  dp[1][0][2][2] = 1;
  for (int i=1; i<=N-1; i++) {
    REP(C,2) {
      REP(last,3) {
        REP(mod,3) {
          if (dp[i][C][last][mod] != 0) {
            REP(j,3) {
              dp[i+1][C|(last==j)][j][(mod+j)%3] += dp[i][C][last][mod];
              dp[i+1][C|(last==j)][j][(mod+j)%3] %= MOD;
            }
          }
          // REP(j,3) {
          //   dp[i+1][C|(last==j)][j][(mod+j)%3] += dp[i][C][last][mod];
          //   dp[i+1][C|(last==j)][j][(mod+j)%3] %= MOD;
          // }
        }
      }
    }
  }

  int mod = 0;
  REP(i,N) mod += S[i] - 'a';
  mod %= 3;

  int ans = 1;
  ans += dp[N][1][0][mod] + dp[N][1][1][mod] + dp[N][1][2][mod];
  REP(i,N-1) if (S[i] == S[i+1]) {
    ans--;
    break;
  }
  cout << ans % MOD << endl;
}

Measured memory_bytes: 28676
import java.util.*;
public class Main{
		private static Scanner sc;
	    public static void main(String[] args){
	    	int A[] = new int[33];
	        A[0]=1;
	        for (int i=1; i<=32; i++){
	        	A[i]=A[i-1];
	        	if (i>1) A[i]+=A[i-2];
	        	if (i>2) A[i]+=A[i-3];
	        }
	        sc = new Scanner(System.in);
			int a;
			while ((a=sc.nextInt())>0){
				System.out.println((int)(A[a]/3650)+1);
	        }
	}
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Input();
            var ans = n * n * n;
            Console.WriteLine(ans);


        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int k;bool v[1000000];
main()
{
	scanf("%d",&k);
	for(register int i=7%k,ans=1;;i=(i*10+7)%k,++ans)
	{
		if(!i){printf("%d",ans);return 0;}
		if(v[i]){puts("-1");return 0;}
		v[i]=1;
	}
}

Measured memory_bytes: 2708
package main

import "fmt"

import "strings"

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}
func main() {
	var s string
	fmt.Scan(&s)
	//fmt.Println(len(s))
	var s_reverse string
	s_reverse = Reverse(s)
	var ind_A, ind_Z int
	ind_A = strings.Index(s, "A")
	ind_Z = len(s) - strings.Index(s_reverse, "Z")
	fmt.Printf("%d", ind_Z-ind_A)
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans,x,y;
struct Node{long long x,y;}a[100010];
long long maxn;
bool cmp(Node a,Node b)
{
	return a.x<b.x || a.x==b.x && a.y<b.y;
}
int main()
{
	cin>>n>>m;
	for (int i=1; i<=m; ++i)
		cin>>a[i].x>>a[i].y;
	sort(a+1,a+m+1,cmp);
	maxn=a[1].y; ans=0;
	for (int i=2; i<=m; ++i)
	{
		if (a[i].x>=maxn)
		{
			maxn=a[i].y;
			ans++;
		}
		else
			maxn=min(maxn,a[i].y);
	}
	ans++;
	cout<<ans;
}


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

using namespace std;

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

  string s, t;
  cin >> s >> t;
  int n = s.length(), m = t.length();

  vector<int> ss(n + 1), st(m + 1);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') ss[i + 1] = ss[i] + 1;
    if (s[i] == 'B') ss[i + 1] = ss[i] + 2;
  }
  for (int i = 0; i < m; i++) {
    if (t[i] == 'A') st[i + 1] = st[i] + 1;
    if (t[i] == 'B') st[i + 1] = st[i] + 2;
  }

  int q, a, b, c, d;
  cin >> q;
  while (q--) {
    cin >> a >> b >> c >> d;
    int x = ss[b] - ss[a - 1];
    int y = st[d] - st[c - 1];
    if (x % 3 == y % 3) {
      cout << "YES\n";
    }
    else {
      cout << "NO\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1744
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		final int K = scan.nextInt();
		final int X = scan.nextInt();

		for(int i = 0;i < 2*K-1;i++){
			System.out.println(X - (K-1) + i);
		}
	}
}

Measured memory_bytes: 21844
s = gets.chomp
k = gets.to_i

def n(a)
  26 - (a.ord - 'a'.ord)
end

i = 0
loop do
  break if k.zero?
  if i == s.size
    l = s[-1]
    (k % 26).times do
      l.next!
      l = 'a' if l == 'aa'
    end
    s[-1] = l
    break
  end

  nn = n(s[i])
  if nn <= k && s[i] != 'a'
    s[i] = 'a'
    k -= nn
  end
  i += 1
end

puts s


Measured memory_bytes: 2044
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
    }
    
    Scanner sc;
    int X = 0;
    String S;
    int min = Integer.MAX_VALUE;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        S = sc.next();
    }
    
    //解答処理
    int solve() {
        for (int i=0; i<(S.length()-2); ++i){
            int X = Integer.parseInt(S.substring(i,i+3));    //Sから取り出した数字をint型に変換
            int dif = Math.abs(X - 753);   //差の絶対値を求める
            min = Math.min(min,dif);  //小さい方をminに代入
        }
        
        int answer = min;
        return answer;
    }
    
    //出力
    void show(int answer) {
        System.out.println(answer);
    }
}

Measured memory_bytes: 35608
# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


def resolve_v3(A, B, N):
    maxM = calcM(A, B, N)

    k, r = divmod(N, B)
    if k and B * k -1 <= N:
        # k * B - 1で調査
        maxM = max(maxM, calcM(A, B, B - 1))
    # if r == 0:
    #     maxM = max(maxM, calcM(A, B, N - 1))

    maxM = calcM(A, B, min(N, B - 1))


    return maxM

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v3(A, B, N)
    print(M)




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

using namespace std;
typedef long long ll;

int a[3000];
ll sum[3001];
vector<vector<ll>> dp(3000, vector<ll>(3000, -1));


ll fun(int l, int r){
	if(dp[l][r] != -1) return dp[l][r];
	if(l == r){
		return dp[l][l] = a[l];
	}
	return dp[l][r] = max(a[l] - fun(l+1, r),a[r] - fun(l, r-1));
}


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

Measured memory_bytes: 74016
import sys

def main():
    input = sys.stdin.readline
    H, W, N = map(int, input().split())
    ini_r, ini_c = map(int, input().split())
    S = str(input().strip())[::-1]
    T = str(input().strip())[::-1]

    dp = [0] * (N+1)
    dp[0] = (1, H, 1, W)
    for i in range(N):
        s, t, = S[i], T[i]
        d, u, l, r = dp[i]

        if t == 'L':
            r = min(W, r+1)
        elif t == 'R':
            l = max(1, l-1)
        elif t == 'U':
            u = min(H, u+1)
        else:
            d = max(1, d-1)

        if s == 'L':
            l += 1
        elif s == 'R':
            r -= 1
        elif s == 'U':
            d += 1
        else:
            u -= 1

        if u < d or r < l:
            return 'NO'

        dp[i+1] = (d, u, l, r)

    d, u, l, r = dp[N]
    if not(d <= ini_r <= u and l <= ini_c <= r):
        return 'NO'
    else:
        return 'YES'


if __name__ == '__main__':
    print(main())


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

typedef long long ll;

int N, S, W, Q, a[100005];

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%Q;
    x=x*x%Q;
    n/=2;
  }
  return res;
}

void init(){
  int g = S;
  for(int i=0; i<N; i++) {
    a[i] = (g/7) % 10;
    if( g%2 == 0 ) { g = (g/2); }
    else           { g = (g/2) ^ W; }
  }
}

signed main(){

  while(1){
    
    cin>>N>>S>>W>>Q;
    if( !N && !S && !W && !Q ) break;
    
    init();
    
    map<int,int> cnt;
    
    int ans = 0, A = 1, B = 0, sum = 0;
        
    if( a[0] != 0 ){
      cnt[ a[0] % Q ]++;
      sum++;
      if( a[0] % Q == 0 ) ans++;
    }
    
    for(int i=1;i<N;i++){
      
      A = A * 10 % Q;
      B = ( B * 10 + a[i] ) % Q;
      
      if( a[i] != 0 ){
	
	int num = ( mod_pow( A, Q - 2 ) * ( a[i] + ( Q - B ) ) ) % Q;
	
	if( !( A == 0 && ( a[i] + ( Q - B ) ) % Q != 0 ) ){
	  cnt[num]++;
	  sum++;
	}
	
      }
      
      int num = ( mod_pow( A, Q - 2 ) * ( Q - B ) ) % Q;
            
      if( !( A == 0 && ( Q - B ) % Q != 0 ) ){
	if( A != 0 ) ans += cnt[num];
	else ans += sum;
      }
      
    }
    
    cout<<ans<<endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 9532
from copy import deepcopy
h, w, k = map(int, input().split())
C = [[c for c in input()] for i in range(h)]

def subsets(n):
    result = [[]]
    for i in range(n):
        for j in range(len(result)):
            current = result[j]
            result.append(current+[i])
    return result

def countExceptForIndices(rows, columns):
    cnt = 0
    for i in range(h):
        if i in rows:
            continue
        for j in range(w):
            if j in columns:
                continue
            if C[i][j] == "#":
                cnt += 1
    return cnt
redRows = subsets(h)
redColumns = subsets(w)
ans = 0
for r in redRows:
    for j in redColumns:
        if countExceptForIndices(r, j) == k:
            ans += 1 
print (ans)

Measured memory_bytes: 9308
// abc147_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector<int> A(N);
    vector<vector<P>> T(N);
    REP(i, N){
        cin >> A[i];
        T[i].resize(A[i]);
        REP(j, A[i]){
            cin >> T[i][j].first >>  T[i][j].second;
            T[i][j].first--;
        }
    }

    int ans = 0;
    REP(p, 1 << N){

        int tmp_cnt = 0;
        bool is_valid = true;
        REP(i, N){
            if ((p >> i) & 1){
                tmp_cnt++;
                REP(j, A[i]){
                    int k = T[i][j].first;
                    is_valid &= ((p >> k) & 1) == T[i][j].second;
                }
            }
        }
        if (is_valid){
            ans = max(ans, tmp_cnt);
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        var d = "Christmas";
        switch (int.Parse(Console.ReadLine()))
        {
            case 24:
                d += " Eve";
                break;
            case 23:
                d += " Eve Eve";
                break;
            case 22:
                d += " Eve Eve Eve";
                break;
        }
        Console.WriteLine(d);
    }
}

Measured memory_bytes: 27120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

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

    repr(i, k, n-1){
        if(a[i] > a[i-k]){
            cout << "Yes" << endl;
        }else{
                cout << "No" << endl;
        }
    }
    
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 4416
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range (a+1):
    for j in range (b+1):
        for k in range (c+1):
            if 500*i+100*j+50*k == x:
                ans += 1
print(ans)

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

int main(void)
{
    long long mod = 1000000007;
    long long S;
    cin >> S;
    vector<long long> count(2001);
    count[1] = 0;
    count[2] = 0;
    count[3] = 1;
    count[4] = 1;
    count[5] = 1;
    for (long long i = 6; i <= S; i++)
    {
        count[i] = 1;
        long long x = 3;
        while(1)
        {
            if (i - x < 3)
            {
                break;
            }
            count[i] = (count[i] + count[i-x]) % mod;
            x++;
        }
    }
    cout << count[S] << endl;
}

Measured memory_bytes: 3628
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    rep(i,100000){
        int x,y;
        cin>>x>>y;
        if(x==0&&y==0) break;
        // cout<<"Case "<<i+1<<": "<<x<<endl;
        cout<<min(x,y)<<" "<<max(x,y)<<endl;
    }

}


Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 2000000
int H,A[MAX+1];
void maxHeapify(int);

void maxHeapify(int i){
  int l,r,largest,c;
  l=2*i;
  r=2*i+1;
  
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest]) largest=r;

  if(largest!=i){
    c=A[i];
    A[i]=A[largest];
    A[largest]=c;
    maxHeapify(largest);
  }
}

int main()
{
  int i;
  
  scanf("%d",&H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }

  printf("\n");
  
  return 0;
}

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

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

	int n;
	cin >> n;

	vector<int> cs(n + 9, 0);
	for (int i = 1; i <= n; ++i) {
		char c;
		cin >> c;
		if (c == '#')
			++cs[i];
	}
	partial_sum(cs.begin(), cs.end(), cs.begin());

	int ans = (int) 1e9;
	for (int i = 0; i <= n; ++i) {
		ans = min(ans, cs[i] + (n - i) - (cs[n] - cs[i]));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
//ringo9971さんのコードを参考にさせていただきました。ありがとうございました。

#include<stdio.h>
#include<stdlib.h>

/*例えば
2つ目の要素を使いたいときに
*(int*)(a+1) - *(int*)(b+1)とするとうまくいったが
3つ目も同様にするとうまくいかなかった。(+2にしたけども）。
実際にそれらの値を%dで出力すると、全然違う値が出てきたのでその上のような書き方は
ダメとわかった。(2つ目のはたまたまだったとわかった)
で、下のように一度別の変数に入れてから++すると、2つ目とか3つ目とかの要素を
さすことができた。
*/
int compF(const void* a, const void* b){
    int* A = (int*)a;
    int* B = (int*)b;
    if(*A == *B){
        A++; B++;
        return *A - *B;
    }
    else{
        return *A - *B;
    }
}

int compB(const void* a, const void* b){
    int* A = (int*)a;
    int* B = (int*)b;
    A += 2; B += 2;
    return *A - *B;
}

int main(void){
    int N, M;
    scanf("%d%d", &N, &M);
    int data[M][3];
    for(int i = 0; i < M; i++){
        for(int j = 0; j < 2; j++){scanf("%d", &data[i][j]);}
        data[i][2] = i;
    }
    /*for(int i = 0; i < M; i++){
        for(int j = 0; j < 3; j++){printf("%d", data[i][j]);}
        printf("\n");
    }
    return 0;*/
    qsort(data, M, 3*sizeof(int), compF);
    
    int pre = data[0][0];
    int count = 0;
    int idx = 0;
    while(idx < M){
        if(pre == data[idx][0]){
            count++;
            data[idx][1] = count;
        }
        else{
            count = 1;
            pre = data[idx][0];
            data[idx][1] = count;
        }
        idx++;
    }
    
    qsort(data, M, 3*sizeof(int), compB);

    /*for(int i = 0; i < M; i++){
        for(int j = 0; j < 3; j++){printf("%d ", data[i][j]);}
        printf("\n");
    }
    return 0;*/

    for(int i = 0; i < M; i++){
        printf("%06d%06d\n", data[i][0], data[i][1]);
    }
    return 0;

}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define ff first
#define tcase int _; cin>> _; for( ; _; --_)
#define ss second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	for(;exp; exp>>=1){
		if(exp % 2 == 1) total = mod(((mod(total, m)) * (mod(base, m))), m);
		base= mod((mod(base, m) * mod(base, m)), m);
	}
	return total;
}

void solve(){
    int n;
    cin >> n;
    n-=3; 

    int c[2001];
    int inv[2001];
    c[0] = c[1] = inv[0] = inv[1] = 1;

    for(int i = 2; i <= 2000; ++i) c[i] = mod(i * c[i- 1], MOD);
    inv[2000] = fexp(c[2000], MOD-2, MOD);
    for(int i = 1999; i >=2; --i) inv[i] = mod(inv[i + 1] * (i + 1), MOD);

    int ans = 0;
    for(int i = 0; n >=0 ; ++i, n-=3){
        //int k = mod(c[n + i] * mod(fexp(c[n], MOD-2, MOD) * fexp(c[i], MOD-2, MOD), MOD), MOD);
        int k = mod(c[n + i] * mod(inv[n] * inv[i], MOD), MOD);
        ans = mod(ans + k, MOD);
    }
    cout<< ans<< endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 1e6+5;

int main() {
   int x, y, z, k;
   cin >> x >> y >> z >> k;

   while(k && y <= x) k--, y <<= 1;
   while(k && z <= y) k--, z <<= 1;

   if(x < y && y < z) puts("Yes");
   else puts("No");
}


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

int main()
{
    int n, q;
    int order, index, value;

    cin >> n >> q;

    stack<int> s[n];

    for( int i = 0; i < q; i++ )
    {   
        cin >> order >> index;

        switch( order )
        {
            case 0:
                cin >> value;
                s[index].push(value);
                break;
            case 1:
                if( s[index].size() == 0 );
                else
                    cout << s[index].top() << endl;
                break;
            case 2:
                if( s[index].size() == 0);
                else
                    s[index].pop();
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 4448