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

#define REP(i, a, n) for(int i=a; i<n; i++)
#define sortv(v) sort(v.begin(), v.end());
#define sortg(v) sort(v.begin(), v.end(), greater<>());

int main() {
  int n, y, a=-1, b=-1, c=-1, tmp;
  cin >> n >> y;
  REP(i, 0, n+1){
    tmp = y-1000*n-4000*i;
    if(tmp>0 && tmp%9000==0 && n-tmp/9000-i>=0){
      a=tmp/9000;
      b=i;
      c=n-a-b;
    }
    if(tmp==0 && n-i>=0){
      a=0;
      b=i;
      c=n-i;
    }
  }
  cout << a << ' ' << b << ' ' << c << endl;

}


Measured memory_bytes: 256
import math
from collections import deque
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    if all([a_i>0 for a_i in a]):
        print(n-1)
        for i in range(1,n):
            print(i,i+1)
        
    elif all([a_i<=0 for a_i in a]):
        print(n-1)
        for i in range(1,n)[::-1]:
            print(i+1,i)

    else:
        if abs(min(a))<max(a):
            print(2*n-1)
            pos = a.index(max(a))+1
            for i in range(n):
                print(pos,i+1)
            for i in range(1,n):
                print(i,i+1)


        else:
            print(2*n-1)
            pos = a.index(min(a))+1
            for i in range(n):
                print(pos,i+1)  
            
            for i in range(1,n)[::-1]:
                print(i+1,i)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3440
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, -weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn dfs(g: &Graph, from: usize, d: i32, dists: &mut Vec<Option<i32>>) -> bool {
    if let Some(v) = dists[from] {
        return v == d;
    }
    dists[from] = Some(d);
    let mut ret = true;
    for edge in g[from].iter() {
        ret &= dfs(g, edge.dest, d + edge.weight, dists);
    }
    ret
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut g = graph_new(n);
    let mut e = 0;
    for _ in 0..m {
        let mut f: usize = read();
        let mut t: usize = read();
        let d: i32 = read();
        f -= 1; t -= 1;
        add_bi_edge(&mut g, &mut e, f, t, d);
    }
    let mut ans = true;
    let mut dists = vec![None; n];
    for i in 0..n {
        if dists[i] != None { continue; }
        ans &= dfs(&g, i, 0, &mut dists);
    }
    println!("{}", if ans { "Yes" } else { "No" });
}

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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int n, k; cin >> n >> k;
    vi a(n);
    for(int& u : a) cin >> u;
    sort(all(a));
    int sum = 0;
    for(int i = 0; i < k; i++) sum += a[i];
    cout << sum << '\n';
    
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
	
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    n = I()
    a = [S() for _ in range(n)]
    m = I()
    b = [S() for _ in range(m)]
    d = 1
    for c in b:
        if c not in a:
            rr.append('Unknown {}'.format(c))
        elif d == 1:
            rr.append('Opened by {}'.format(c))
            d = 0
        else:
            rr.append('Closed by {}'.format(c))
            d = 1

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9084
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

// Delete the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 100003, M_MAX = 200003;
int h[N_MAX], cntEdge;
struct Edge {
  int tar, nxt;
  Edge() {}
  Edge(int tar, int nxt) : tar(tar), nxt(nxt) {}
}ed[M_MAX];

int col[N_MAX], cntNode, tub[3];
int dfs(int x) {
  ++cntNode, ++tub[col[x]];
  bool ext[2] = {0, 0};
  int state = 0;
  for (int i = h[x]; i; i = ed[i].nxt) {
    ++cntEdge, ext[i & 1] = 1;
    int y = ed[i].tar, temp = col[x] - 1 - (i & 1);
    temp += (temp >> 31) & 3;
    if (col[y] > 2)
      col[y] = temp, state |= dfs(y);
    else
      if (col[y] != temp)
        state |= 2;
  }
  return state | (ext[0] & ext[1]);
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    ed[++cntEdge] = Edge(y, h[x]), h[x] = cntEdge;
    ed[++cntEdge] = Edge(x, h[y]), h[y] = cntEdge;
  }
  
  long long ans = 0;
  memset(col + 1, 0x3f, sizeof(int) * n);
  for (int i = n; i; --i)
    if (col[i] > 2) {
      cntNode = cntEdge = tub[0] = tub[1] = tub[2] = 0, col[i] = 2;
      int state = dfs(i);
      if (state & 2)
        ans += 1ll * cntNode * cntNode;
      else
        if (state & 1)
          ans += 1ll * tub[0] * tub[1] + 1ll * tub[1] * tub[2] +
            1ll * tub[2] * tub[0];
        else
          ans += cntEdge >> 1;
    }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 7296
s=input()
t=input()
c=0
for i in range(len(s)-len(t)+1):
    x=s[i:i+len(t)]
    tmp=0
    for j in range(len(t)):
        if x[j]==t[j]:
            tmp+=1
    if c<tmp:
        c=tmp
print(len(t)-c)

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int a;
    int left = 0, right = 0;
    for (int i = 0; i < M; i++) {
        cin >> a;
        if(a < X) left++;
        else right++;
    }
    cout << min(left, right) << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define ll long long
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(x) for(int i=1;i<=x;i++) 
#define sforn(x, y) for(int i=1;i<=x;i++)for(int j=1;j<=y;j++)
#define pii pair<int, int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){ speed;
    string s1, s2;
    cin >> s1 >> s2;
    int ans = 0;
    for(int i=0;i<s1.sz;i++) ans+=(s1[i] == s2[i]);
    cout << ans << endl;
    return 0;
}

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

const int MOD=2019;

int main(){
  int L; cin >> L;
  int R; cin >> R;
  int l=L % MOD;
  int r=R % MOD;
  int ans=2019;
  if (L/MOD < R/MOD)
    cout << 0 << endl;
  else{
    for (int i=l;i<r;i++){
      for (int j=i+1;j<=r;j++){
        if(i*j%MOD < ans)
          ans=i*j%MOD;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
using System;

namespace abc138_a
{
    static class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().ToInteger();
            var s = Console.ReadLine();
            Console.WriteLine($"{(a < 3200 ? "red" : s)}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }
    }
}


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

namespace ABC109 {
	class ABC109_B {
		static void Main(string[] args) {
			var N = int.Parse(Console.ReadLine());
			var input = new List<string>();
			var head = new List<char>();
			var tail = new List<char>();

			for (int i = 0; i < N; i++) {
				input.Add(Console.ReadLine());
				head.Add(input[i].First());
				tail.Add(input[i].Last());
			}

			if (input.Count() != input.Distinct().Count()) {
				Console.WriteLine("No");
				return;
			};

			for (int i = 0; i < N-1; i++) {
				if(head[i+1] != tail[i]) {
					Console.WriteLine("No");
					return;
				}
			}

			Console.WriteLine("Yes");
		}
	}
}


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

#define pb push_back
#define mp make_pair

#define mod 998244353LL
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define INF 1000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x)*(x))

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL)

#define EPS 1e-7

// using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

typedef pair<i64, i64> pii;

#define maxn (1<<18)+5
#define alpha 22

i64 a[maxn] ;
pair<int,int> dp[maxn] ;
bool vis[maxn] ;

int n ;

void update( pair<int,int> &p , int idx )
{
    if( a[p.xx] < a[p.yy] ) swap( p.xx , p.yy ) ;

    if( p.xx == idx || p.yy == idx ) return ;
    if( a[p.yy] < a[idx]  ) p.yy = idx ;
    if( a[p.xx] < a[p.yy] ) swap( p.xx , p.yy ) ;
}

void dfs(int mask)
{
    if( vis[mask] ) return ;

    dp[mask] = mp( mask  , (1<<n) ) ;

    for(int i=0 ; i<n ; i++)
    {
        if( (mask&(1<<i)) )
        {
            dfs( (mask^(1<<i)) ) ;
            update( dp[mask] , dp[ (mask^(1<<i)) ].xx ) ;
            update( dp[mask] , dp[ (mask^(1<<i)) ].yy ) ;
        }
    }
  //  printf("%d: %d %d\n",mask,dp[mask].xx,dp[mask].yy) ;
    vis[mask] = 1 ;
    return ;
}

i64 ans[maxn] ;

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

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

    a[ (1<<n) ] = -INF ;

    dfs( ((1<<n)-1) ) ;

    for(int i=1 ; i<(1<<n) ; i++)
    {
        ans[i] = a[ dp[i].xx ] + a[ dp[i].yy ] ;
        ans[i] = max( ans[i-1] , ans[i] ) ;
        printf("%lld\n",ans[i]) ;
    }

    return 0 ;
}


Measured memory_bytes: 9472
object Main extends App {

  import scala.io.StdIn._

  val Array(n, a) = readLine().split(' ').map(_.toInt)
  val values = readLine().split(' ').map(_.toInt).map(_ - a).toList
  def table : Map[Int, Long] ={
    def hoge(current: Map[Int, Long], values: List[Int]): Stream[Map[Int, Long]] = {

      def withValue(n: Int) = {
        val newKeys = current.keySet ++ current.keySet.map(_ + n)
        newKeys.map{k => k -> (current.getOrElse(k , 0L) + current.getOrElse(k - n, 0L))}.toMap
      }

      val next = values.headOption.map (withValue)

      val trail = next.map(hoge(_, values.tail)).getOrElse(Stream.Empty)
      current #:: trail
    }

    hoge(Map(0 -> 1), values)(n)
  }

  println(table(0) - 1)
}


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

int main() {
  int N,a,b,c,d;
  cin >> N;
  a = N/1000;
  b = (N%1000)/100;
  c = ((N%1000)%100)/10;
  d = ((N%1000)%100)%10;
  if (a == b){
    if (b == c)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  else {
    if (b == c) {
      if (c == d)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
    else
      cout << "No" << endl;
  }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
	int N,K;cin>>N>>K;
	int ans=0;
	rep(i,N){
		int h;cin>>h;
		if(h>=K)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n,x;
		int y[][] = new int[50][2];
		int i = 0;
		while(true){
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			if ((n==0)&&(x==0)) {
				break;
			} else {
				y[i][0] = n;
				y[i][1] = x;
				i++;
			}
		}
		stdIn.close();
		for(int j=0;j<i; j++) {
			if((y[j][0]*3-3 < y[j][1])|| y[j][1]<6) {
				System.out.println("0");
			} else if((y[j][0] !=0) && (y[j][1]!=0)) {
				System.out.println(check(y[j][0],y[j][1]));
			}
		}
	}
	static int check(int m,int n){
		int ans=0;
		for(int a=m;a>=1;a--) {
			for(int b=m;b>=1;b--){
				if((1<=n-a-b) && (n-a-b <= m)){
					if((a!=b) && (a!=n-a-b) && (b!=n-a-b)) {
						ans +=1;
					}
				}

			}
		}

		return ans/6;
	}
}



Measured memory_bytes: 26304
from collections import defaultdict
N, C = map(int, input().split())

D = [tuple(map(int, input().split())) for _ in range(C)]

d = [defaultdict(int) for i in range(3)]


for i in range(N):
    c = [int(x) for x in input().split()]
    for j in range(N):
        for k in range(C):
            d[(i+j) % 3][k] += D[c[j]-1][k]
# print(d)

ans = 10**9
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and j != k and k != i:
                ans = min(ans, d[0][i]+d[1][j]+d[2][k])

print(ans)


Measured memory_bytes: 45148
n = int(input())
 
val_list = []
for _ in range(n):
    val_list.append(int(input()))
 
min_val = val_list[0]
 
diff_max = -200000000000000000
 
for i in range(1, len(val_list)):
    diff_max = max(diff_max, val_list[i]-min_val)
    min_val = min(min_val, val_list[i])
 
print(diff_max)


Measured memory_bytes: 13588
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import bisect
from operator import itemgetter

h,w,m = readints()

r = [0]*h
c = [0]*w

p = [readints() for i in range(m)]
p.sort(key=itemgetter(1))

d = [[] for i in range(h)]
for i in range(m):
    a,b = (x-1 for x in p[i])
    r[a] += 1
    c[b] += 1
    d[a].append(b)

mr = max(r)
mc = max(c)
R = [i for i,x in enumerate(r) if x==mr]
C = [i for i,x in enumerate(c) if x==mc]

flag = 1
if len(R)*len(C)>m:
    flag = 0
else:
    for x in R:
        for y in C:
            z = bisect.bisect_left(d[x],y)
            if z>=len(d[x]):
                flag = 0
                break
            else:
                if y != d[x][z]:
                    flag = 0
                    break

print(max(r)+max(c)-flag)






Measured memory_bytes: 213984
n,x = map(int,input().split(" "))

def minus_x(t):
    return abs(int(t) - x)
cities = sorted(list(map(minus_x,input().split(" "))))

def gcd(a,b):
    while b>0:
        a,b = b,a%b
    return a

if n == 1:
    ans = cities[0]
else:
    ans = gcd(cities[0],cities[1])
    for i in range(2,n-1):
        ans = gcd(cities[i],ans)

print(ans)

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

int main() {
  int N, M, a, b;
  cin >> N;
  M = N;
  
  for (int i = 0; i <9; i++) {
    a = N % 10;
    N /= 10;
    b += a;
  }
  
  if (M % b == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

class Main
{
    public static void main(String[] args)
    {
        new Main().run();
    }
    
    void run(){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int[] P=new int[N];
        int[] Q=new int[N];
        int n1=0,n2=0;
        for(int i=0;i<N;++i)P[i]=sc.nextInt();
        for(int i=0;i<N;++i)Q[i]=sc.nextInt();
        for(int i=0;i<N;++i)n1=n1*10+P[i];
        for(int i=0;i<N;++i)n2=n2*10+Q[i];
        int ans=0;
        if(n1>n2){
            n1^=n2;
            n2^=n1;
            n1^=n2;
        }
        while(true){
            if(n1==n2)break;
            ++n1;
            while(!ok(n1,N))++n1;
            ++ans;
        }
        System.out.println(ans);
    }
    
    boolean ok(int v,int n){
        boolean[] f=new boolean[10];
        while(v>0){
            if(f[v%10])return false;
            f[v%10]=true;
            v/=10;
        }
        boolean ret=true;
        for(int i=1;i<=n;++i)ret&=f[i];
        return ret;
    }
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


Measured memory_bytes: 339668
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int x = n % 500;
        if(x - a <= 0){
            System.out.println("Yes");
            return;
        }
            System.out.println("No");
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

	int N, M;
	cin >> N >> M;

	VI cs( M ), ds( M );
	REP( i, N )
	{
		cin >> cs[i] >> ds[i];
	}

	VI ary( N + 1 );
	REP( i, M )
	{
		++ary[ cs[i] ];
		--ary[ ds[i] ];
	}
	VI csum;
	partial_sum( ALL( ary ), BI( csum ) );

	cout << N + 1 + 2 * count_if( ALL( csum ), bind( not_equal_to< int >(), _1, 0 ) ) << endl;

	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<string>
#include<algorithm>
using namespace std;
string date[110];
    int flag[110];

int main()
{
    int n,l;
    scanf("%d%d",&n,&l);
    for(int i=0; i<n; i++)
        cin>>date[i];
    memset(flag,0,sizeof(flag));
    sort(date,date+n);
    for(int i=0;i<n;i++)
        cout<<date[i];
    printf("\n");
    return 0;
}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  cin >> N;
  //vi A(N), B(N);
  vector<pi> AB(N), BA(N);
  REP(0, N, i) {
    i64 A, B;
    cin >> A >> B;
    AB[i] = {A, B};
    BA[i] = {B, A};
  }
  auto comp_ab = [](const pi &lhs, const pi &rhs) {
    if(lhs.first == rhs.first) {
      return lhs.second > rhs.second;
    }
    return lhs.first < rhs.first;
  };
  auto comp_ba = [](const pi &lhs, const pi &rhs) {
    if(lhs.first == rhs.first) {
      return lhs.second < rhs.second;
    }
    return lhs.first > rhs.first;
  };
  sort(all(AB), comp_ab);
  sort(all(BA), comp_ba);

  auto bound = [&](i64 n) {
    return pi(AB[n].first, BA[N-1-n].first);
  };

  if(N % 2 == 1) {
    pi b = bound((N - 1) / 2);
    cout << b.second - b.first + 1 << endl;
  }
  else {
    pi b0 = bound(N / 2 - 1);
    pi b1 = bound(N / 2);
    //cout << b0.first << " " << b0.second << endl;
    //cout << b1.first << " " << b1.second << endl;

    cout << ((b0.second + b1.second) - (b0.first + b1.first) + 1) << endl;
  }


  return 0;
}


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

int main(void)
{
    int a,b;
    cin>>a>>b;
    // int l = min(a*12.5,b*10.0), r = max(a*12.5,b*10.0);
    for(int i=0;i<=1250;++i){
        if(int(i*0.08)==a && int(i*0.1)==b){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector< vector<int> > a(n, vector<int>(n, 0));
  for(int i=0;i<n;i++) {
    int u,k;
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++) {
      int v;
      cin >> v;
      v--;
      a[u][v]++;
    }
  }
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      if(j) cout << " ";
      cout << a[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<ll> a(m);
    rep(i,m) cin>>a[i];
    ll s = 0;
    rep(i,m) s+=a[i];
    
    cout << max(-1ll, n-s) << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
    std::vector<int> vec1 {1, 3, 5, 7, 8, 10, 12};
    std::vector<int> vec2 {4, 6, 9, 11};
    std::vector<int> vec3 {2};

    int x, y;
    std::cin >> x >> y;

    bool flg = false;
    if(vec1.end() !=  std::find(vec1.begin(), vec1.end(), x)){
        if(vec1.end() !=  std::find(vec1.begin(), vec1.end(), y)){
            flg = true;
        }
    }else if(vec2.end() !=  std::find(vec2.begin(), vec2.end(), x)){
        if(vec2.end() !=  std::find(vec2.begin(), vec2.end(), y)){
            flg = true;
        }
    }else if(vec3.end() !=  std::find(vec3.begin(), vec3.end(), x)){
        if(vec3.end() !=  std::find(vec3.begin(), vec3.end(), y)){
            flg = true;
        }
    }

    if(flg){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,y; cin>>n>>y;
    y/=1e3;
    rep(i,n+1)rep(j,n+1){
        int a=y-10*i-5*j;
        if(a>=0 && a==n-i-j){
            cout<<i<<" "<<j<<" "<<n-i-j<<endl;
            i=n; break;
        }
        if(i==n && j==n) cout<<"-1 -1 -1"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<string> A(N);
  vector<int> B(N);
  map<string, int> m{};
  for (auto& a : A) {
    cin >> a;
    ++m[a];
  }
  for (int i = 0; i < N; ++i) {
    B[i] = m[A[i]];
  }
  auto cnt = *boost::max_element(B);
  map<string, int> res{};
  for (int i = 0; i < N; ++i) {
    if (B[i] == cnt) {
      // res.emplace(A[i]);
      res[A[i]];
    }
  }
  boost::for_each(res, [](auto p){
    cout << p.first << CRLF;
  });
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 38656
#include <stdio.h>

int main() {
	int n;
	int ans = 0;
	char str[51]={};
	scanf("%d", &n);
	scanf("%s", str);
	for (int i = 0; i < n - 2; i++) {
		if((str[i]=='A')&&(str[i+1]=='B')&&(str[i+2]=='C')){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import numpy as np
lis=[]
for i in range(102):
    lis.append(i)
#print(lis)
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)
 
X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]
 
    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)-1
    arr=arr[arr<=P_max+1]
    arr=arr[arr>=P_min-1]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)
 
    def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default
 
    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Measured memory_bytes: 27288
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
	int n,m,x,po[10001],p;
	while(cin>>n>>m,n){
		int ans=0;
		vector<int>v[1000];
		r(i,m){
			cin>>po[i]>>x;
			r(j,x){
				cin>>p;
				v[i].push_back(p-1);
			}
		}
		r(i,n){
			int a[n]={},p1=0,p2=1e9;
			r(j,m){
				if(v[j].size()>=2)r(k,v[j].size()){
					if(v[j][k]==i)a[i]+=po[j];
				}
				else a[v[j][0]]+=po[j];
			}
			r(j,n){
				p1=max(p1,a[j]);
				p2=min(p2,a[j]);
			}
			ans=max(ans,p1-p2+1);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3636
#include <stdio.h>

int isPrime(int a){
	if(a % 2 == 0)return 0;
	int lim = a / 2;
	for(int i = 3; i < lim; i += 2){
		if(a % i == 0)return 0;
	}
	return 1;
}

int main(void){
	int n, m;
	scanf("%d %d", &n, &m);
	if(isPrime(m)){
		printf("1\n");
		return 0;
	}
	int i = 0;
	while(m % (n + i))i++;
	printf("%d\n", m / (n + i));
	/*
	int i = 0;
	while(!isPrime(m - i))i++;
	printf("%d\n", m - i);
	*/
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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

const int MOD = 1E9+7;

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

    int n; cin >> n;
    vector<ll> v(n); for (ll& l : v) cin >> l;

    ll sum = accumulate(v.begin(), v.end(), 0ll, plus<ll>());
    ll result = 0;
    for (int i = 0; i < n; i++)
    {
        sum -= v[i];
        result = (result+((sum%MOD)*v[i])%MOD)%MOD;
    }
    cout << result%MOD << endl;

    return 0;
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N,K; cin >> N >> K;
    int a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    int imos[N+1]={};
    int ans[N];
    for(int k=0;k<min(K,100);k++){
        for(int i=0;i<N;i++){
            if(i-a[i]<0&&i+a[i]>N-1){
                imos[0]++;
                imos[N]--;
            }else if(i-a[i]<0){
                imos[0]++;
                imos[i+a[i]+1]--;
            }else if(i+a[i]>N-1){
                imos[i-a[i]]++;
                imos[N]--;
            }else{
                imos[i-a[i]]++;
                imos[i+a[i]+1]--;
            }
        }
        for(int i=0;i<N;i++){
            imos[i+1]+=imos[i];
            ans[i]=imos[i];
            a[i]=imos[i];
            imos[i]=0;
        }
    }
    for(int i=0;i<N;i++){
        cout << ans[i] << " ";
    }
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define  endl 			"\n"
#define  FOR(i, a, n)   for (ll i = a; i < n; i++)
#define  ROF(i, a, n)   for (ll i = a; i >= n; i--)
#define  all(x)         (x).begin(), (x).end()
#define  mset(x, val)   memset(x,val,sizeof(x))
#define  dline          cout<<"///REACHED///\n";

typedef long long ll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  4e+5+7;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//int T;
	//cin >> T;
	//while (T--) {
	bool f;
	int x, y, u, v, ans = 0;
	cin >> x >> y;
	vector<int> a(x);
	vector<unordered_set<int>> b(x);
	for(int& q: a ) cin >> q, q--;
	FOR(i, 0, y) {
		cin >> u >> v;
		u--, v--;
		b[u].insert( v);
		b[v].insert(u);
	}
	FOR(i, 0, x) {
		f = true;
		for(auto q: b[i]) {
			if (a[i] <= a[q]) {
				f = false;
				break;
			}
		}
		if (f) ans++;
	}
	cout << ans << endl;


	//}
	return 0;
}

Measured memory_bytes: 18484
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    const int MOD = 1000000007;
    int LastPos(int start, string cells, string[][] command)
    {
        int pos = start;
        foreach(var cmd in command)
        {
            if(cmd[0][0] == cells[pos])
            {
                if(cmd[1] == "L")
                    pos--;
                else
                    pos++;
            }
            if(pos < 0 || pos >= cells.Length)
                break;
        }
        return pos;
    }
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int q = int.Parse(inputs[1]);

        string cells = Console.ReadLine();
        string[][] command =
            Enumerable.Range(0, q)
            .Select(x => Console.ReadLine().Split())
            .ToArray();
        int right = -1, left = n;
        for(int start = 0, end = n - 1, mid = (start + end) / 2;start <= end; mid = (start + end) / 2)
        {
            int p = LastPos(mid, cells, command);
            if(p == -1)
            {
                right = mid;
                start = mid + 1;                
            }
            else
            {
                end = mid - 1;
            }
        }
        for(int start = 0, end = n - 1, mid = (start + end) / 2;start <= end; mid = (start + end) / 2)
        {
            int p = LastPos(mid, cells, command);
            if(p == n)
            {
                left = mid;
                end = mid - 1;                
            }
            else
            {
                start = mid + 1;
            }
        }
        //System.Console.WriteLine($"{right} {left}");
        int result = left - right - 1;
        System.Console.WriteLine(result);
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 41388
/*	
*  Sachin Mittal
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,j,n) for(int i=j;i<n;i++)
#define F first
#define S second
#define lb lower_bound
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define sz(s) (int)(s.size())
#define debug(x) cout << #x << " = " << x << '\n';

void solve()
{
    int a[5];
    rep(i, 0, 5){
    	cin >> a[i];
    }
    rep(i, 0, 5){
    	if(!a[i]){
    		cout << i + 1;
    		break;
    	}
    }
}

int32_t main(){
ios_base::sync_with_stdio(false); 
cin.tie(0); cout.tie(0);
int tst = 1;
//cin >> tst;
while(tst--)
{
	solve();
}
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long int a,b,c,d;
	cin >> a >> b >> c >> d;
	if (a > 0 && c > 0){
		cout << b*d << "\n";
	}else if(a < 0 && c < 0){
		cout << max(a*c, b*d) << "\n";
	}else if (a < 0){ // c >= 0
		if (b > 0){
			cout << b*d << "\n";
		}else{
			cout << b*c << "\n";
		}	
	}else{ // a >= 0
		if (d > 0){
			cout << b*d << "\n";
		}else{
			cout << a*d << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3652
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> c(n-1),s(n-1),f(n-1);
  rep(i,n) cin>>c[i]>>s[i]>>f[i];
  rep(i,n){
    ll t=0;
    for(ll j=i;j<n-1;j++){
      if(t<s[j]){
        t=s[j];
      }else if(t%f[j]!=0){
        t+=f[j]-t%f[j];
      }
      t+=c[j];
    }
    cout<<t<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n, k, u, v, i, j;
    cin >> n;
    int m[n+1][n+1];
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++) m[i][j] = 0;
    }
    for(i = 1; i <= n; i++){
        cin >> u >> k;
        for(j = 1; j <= k; j++){
            cin >> v;
            m[u][v] = 1;
        }
    }
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            if(j == n) cout << m[i][j] << endl;
            else cout << m[i][j] << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int t;
    while(cin>>t,t){
        int n,sum=0;
        cin>>n;
        while(n--){
            int s,f;
            cin>>s>>f;
            sum+=f-s;
        }
        if(t<=sum)cout<<"OK"<<endl;
        else cout<<t-sum<<endl;
    }

}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), idx(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
        idx[a[i]] = i;
    }
    set<int> s;
    ll ans = 0;
    for(int x = n-1; x >= 0; x--){
        int i = idx[x];
        ll c = 0;
        s.insert(i);
        vector<int> l(2, -1), r(2, n);
        auto it = s.find(i);
        rep(j,2){
            if(it == s.begin()) break;
            --it;
            l[j] = *it;
        }
        it = s.find(i);
        rep(j,2){
            ++it;
            if(it == s.end()) break;
            r[j] = *it;
        }
        vector<int> ls(2);
        ls[0] = i - l[0]; ls[1] = l[0] - l[1];
        vector<int> rs(2);
        rs[0] = r[0] - i; rs[1] = r[1] - r[0];
        c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
        ans += c * (x+1);
    }
    cout << ans << endl;
	return 0;
}

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

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int A,B;
  cin >> A >> B;
  if(A==B) cout << A+B;
  else cout << max(A,B)*2-1;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

#define N 52
using namespace std;

char s[N][N];

int H, W;
int d[N][N];

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

int bfs() {
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            d[i][j] = -1;
        }
    }
    d[1][1] = 0;

    queue< pair< int, int > > q;
    q.push(make_pair(1, 1));

    while (q.size()) {
        pair< int, int > p = q.front();
        q.pop();

        if (p.first == H && p.second == W) {
            break;
        }

        for (int i = 0; i < 4; i++) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if (1 <= nx && nx <= W && 1 <= ny && ny <= H) {
                if (s[ny][nx] != '#' && d[ny][nx] == -1) {
                    q.push(make_pair(ny, nx));
                    d[ny][nx] = d[p.first][p.second] + 1;
                }
            }
        }
    }

    return d[H][W];
}

int main() {
    cin >> H >> W;

    int white_cnt = 0;

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> s[i][j];
            if (s[i][j] == '.') {
                white_cnt++;
            }
        }
    }

    int res = bfs();
    if (res != -1) {
        cout << white_cnt - (res + 1) << endl;
    } else {
        cout << -1 << endl;
    }
}

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

using namespace std;

#include <unordered_map>

using std::unordered_map;

class UnionFind {
  // unordered_map<int, int> graph_;
  // unordered_map<int, int> sizes_;
  vector<int> graph_;
  vector<int> sizes_;

 public:
  UnionFind(int n) : sizes_(n, 1), graph_(n) {
    for (int i = 0; i < n; ++i) {
      graph_[i] = i;
    }
  };

  int Root(int key) {
    if (graph_[key] == key) {
      return key;
    } else {
      return graph_[key] = Root(graph_[key]);
    }
  }

  bool Same(int key1, int key2) { return Root(key1) == Root(key2); }

  void Unite(int key1, int key2) {
    if (Same(key1, key2)) {
      return;
    }

    int root1 = Root(key1);
    int root2 = Root(key2);
    int size = Size(root1) + Size(root2);
    graph_[root1] = root2;
    sizes_[root2] = size;
  }

  int Size(int key) {
    int root = Root(key);
    return sizes_[root];
  }
};

int main(int argc, const char *argv[]) {
  //
  int n, m;
  cin >> n >> m;

  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.Unite(a, b);
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, uf.Size(i));
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 11112
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleTest
{
    class Program
    {
        static bool Kaibun(string s)
        {
            var r = new string(s.Reverse().ToArray());
            return r.CompareTo(s)==0;
        }
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string sub1 = input.Substring(0, (input.Length - 1) / 2);
            string sub2 = input.Substring((input.Length + 3) / 2 - 1, 1 + input.Length - (input.Length + 3) / 2);
            //Console.WriteLine(input.Length);
            //Console.WriteLine(sub1);
            //Console.WriteLine(sub2);
            //Console.WriteLine(string.Format("{0}, {1}, {2}",
            //    Kaibun(input), Kaibun(sub1), Kaibun(sub2)));
            bool result = Kaibun(input) && Kaibun(sub1) && Kaibun(sub2);
            Console.WriteLine(result ? "Yes" : "No");

        }
    }
}


Measured memory_bytes: 13408
#include<stdio.h>

void trace(int A[],int N){
	int i;
	for(i=0;i<N;i++){
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}

void insertionSort(int A[],int N){
	int j,i,v;
	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		trace(A,N);
	}
}

int main(){
	int N,i,j, A[100];
	
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	
	trace(A,N);
	insertionSort(A,N);
	
	return 0;
}

Measured memory_bytes: 604
import java.io.*;

public class Main{
	public static void main(String[] args){
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s;
		String[] t;
		int l,kakudo;
		int sumkakudo =0;
		double x,y,sumX,sumY;
		sumX=0;
		sumY=0;
		try{
			while((s=r.readLine()) !=null){
				t=s.split(",");
				l=Integer.parseInt(t[0]);
				kakudo=Integer.parseInt(t[1]);
				if(l==0 &&kakudo==0){break;}
				y=l*Math.sin(Math.toRadians(90-sumkakudo));
				x=l*Math.cos(Math.toRadians(90-sumkakudo));
				sumX +=x;
				sumY +=y;
				sumkakudo +=kakudo;
			}
			System.out.println((int)sumX+"\n"+(int)sumY);
			sumkakudo=0;
			sumX=0;
			sumY=0;
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16912